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 LongKeyIntValueHashMap extends BaseHashMap { 44 45 private Set keySet; 46 private Collection values; 47 48 public LongKeyIntValueHashMap() { 49 this(16, 0.75f); 50 } 51 52 public LongKeyIntValueHashMap(boolean minimize) { 53 54 this(16, 0.75f); 55 56 minimizeOnEmpty = minimize; 57 } 58 59 public LongKeyIntValueHashMap(int initialCapacity) 60 throws IllegalArgumentException { 61 this(initialCapacity, 0.75f); 62 } 63 64 public LongKeyIntValueHashMap(int initialCapacity, 65 float loadFactor) 66 throws IllegalArgumentException { 67 super(initialCapacity, loadFactor, BaseHashMap.longKeyOrValue, 68 BaseHashMap.intKeyOrValue, false); 69 } 70 71 public int get(long key) throws NoSuchElementException { 72 73 int lookup = getLookup(key); 74 75 if (lookup != -1) { 76 return intValueTable[lookup]; 77 } 78 79 throw new NoSuchElementException (); 80 } 81 82 public int get(long key, int defaultValue) { 83 84 int lookup = getLookup(key); 85 86 if (lookup != -1) { 87 return intValueTable[lookup]; 88 } 89 90 return defaultValue; 91 } 92 93 public boolean get(long key, int[] value) { 94 95 int lookup = getLookup(key); 96 97 if (lookup != -1) { 98 value[0] = intValueTable[lookup]; 99 100 return true; 101 } 102 103 return false; 104 } 105 106 public boolean put(long key, int value) { 107 108 int oldSize = size(); 109 110 super.addOrRemove(key, value, null, null, false); 111 112 return oldSize != size(); 113 } 114 115 public boolean remove(long key) { 116 117 int oldSize = size(); 118 119 super.addOrRemove(key, 0, null, null, true); 120 121 return oldSize != size(); 122 } 123 124 public Set keySet() { 125 126 if (keySet == null) { 127 keySet = new KeySet(); 128 } 129 130 return keySet; 131 } 132 133 public Collection values() { 134 135 if (values == null) { 136 values = new Values(); 137 } 138 139 return values; 140 } 141 142 class KeySet implements Set { 143 144 public Iterator iterator() { 145 return LongKeyIntValueHashMap.this.new BaseHashIterator(true); 146 } 147 148 public int size() { 149 return LongKeyIntValueHashMap.this.size(); 150 } 151 152 public boolean contains(Object o) { 153 throw new RuntimeException (); 154 } 155 156 public Object get(Object key) { 157 throw new RuntimeException (); 158 } 159 160 public boolean add(Object value) { 161 throw new RuntimeException (); 162 } 163 164 public boolean addAll(Collection c) { 165 throw new RuntimeException (); 166 } 167 168 public boolean remove(Object o) { 169 throw new RuntimeException (); 170 } 171 172 public boolean isEmpty() { 173 return size() == 0; 174 } 175 176 public void clear() { 177 LongKeyIntValueHashMap.this.clear(); 178 } 179 } 180 181 class Values implements Collection { 182 183 public Iterator iterator() { 184 return LongKeyIntValueHashMap.this.new BaseHashIterator(false); 185 } 186 187 public int size() { 188 return LongKeyIntValueHashMap.this.size(); 189 } 190 191 public boolean contains(Object o) { 192 throw new RuntimeException (); 193 } 194 195 public boolean add(Object value) { 196 throw new RuntimeException (); 197 } 198 199 public boolean addAll(Collection c) { 200 throw new RuntimeException (); 201 } 202 203 public boolean remove(Object o) { 204 throw new RuntimeException (); 205 } 206 207 public boolean isEmpty() { 208 return size() == 0; 209 } 210 211 public void clear() { 212 LongKeyIntValueHashMap.this.clear(); 213 } 214 } 215 } 216 | Popular Tags |