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