View Javadoc
1   /*
2    * Copyright 2010 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package com.googlecode.mgwt.collection.shared.java;
17  
18  import java.util.HashMap;
19  import java.util.Set;
20  
21  import com.googlecode.mgwt.collection.shared.LightArray;
22  import com.googlecode.mgwt.collection.shared.LightMap;
23  
24  /**
25   * Java implementation of {@link LightMap}
26   * 
27   * @author Daniel Kurka
28   * 
29   * @param <V> type of objects to store
30   */
31  public class JavaLightMap<V> implements LightMap<V> {
32  
33  	private HashMap<String, V> map;
34  
35    /**
36     * Construct a {@link JavaLightMap}
37     */
38  	public JavaLightMap() {
39  		map = new HashMap<String, V>();
40  	}
41  
42  	@Override
43  	public void clear() {
44  		map.clear();
45  
46  	}
47  
48  	@Override
49  	public boolean containsKey(String key) {
50  		return map.containsKey(key);
51  	}
52  
53  	@Override
54  	public LightArray<String> getKeys() {
55  		Set<String> keySet = map.keySet();
56  		return JavaLightArray.fromSet(keySet);
57  	}
58  
59  	@Override
60  	public void remove(String key) {
61  		map.remove(key);
62  	}
63  
64  	@Override
65  	public V get(String key) {
66  		return map.get(key);
67  	}
68  
69  	@Override
70  	public void put(String key, V value) {
71  		map.put(key, value);
72  	}
73  
74  }