001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.lib;
032:
033: import java.util.NoSuchElementException;
034:
035: import org.hsqldb.store.BaseHashMap;
036:
037: /**
038: * @author fredt@users
039: * @version 1.7.2
040: * @since 1.7.2
041: */
042: public class IntKeyLongValueHashMap extends BaseHashMap {
043:
044: public IntKeyLongValueHashMap() {
045: this (16, 0.75f);
046: }
047:
048: public IntKeyLongValueHashMap(int initialCapacity)
049: throws IllegalArgumentException {
050: this (initialCapacity, 0.75f);
051: }
052:
053: public IntKeyLongValueHashMap(int initialCapacity, float loadFactor)
054: throws IllegalArgumentException {
055: super (initialCapacity, loadFactor, BaseHashMap.intKeyOrValue,
056: BaseHashMap.longKeyOrValue, false);
057: }
058:
059: public long get(int key) throws NoSuchElementException {
060:
061: int lookup = getLookup(key);
062:
063: if (lookup != -1) {
064: return longValueTable[lookup];
065: }
066:
067: throw new NoSuchElementException();
068: }
069:
070: public long get(int key, int defaultValue) {
071:
072: int lookup = getLookup(key);
073:
074: if (lookup != -1) {
075: return longValueTable[lookup];
076: }
077:
078: return defaultValue;
079: }
080:
081: public boolean get(int key, long[] value) {
082:
083: int lookup = getLookup(key);
084:
085: if (lookup != -1) {
086: value[0] = longValueTable[lookup];
087:
088: return true;
089: }
090:
091: return false;
092: }
093:
094: public boolean put(int key, int value) {
095:
096: int oldSize = size();
097:
098: super .addOrRemove(key, value, null, null, false);
099:
100: return oldSize != size();
101: }
102:
103: public boolean remove(int key) {
104:
105: int oldSize = size();
106:
107: super .addOrRemove(key, 0, null, null, true);
108:
109: return oldSize != size();
110: }
111: }
|