Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fccf9783a113777a3a8c068e4196c1f16a7bcb73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.text.source;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


/**
 * Internal implementation of {@link org.eclipse.jface.text.source.IAnnotationMap}.
 * 
 * @since 3.0
 */
class AnnotationMap implements IAnnotationMap {

    /**
     * The lock object used to synchronize the operations explicitly defined by
     * <code>IAnnotationMap</code>
     */
    private Object fLockObject;

    /** The map holding the annotations */
    private Map fInternalMap;

    /**
     * Creates a new annotation map with the given capacity.
     * 
     * @param capacity the capacity
     */
    public AnnotationMap(int capacity) {
        fInternalMap = new HashMap(capacity);
    }

    /*
     * @see org.eclipse.jface.text.source.ISynchronizable#setLockObject(java.lang.Object)
     */
    public void setLockObject(Object lockObject) {
        fLockObject = lockObject;
    }

    /*
     * @see org.eclipse.jface.text.source.ISynchronizable#getLockObject()
     */
    public Object getLockObject() {
        if (fLockObject == null) return this;
        return fLockObject;
    }

    /*
     * @see org.eclipse.jface.text.source.IAnnotationMap#valuesIterator()
     */
    public Iterator valuesIterator() {
        synchronized (getLockObject()) {
            return new ArrayList(fInternalMap.values()).iterator();
        }
    }

    /*
     * @see org.eclipse.jface.text.source.IAnnotationMap#keySetIterator()
     */
    public Iterator keySetIterator() {
        synchronized (getLockObject()) {
            return new ArrayList(fInternalMap.keySet()).iterator();
        }
    }
    
    /*
     * @see java.util.Map#containsKey(java.lang.Object)
     */
    public boolean containsKey(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.containsKey(annotation);
        }
    }

    /*
     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
     */
    public Object put(Object annotation, Object position) {
        synchronized (getLockObject()) {
            return fInternalMap.put(annotation, position);
        }
    }

    /*
     * @see java.util.Map#get(java.lang.Object)
     */
    public Object get(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.get(annotation);
        }
    }

    /*
     * @see java.util.Map#clear()
     */
    public void clear() {
        synchronized (getLockObject()) {
            fInternalMap.clear();
        }
    }

    /*
     * @see java.util.Map#remove(java.lang.Object)
     */
    public Object remove(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.remove(annotation);
        }
    }
    
    /*
     * @see java.util.Map#size()
     */
    public int size() {
        synchronized (getLockObject()) {
            return fInternalMap.size();
        }
    }
    
    /*
     * @see java.util.Map#isEmpty()
     */
    public boolean isEmpty() {
        synchronized (getLockObject()) {
			return fInternalMap.isEmpty();
		}
    }
    
	/*
	 * @see java.util.Map#containsValue(java.lang.Object)
	 */
	public boolean containsValue(Object value) {
		synchronized(getLockObject()) {
			return fInternalMap.containsValue(value);
		}
	}
	
	/*
	 * @see java.util.Map#putAll(java.util.Map)
	 */
	public void putAll(Map map) {
		synchronized (getLockObject()) {
			fInternalMap.putAll(map);
		}
	}
	
	/*
	 * @see IAnnotationMap#entrySet()
	 */
	public Set entrySet() {
		synchronized (getLockObject()) {
			return fInternalMap.entrySet();
		}
	}
	
	/*
	 * @see IAnnotationMap#keySet()
	 */
	public Set keySet() {
		synchronized (getLockObject()) {
			return fInternalMap.keySet();
		}
	}
	
	/*
	 * @see IAnnotationMap#values()
	 */
	public Collection values() {
		synchronized (getLockObject()) {
			return fInternalMap.values();
		}
	}
}

Back to the top