01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.themes;
11:
12: import java.util.Collections;
13: import java.util.HashSet;
14: import java.util.Map;
15: import java.util.Set;
16:
17: /**
18: * @since 3.0
19: */
20: public class CascadingMap {
21:
22: private Map base, override;
23:
24: /**
25: * @param base the base (default) map
26: * @param override the override map
27: */
28: public CascadingMap(Map base, Map override) {
29: this .base = base;
30: this .override = override;
31: }
32:
33: /**
34: * Return the union of the parent and child key sets.
35: *
36: * @return the union. This set is read only.
37: */
38: public Set keySet() {
39: Set keySet = new HashSet(base.keySet());
40: keySet.addAll(override.keySet());
41: return Collections.unmodifiableSet(keySet);
42: }
43:
44: /**
45: * Get the value. Preference will be given to entries in the override map.
46: *
47: * @param key the key
48: * @return the value
49: */
50: public Object get(Object key) {
51: if (override.containsKey(key)) {
52: return override.get(key);
53: }
54: return base.get(key);
55: }
56: }
|