10
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.viewers.deferred.IntHashMap;
|
|
14
|
|
15 import tango.util.collection.HashMap;
|
|
16
|
|
17 /**
|
|
18 * Represents a map of objects onto ints. This is intended for future optimization:
|
|
19 * using int primitives would allow for an implementation that doesn't require
|
|
20 * additional object allocations for Integers. However, the current implementation
|
|
21 * simply delegates to the Java HashMap class.
|
|
22 *
|
|
23 * @since 3.1
|
|
24 */
|
|
25 /* package */ class IntHashMap {
|
|
26 private HashMap!(Object,int) map;
|
|
27
|
|
28 /**
|
|
29 * @param size
|
|
30 * @param loadFactor
|
|
31 */
|
|
32 public this(int size, float loadFactor) {
|
|
33 map = new HashMap!(Object,int);
|
|
34 // (size, loadFactor);
|
|
35 }
|
|
36
|
|
37 /**
|
|
38 *
|
|
39 */
|
|
40 public this() {
|
|
41 map = new HashMap!(Object,int);
|
|
42 }
|
|
43
|
|
44 /**
|
|
45 * @param key
|
|
46 */
|
|
47 public void remove(Object key) {
|
|
48 map.removeKey(key);
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * @param key
|
|
53 * @param value
|
|
54 */
|
|
55 public void put(Object key, int value) {
|
|
56 map.add(key, value);
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * @param key
|
|
61 * @return the int value at the given key
|
|
62 */
|
|
63 public int get(Object key) {
|
|
64 return get(key, 0);
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * @param key
|
|
69 * @param defaultValue
|
|
70 * @return the int value at the given key, or the default value if this map does not contain the given key
|
|
71 */
|
|
72 public int get(Object key, int defaultValue) {
|
|
73 if( map.containsKey( key )){
|
|
74 return map.get(key);
|
|
75 }
|
|
76 return defaultValue;
|
|
77 }
|
|
78
|
|
79 /**
|
|
80 * @param key
|
|
81 * @return <code>true</code> if this map contains the given key, <code>false</code> otherwise
|
|
82 */
|
|
83 public bool containsKey(Object key) {
|
|
84 return map.containsKey(key);
|
|
85 }
|
|
86
|
|
87 /**
|
|
88 * @return the number of key/value pairs
|
|
89 */
|
|
90 public int size() {
|
|
91 return map.size();
|
|
92 }
|
|
93 }
|