Mercurial > projects > dwt-addons
comparison dwtx/jface/text/source/AnnotationMap.d @ 129:eb30df5ca28b
Added JFace Text sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 23 Aug 2008 19:10:48 +0200 |
parents | |
children | c4fb132a086c |
comparison
equal
deleted
inserted
replaced
128:8df1d4193877 | 129:eb30df5ca28b |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.source.AnnotationMap; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 | |
18 import java.util.ArrayList; | |
19 import java.util.Collection; | |
20 import java.util.HashMap; | |
21 import java.util.Iterator; | |
22 import java.util.Map; | |
23 import java.util.Set; | |
24 | |
25 | |
26 /** | |
27 * Internal implementation of {@link dwtx.jface.text.source.IAnnotationMap}. | |
28 * | |
29 * @since 3.0 | |
30 */ | |
31 class AnnotationMap : IAnnotationMap { | |
32 | |
33 /** | |
34 * The lock object used to synchronize the operations explicitly defined by | |
35 * <code>IAnnotationMap</code> | |
36 */ | |
37 private Object fLockObject; | |
38 /** | |
39 * The internal lock object used if <code>fLockObject</code> is <code>null</code>. | |
40 * @since 3.2 | |
41 */ | |
42 private final Object fInternalLockObject= new Object(); | |
43 | |
44 /** The map holding the annotations */ | |
45 private Map fInternalMap; | |
46 | |
47 /** | |
48 * Creates a new annotation map with the given capacity. | |
49 * | |
50 * @param capacity the capacity | |
51 */ | |
52 public AnnotationMap(int capacity) { | |
53 fInternalMap= new HashMap(capacity); | |
54 } | |
55 | |
56 /* | |
57 * @see dwtx.jface.text.source.ISynchronizable#setLockObject(java.lang.Object) | |
58 */ | |
59 public synchronized void setLockObject(Object lockObject) { | |
60 fLockObject= lockObject; | |
61 } | |
62 | |
63 /* | |
64 * @see dwtx.jface.text.source.ISynchronizable#getLockObject() | |
65 */ | |
66 public synchronized Object getLockObject() { | |
67 if (fLockObject is null) | |
68 return fInternalLockObject; | |
69 return fLockObject; | |
70 } | |
71 | |
72 /* | |
73 * @see dwtx.jface.text.source.IAnnotationMap#valuesIterator() | |
74 */ | |
75 public Iterator valuesIterator() { | |
76 synchronized (getLockObject()) { | |
77 return new ArrayList(fInternalMap.values()).iterator(); | |
78 } | |
79 } | |
80 | |
81 /* | |
82 * @see dwtx.jface.text.source.IAnnotationMap#keySetIterator() | |
83 */ | |
84 public Iterator keySetIterator() { | |
85 synchronized (getLockObject()) { | |
86 return new ArrayList(fInternalMap.keySet()).iterator(); | |
87 } | |
88 } | |
89 | |
90 /* | |
91 * @see java.util.Map#containsKey(java.lang.Object) | |
92 */ | |
93 public bool containsKey(Object annotation) { | |
94 synchronized (getLockObject()) { | |
95 return fInternalMap.containsKey(annotation); | |
96 } | |
97 } | |
98 | |
99 /* | |
100 * @see java.util.Map#put(java.lang.Object, java.lang.Object) | |
101 */ | |
102 public Object put(Object annotation, Object position) { | |
103 synchronized (getLockObject()) { | |
104 return fInternalMap.put(annotation, position); | |
105 } | |
106 } | |
107 | |
108 /* | |
109 * @see java.util.Map#get(java.lang.Object) | |
110 */ | |
111 public Object get(Object annotation) { | |
112 synchronized (getLockObject()) { | |
113 return fInternalMap.get(annotation); | |
114 } | |
115 } | |
116 | |
117 /* | |
118 * @see java.util.Map#clear() | |
119 */ | |
120 public void clear() { | |
121 synchronized (getLockObject()) { | |
122 fInternalMap.clear(); | |
123 } | |
124 } | |
125 | |
126 /* | |
127 * @see java.util.Map#remove(java.lang.Object) | |
128 */ | |
129 public Object remove(Object annotation) { | |
130 synchronized (getLockObject()) { | |
131 return fInternalMap.remove(annotation); | |
132 } | |
133 } | |
134 | |
135 /* | |
136 * @see java.util.Map#size() | |
137 */ | |
138 public int size() { | |
139 synchronized (getLockObject()) { | |
140 return fInternalMap.size(); | |
141 } | |
142 } | |
143 | |
144 /* | |
145 * @see java.util.Map#isEmpty() | |
146 */ | |
147 public bool isEmpty() { | |
148 synchronized (getLockObject()) { | |
149 return fInternalMap.isEmpty(); | |
150 } | |
151 } | |
152 | |
153 /* | |
154 * @see java.util.Map#containsValue(java.lang.Object) | |
155 */ | |
156 public bool containsValue(Object value) { | |
157 synchronized(getLockObject()) { | |
158 return fInternalMap.containsValue(value); | |
159 } | |
160 } | |
161 | |
162 /* | |
163 * @see java.util.Map#putAll(java.util.Map) | |
164 */ | |
165 public void putAll(Map map) { | |
166 synchronized (getLockObject()) { | |
167 fInternalMap.putAll(map); | |
168 } | |
169 } | |
170 | |
171 /* | |
172 * @see IAnnotationMap#entrySet() | |
173 */ | |
174 public Set entrySet() { | |
175 synchronized (getLockObject()) { | |
176 return fInternalMap.entrySet(); | |
177 } | |
178 } | |
179 | |
180 /* | |
181 * @see IAnnotationMap#keySet() | |
182 */ | |
183 public Set keySet() { | |
184 synchronized (getLockObject()) { | |
185 return fInternalMap.keySet(); | |
186 } | |
187 } | |
188 | |
189 /* | |
190 * @see IAnnotationMap#values() | |
191 */ | |
192 public Collection values() { | |
193 synchronized (getLockObject()) { | |
194 return fInternalMap.values(); | |
195 } | |
196 } | |
197 } |