1 11 package org.eclipse.jface.text.source; 12 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 import java.util.Set ; 20 21 22 27 class AnnotationMap implements IAnnotationMap { 28 29 33 private Object fLockObject; 34 38 private final Object fInternalLockObject= new Object (); 39 40 41 private Map fInternalMap; 42 43 48 public AnnotationMap(int capacity) { 49 fInternalMap= new HashMap (capacity); 50 } 51 52 55 public synchronized void setLockObject(Object lockObject) { 56 fLockObject= lockObject; 57 } 58 59 62 public synchronized Object getLockObject() { 63 if (fLockObject == null) 64 return fInternalLockObject; 65 return fLockObject; 66 } 67 68 71 public Iterator valuesIterator() { 72 synchronized (getLockObject()) { 73 return new ArrayList (fInternalMap.values()).iterator(); 74 } 75 } 76 77 80 public Iterator keySetIterator() { 81 synchronized (getLockObject()) { 82 return new ArrayList (fInternalMap.keySet()).iterator(); 83 } 84 } 85 86 89 public boolean containsKey(Object annotation) { 90 synchronized (getLockObject()) { 91 return fInternalMap.containsKey(annotation); 92 } 93 } 94 95 98 public Object put(Object annotation, Object position) { 99 synchronized (getLockObject()) { 100 return fInternalMap.put(annotation, position); 101 } 102 } 103 104 107 public Object get(Object annotation) { 108 synchronized (getLockObject()) { 109 return fInternalMap.get(annotation); 110 } 111 } 112 113 116 public void clear() { 117 synchronized (getLockObject()) { 118 fInternalMap.clear(); 119 } 120 } 121 122 125 public Object remove(Object annotation) { 126 synchronized (getLockObject()) { 127 return fInternalMap.remove(annotation); 128 } 129 } 130 131 134 public int size() { 135 synchronized (getLockObject()) { 136 return fInternalMap.size(); 137 } 138 } 139 140 143 public boolean isEmpty() { 144 synchronized (getLockObject()) { 145 return fInternalMap.isEmpty(); 146 } 147 } 148 149 152 public boolean containsValue(Object value) { 153 synchronized(getLockObject()) { 154 return fInternalMap.containsValue(value); 155 } 156 } 157 158 161 public void putAll(Map map) { 162 synchronized (getLockObject()) { 163 fInternalMap.putAll(map); 164 } 165 } 166 167 170 public Set entrySet() { 171 synchronized (getLockObject()) { 172 return fInternalMap.entrySet(); 173 } 174 } 175 176 179 public Set keySet() { 180 synchronized (getLockObject()) { 181 return fInternalMap.keySet(); 182 } 183 } 184 185 188 public Collection values() { 189 synchronized (getLockObject()) { 190 return fInternalMap.values(); 191 } 192 } 193 } 194 | Popular Tags |