KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > source > AnnotationMap


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  *******************************************************************************/

11 package org.eclipse.jface.text.source;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Set JavaDoc;
20
21
22 /**
23  * Internal implementation of {@link org.eclipse.jface.text.source.IAnnotationMap}.
24  *
25  * @since 3.0
26  */

27 class AnnotationMap implements IAnnotationMap {
28
29     /**
30      * The lock object used to synchronize the operations explicitly defined by
31      * <code>IAnnotationMap</code>
32      */

33     private Object JavaDoc fLockObject;
34     /**
35      * The internal lock object used if <code>fLockObject</code> is <code>null</code>.
36      * @since 3.2
37      */

38     private final Object JavaDoc fInternalLockObject= new Object JavaDoc();
39
40     /** The map holding the annotations */
41     private Map JavaDoc fInternalMap;
42
43     /**
44      * Creates a new annotation map with the given capacity.
45      *
46      * @param capacity the capacity
47      */

48     public AnnotationMap(int capacity) {
49         fInternalMap= new HashMap JavaDoc(capacity);
50     }
51
52     /*
53      * @see org.eclipse.jface.text.source.ISynchronizable#setLockObject(java.lang.Object)
54      */

55     public synchronized void setLockObject(Object JavaDoc lockObject) {
56         fLockObject= lockObject;
57     }
58
59     /*
60      * @see org.eclipse.jface.text.source.ISynchronizable#getLockObject()
61      */

62     public synchronized Object JavaDoc getLockObject() {
63         if (fLockObject == null)
64             return fInternalLockObject;
65         return fLockObject;
66     }
67
68     /*
69      * @see org.eclipse.jface.text.source.IAnnotationMap#valuesIterator()
70      */

71     public Iterator JavaDoc valuesIterator() {
72         synchronized (getLockObject()) {
73             return new ArrayList JavaDoc(fInternalMap.values()).iterator();
74         }
75     }
76
77     /*
78      * @see org.eclipse.jface.text.source.IAnnotationMap#keySetIterator()
79      */

80     public Iterator JavaDoc keySetIterator() {
81         synchronized (getLockObject()) {
82             return new ArrayList JavaDoc(fInternalMap.keySet()).iterator();
83         }
84     }
85
86     /*
87      * @see java.util.Map#containsKey(java.lang.Object)
88      */

89     public boolean containsKey(Object JavaDoc annotation) {
90         synchronized (getLockObject()) {
91             return fInternalMap.containsKey(annotation);
92         }
93     }
94
95     /*
96      * @see java.util.Map#put(java.lang.Object, java.lang.Object)
97      */

98     public Object JavaDoc put(Object JavaDoc annotation, Object JavaDoc position) {
99         synchronized (getLockObject()) {
100             return fInternalMap.put(annotation, position);
101         }
102     }
103
104     /*
105      * @see java.util.Map#get(java.lang.Object)
106      */

107     public Object JavaDoc get(Object JavaDoc annotation) {
108         synchronized (getLockObject()) {
109             return fInternalMap.get(annotation);
110         }
111     }
112
113     /*
114      * @see java.util.Map#clear()
115      */

116     public void clear() {
117         synchronized (getLockObject()) {
118             fInternalMap.clear();
119         }
120     }
121
122     /*
123      * @see java.util.Map#remove(java.lang.Object)
124      */

125     public Object JavaDoc remove(Object JavaDoc annotation) {
126         synchronized (getLockObject()) {
127             return fInternalMap.remove(annotation);
128         }
129     }
130
131     /*
132      * @see java.util.Map#size()
133      */

134     public int size() {
135         synchronized (getLockObject()) {
136             return fInternalMap.size();
137         }
138     }
139
140     /*
141      * @see java.util.Map#isEmpty()
142      */

143     public boolean isEmpty() {
144         synchronized (getLockObject()) {
145             return fInternalMap.isEmpty();
146         }
147     }
148
149     /*
150      * @see java.util.Map#containsValue(java.lang.Object)
151      */

152     public boolean containsValue(Object JavaDoc value) {
153         synchronized(getLockObject()) {
154             return fInternalMap.containsValue(value);
155         }
156     }
157
158     /*
159      * @see java.util.Map#putAll(java.util.Map)
160      */

161     public void putAll(Map JavaDoc map) {
162         synchronized (getLockObject()) {
163             fInternalMap.putAll(map);
164         }
165     }
166
167     /*
168      * @see IAnnotationMap#entrySet()
169      */

170     public Set JavaDoc entrySet() {
171         synchronized (getLockObject()) {
172             return fInternalMap.entrySet();
173         }
174     }
175
176     /*
177      * @see IAnnotationMap#keySet()
178      */

179     public Set JavaDoc keySet() {
180         synchronized (getLockObject()) {
181             return fInternalMap.keySet();
182         }
183     }
184
185     /*
186      * @see IAnnotationMap#values()
187      */

188     public Collection JavaDoc values() {
189         synchronized (getLockObject()) {
190             return fInternalMap.values();
191         }
192     }
193 }
194
Popular Tags