Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5049f82ef8de0fe3084cf5285ef2804d2e9e72ba (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
/*******************************************************************************
 * Copyright (c) 2007, 2011 Intel 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:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.core.settings.model.extension.CDataObject;

public class MapProxyCache implements IProxyCache {
	private HashMap<String, CDataProxy> fMap;

	private HashMap<String, CDataProxy> getMap(boolean create) {
		if (fMap == null && create)
			fMap = new HashMap<>();
		return fMap;
	}

	@Override
	public CDataProxy[] getCachedProxies() {
		Map<String, CDataProxy> map = getMap(false);
		if (map != null) {
			Collection<CDataProxy> c = map.values();
			return c.toArray(new CDataProxy[c.size()]);
		}
		return new CDataProxy[0];
	}

	@Override
	public CDataProxy getCachedProxy(String id) {
		Map<String, CDataProxy> map = getMap(false);
		if (map != null)
			return map.get(id);
		return null;
	}

	@Override
	public void removeCachedProxy(String id) {
		Map<String, CDataProxy> map = getMap(false);
		if (map != null)
			map.remove(id);
	}

	@Override
	public void clear() {
		fMap.clear();
	}

	@Override
	public void addCachedProxy(CDataProxy proxy) {
		getMap(true).put(proxy.getId(), proxy);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Map<String, CDataProxy> getCachedProxiesMap() {
		return (Map<String, CDataProxy>) getMap(true).clone();
	}

	@Override
	public CDataProxy getCachedProxy(CDataObject data) {
		return getCachedProxy(data.getId());
	}

	@Override
	public void removeCachedProxy(CDataProxy proxy) {
		removeCachedProxy(proxy.getId());
	}

	public void reuseProxies(List<CDataObject> dataList, Map<String, CDataProxy> freeProxyMap) {
	}
}

Back to the top