Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/deferred/IntHashMap.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 04b47443bb01 |
children |
rev | line source |
---|---|
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 | |
16 /** | |
17 * Represents a map of objects onto ints. This is intended for future optimization: | |
18 * using int primitives would allow for an implementation that doesn't require | |
19 * additional object allocations for Integers. However, the current implementation | |
20 * simply delegates to the Java HashMap class. | |
21 * | |
22 * @since 3.1 | |
23 */ | |
24 /* package */ class IntHashMap { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
25 private int[Object] map; |
10 | 26 |
27 /** | |
28 * @param size | |
29 * @param loadFactor | |
30 */ | |
31 public this(int size, float loadFactor) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
32 // map = new HashMap(size,loadFactor); |
10 | 33 } |
34 | |
35 /** | |
36 * | |
37 */ | |
38 public this() { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
39 // map = new HashMap(); |
10 | 40 } |
41 | |
42 /** | |
43 * @param key | |
44 */ | |
45 public void remove(Object key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
46 map.remove(key); |
10 | 47 } |
48 | |
49 /** | |
50 * @param key | |
51 * @param value | |
52 */ | |
53 public void put(Object key, int value) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
54 map[key] = value; |
10 | 55 } |
56 | |
57 /** | |
58 * @param key | |
59 * @return the int value at the given key | |
60 */ | |
61 public int get(Object key) { | |
62 return get(key, 0); | |
63 } | |
64 | |
65 /** | |
66 * @param key | |
67 * @param defaultValue | |
68 * @return the int value at the given key, or the default value if this map does not contain the given key | |
69 */ | |
70 public int get(Object key, int defaultValue) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
71 if( auto res = key in map ){ |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
72 return *res; |
10 | 73 } |
74 return defaultValue; | |
75 } | |
76 | |
77 /** | |
78 * @param key | |
79 * @return <code>true</code> if this map contains the given key, <code>false</code> otherwise | |
80 */ | |
81 public bool containsKey(Object key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
82 if( auto res = key in map ){ |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
83 return true; |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
84 } |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
85 return false; |
10 | 86 } |
87 | |
88 /** | |
89 * @return the number of key/value pairs | |
90 */ | |
91 public int size() { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
92 return map.length; |
10 | 93 } |
94 } |