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