Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 17105ace2f3ae07ce2acdb21a96293d3c3602be3 (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
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * 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;

import org.eclipse.jface.text.Position;


/**
 * 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 internal lock object used if <code>fLockObject</code> is <code>null</code>.
	 * @since 3.2
	 */
    private final Object fInternalLockObject= new Object();

    /** The map holding the annotations */
    private Map<Annotation, Position> fInternalMap;

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

    @Override
	public synchronized void setLockObject(Object lockObject) {
        fLockObject= lockObject;
    }

    @Override
	public synchronized Object getLockObject() {
        if (fLockObject == null)
        	return fInternalLockObject;
        return fLockObject;
    }

    @Override
	public Iterator<Position> valuesIterator() {
        synchronized (getLockObject()) {
            return new ArrayList<>(fInternalMap.values()).iterator();
        }
    }

    @Override
	public Iterator<Annotation> keySetIterator() {
        synchronized (getLockObject()) {
            return new ArrayList<>(fInternalMap.keySet()).iterator();
        }
    }

    @Override
	public boolean containsKey(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.containsKey(annotation);
        }
    }

    @Override
	public Position put(Annotation annotation, Position position) {
        synchronized (getLockObject()) {
            return fInternalMap.put(annotation, position);
        }
    }

    @Override
	public Position get(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.get(annotation);
        }
    }

    @Override
	public void clear() {
        synchronized (getLockObject()) {
            fInternalMap.clear();
        }
    }

    @Override
	public Position remove(Object annotation) {
        synchronized (getLockObject()) {
            return fInternalMap.remove(annotation);
        }
    }

    @Override
	public int size() {
        synchronized (getLockObject()) {
            return fInternalMap.size();
        }
    }

    @Override
	public boolean isEmpty() {
        synchronized (getLockObject()) {
			return fInternalMap.isEmpty();
		}
    }

	@Override
	public boolean containsValue(Object value) {
		synchronized(getLockObject()) {
			return fInternalMap.containsValue(value);
		}
	}

	@Override
	public void putAll(Map<? extends Annotation, ? extends Position> map) {
		synchronized (getLockObject()) {
			fInternalMap.putAll(map);
		}
	}

	@Override
	public Set<Entry<Annotation, Position>> entrySet() {
		synchronized (getLockObject()) {
			return fInternalMap.entrySet();
		}
	}

	@Override
	public Set<Annotation> keySet() {
		synchronized (getLockObject()) {
			return fInternalMap.keySet();
		}
	}

	@Override
	public Collection<Position> values() {
		synchronized (getLockObject()) {
			return fInternalMap.values();
		}
	}
}

Back to the top