KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > themes > CascadingMap


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.ui.internal.themes;
12
13 import java.util.Collections JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * @since 3.0
20  */

21 public class CascadingMap {
22
23     private Map JavaDoc base, override;
24
25     /**
26      * @param base the base (default) map
27      * @param override the override map
28      */

29     public CascadingMap(Map JavaDoc base, Map JavaDoc override) {
30         this.base = base;
31         this.override = override;
32     }
33
34     /**
35      * Return the union of the parent and child key sets.
36      *
37      * @return the union. This set is read only.
38      */

39     public Set JavaDoc keySet() {
40         Set JavaDoc keySet = new HashSet JavaDoc(base.keySet());
41         keySet.addAll(override.keySet());
42         return Collections.unmodifiableSet(keySet);
43     }
44
45     /**
46      * Get the value. Preference will be given to entries in the override map.
47      *
48      * @param key the key
49      * @return the value
50      */

51     public Object JavaDoc get(Object JavaDoc key) {
52         if (override.containsKey(key)) {
53             return override.get(key);
54         }
55         return base.get(key);
56     }
57 }
58
Popular Tags