1 13 14 package EDU.oswego.cs.dl.util.concurrent; 15 import java.util.*; 16 17 24 25 26 public class SyncSortedSet extends SyncSet implements SortedSet { 27 28 34 public SyncSortedSet(SortedSet set, Sync sync) { 35 super (set, sync); 36 } 37 38 42 public SyncSortedSet(SortedSet set, ReadWriteLock rwl) { 43 super (set, rwl.readLock(), rwl.writeLock()); 44 } 45 46 50 public SyncSortedSet(SortedSet set, Sync readLock, Sync writeLock) { 51 super(set, readLock, writeLock); 52 } 53 54 55 protected SortedSet baseSortedSet() { 56 return (SortedSet)c_; 57 } 58 59 public Comparator comparator() { 60 boolean wasInterrupted = beforeRead(); 61 try { 62 return baseSortedSet().comparator(); 63 } 64 finally { 65 afterRead(wasInterrupted); 66 } 67 } 68 69 public Object first() { 70 boolean wasInterrupted = beforeRead(); 71 try { 72 return baseSortedSet().first(); 73 } 74 finally { 75 afterRead(wasInterrupted); 76 } 77 } 78 79 public Object last() { 80 boolean wasInterrupted = beforeRead(); 81 try { 82 return baseSortedSet().last(); 83 } 84 finally { 85 afterRead(wasInterrupted); 86 } 87 } 88 89 90 public SortedSet subSet(Object fromElement, Object toElement) { 91 boolean wasInterrupted = beforeRead(); 92 try { 93 return new SyncSortedSet(baseSortedSet().subSet(fromElement, toElement), 94 rd_, wr_); 95 } 96 finally { 97 afterRead(wasInterrupted); 98 } 99 } 100 101 public SortedSet headSet(Object toElement) { 102 boolean wasInterrupted = beforeRead(); 103 try { 104 return new SyncSortedSet(baseSortedSet().headSet(toElement), 105 rd_, wr_); 106 } 107 finally { 108 afterRead(wasInterrupted); 109 } 110 } 111 112 public SortedSet tailSet(Object fromElement) { 113 boolean wasInterrupted = beforeRead(); 114 try { 115 return new SyncSortedSet(baseSortedSet().tailSet(fromElement), 116 rd_, wr_); 117 } 118 finally { 119 afterRead(wasInterrupted); 120 } 121 } 122 123 } 124 125 126 | Popular Tags |