Mercurial > projects > dwt-addons
diff dwtx/jface/viewers/deferred/IntHashMap.d @ 10:b6c35faf97c8
Viewers
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 31 Mar 2008 00:47:19 +0200 |
parents | |
children | 04b47443bb01 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/viewers/deferred/IntHashMap.d Mon Mar 31 00:47:19 2008 +0200 @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2004, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ +module dwtx.jface.viewers.deferred.IntHashMap; + +import tango.util.collection.HashMap; + +/** + * Represents a map of objects onto ints. This is intended for future optimization: + * using int primitives would allow for an implementation that doesn't require + * additional object allocations for Integers. However, the current implementation + * simply delegates to the Java HashMap class. + * + * @since 3.1 + */ +/* package */ class IntHashMap { + private HashMap!(Object,int) map; + + /** + * @param size + * @param loadFactor + */ + public this(int size, float loadFactor) { + map = new HashMap!(Object,int); +// (size, loadFactor); + } + + /** + * + */ + public this() { + map = new HashMap!(Object,int); + } + + /** + * @param key + */ + public void remove(Object key) { + map.removeKey(key); + } + + /** + * @param key + * @param value + */ + public void put(Object key, int value) { + map.add(key, value); + } + + /** + * @param key + * @return the int value at the given key + */ + public int get(Object key) { + return get(key, 0); + } + + /** + * @param key + * @param defaultValue + * @return the int value at the given key, or the default value if this map does not contain the given key + */ + public int get(Object key, int defaultValue) { + if( map.containsKey( key )){ + return map.get(key); + } + return defaultValue; + } + + /** + * @param key + * @return <code>true</code> if this map contains the given key, <code>false</code> otherwise + */ + public bool containsKey(Object key) { + return map.containsKey(key); + } + + /** + * @return the number of key/value pairs + */ + public int size() { + return map.size(); + } +}