1 30 31 32 package org.hsqldb.lib; 33 34 import java.util.NoSuchElementException ; 35 36 import org.hsqldb.store.BaseHashMap; 37 38 43 public class IntKeyLongValueHashMap extends BaseHashMap { 44 45 public IntKeyLongValueHashMap() { 46 this(16, 0.75f); 47 } 48 49 public IntKeyLongValueHashMap(int initialCapacity) 50 throws IllegalArgumentException { 51 this(initialCapacity, 0.75f); 52 } 53 54 public IntKeyLongValueHashMap(int initialCapacity, 55 float loadFactor) 56 throws IllegalArgumentException { 57 super(initialCapacity, loadFactor, BaseHashMap.intKeyOrValue, 58 BaseHashMap.longKeyOrValue, false); 59 } 60 61 public long get(int key) throws NoSuchElementException { 62 63 int lookup = getLookup(key); 64 65 if (lookup != -1) { 66 return longValueTable[lookup]; 67 } 68 69 throw new NoSuchElementException (); 70 } 71 72 public long get(int key, int defaultValue) { 73 74 int lookup = getLookup(key); 75 76 if (lookup != -1) { 77 return longValueTable[lookup]; 78 } 79 80 return defaultValue; 81 } 82 83 public boolean get(int key, long[] value) { 84 85 int lookup = getLookup(key); 86 87 if (lookup != -1) { 88 value[0] = longValueTable[lookup]; 89 90 return true; 91 } 92 93 return false; 94 } 95 96 public boolean put(int key, int value) { 97 98 int oldSize = size(); 99 100 super.addOrRemove(key, value, null, null, false); 101 102 return oldSize != size(); 103 } 104 105 public boolean remove(int key) { 106 107 int oldSize = size(); 108 109 super.addOrRemove(key, 0, null, null, true); 110 111 return oldSize != size(); 112 } 113 } 114 | Popular Tags |