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