private void putWindowIndex(int pageId, int windowIndex) { if (pageId != -1 && idToWindowIndices != null) { List indices = (List)idToWindowIndices.get(pageId); Integer index = new Integer(windowIndex); if (indices == null) { indices = new ArrayList(); indices.add(index); idToWindowIndices.put(pageId, indices); } else if (indices.contains(index) == false) { indices.add(index); } } }
/** * */ private void rebuildIndices() { idToWindowIndex = null; idToWindowIndex = new IntHashMap<Integer>(); windowIndexToPageId = null; windowIndexToPageId = new IntHashMap<Integer>(); for (int i = 0; i < windows.size(); ++i) { PageWindowInternal window = windows.get(i); putWindowIndex(window.pageId, i); } }
/** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for this key, the old value is replaced. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> if there was no * mapping for key. A <tt>null</tt> return can also indicate that the HashMap * previously associated <tt>null</tt> with the specified key. */ public Object put(int key, Object value) { int i = indexFor(key, table.length); for (Entry e = table[i]; e != null; e = e.next) { if (key == e.key) { Object oldValue = e.value; e.value = value; return oldValue; } } modCount++; addEntry(key, value, i); return null; }
/** * * @param pageId * @param windowIndex */ private void putWindowIndex(int pageId, int windowIndex) { if (idToWindowIndex != null && pageId != -1 && windowIndex != -1) { Integer oldPageId = windowIndexToPageId.remove(windowIndex); if (oldPageId != null) { idToWindowIndex.remove(oldPageId); } idToWindowIndex.put(pageId, windowIndex); windowIndexToPageId.put(windowIndex, pageId); } }
/** * This method is used instead of put by constructors and pseudoconstructors (clone, * readObject). It does not resize the table, check for comodification, etc. It calls * createEntry rather than addEntry. * * @param key * @param value */ private void putForCreate(final int key, final V value) { int i = indexFor(key, table.length); /** * Look for preexisting entry for key. This will never happen for clone or deserialize. It * will only happen for construction if the input Map is a sorted map whose ordering is * inconsistent w/ equals. */ for (Entry<V> e = table[i]; e != null; e = e.next) { if (key == e.key) { e.value = value; return; } } createEntry(key, value, i); }
if (pages == null) pages = new IntHashMap(); pageMaps.put(getName(), pages); Page page = (Page)pages.get(id); if (page != null) pages.put(id, page); return page; pages.put(id, page); return page;
/** * Returns the entry associated with the specified key in the HashMap. Returns null if the * HashMap contains no mapping for this key. * * @param key * @return The Entry object for the given hash key */ Entry getEntry(int key) { int i = indexFor(key, table.length); Entry e = table[i]; while (e != null && !(key == e.key)) { e = e.next; } return e; }
private void writeObject(java.io.ObjectOutputStream s) throws IOException { IntKeyWeakReference ref = null; while ((ref = (IntKeyWeakReference)queue.poll()) != null) { directComponentRefs.remove(ref.uid); } s.defaultWriteObject(); s.writeInt(directComponentRefs.size()); Iterator it = directComponentRefs.entrySet().iterator(); while (it.hasNext()) { IntHashMap.Entry entry = (Entry)it.next(); s.writeInt(entry.getKey()); ComponentAndInterface cai = (ComponentAndInterface)entry.getValue(); s.writeObject(cai.getComponent()); s.writeUTF(cai.getInterfaceName()); } } }
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); int size = s.readInt(); queue = new ReferenceQueue(); directComponentRefs = new IntHashMap((int)(size * 1.25)); while (--size >= 0) { int uid = s.readInt(); Component component = (Component)s.readObject(); String interfaceName = s.readUTF(); IntKeyWeakReference ref = new IntKeyWeakReference(uid, component, queue); directComponentRefs.put(uid, new ComponentAndInterface(ref, interfaceName)); } }
@Override public String name(int value) { return mapValueToName.get(value); }
void putAllForCreate(final IntHashMap<V> m) { for (Entry<V> entry : m.entrySet()) { putForCreate(entry.getKey(), entry.getValue()); } }
/** * Reconstitute the <tt>HashMap</tt> instance from a stream (i.e., deserialize it). * * @param s * @throws IOException * @throws ClassNotFoundException */ private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); // Read in number of buckets and allocate the bucket array; int numBuckets = s.readInt(); table = new Entry[numBuckets]; init(); // Give subclass a chance to do its thing. // Read in size (number of Mappings) int size = s.readInt(); // Read the keys and values, and put the mappings in the HashMap for (int i = 0; i < size; i++) { int key = s.readInt(); Object value = s.readObject(); putForCreate(key, value); } }
/** * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and values themselves are * not cloned. * * @return a shallow copy of this map. */ @SuppressWarnings("unchecked") @Override public Object clone() throws CloneNotSupportedException { IntHashMap<V> result = null; try { result = (IntHashMap<V>)super.clone(); result.table = new Entry[table.length]; result.entrySet = null; result.modCount = 0; result.size = 0; result.init(); result.putAllForCreate(this); } catch (CloneNotSupportedException e) { // assert false; } return result; }
/** * Gets the combination * * @param uidString * @return ComponentAndInterface */ public ComponentAndInterface getComponentAndInterfaceForUID(String uidString) { IntKeyWeakReference ref = null; while ((ref = (IntKeyWeakReference)queue.poll()) != null) { directComponentRefs.remove(ref.uid); } int uid = Integer.parseInt(uidString); ComponentAndInterface cai = (ComponentAndInterface)directComponentRefs.get(uid); return cai; }
/** * Constructs an empty <tt>HashMap</tt> with the default initial capacity (16) and the default * load factor (0.75). */ @SuppressWarnings("unchecked") public IntHashMap() { loadFactor = DEFAULT_LOAD_FACTOR; threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR); table = new Entry[DEFAULT_INITIAL_CAPACITY]; init(); }
@Override public void add(String name, int value) { mapNameToValue.put(name, Integer.valueOf(value)); mapValueToName.put(value, name); }
/** * Returns <tt>true</tt> if this map maps one or more keys to the specified value. * * @param value * value whose presence in this map is to be tested. * @return <tt>true</tt> if this map maps one or more keys to the specified value. */ public boolean containsValue(final Object value) { if (value == null) { return containsNullValue(); } for (Entry<V> entry : table) { for (Entry<V> e = entry; e != null; e = e.next) { if (value.equals(e.value)) { return true; } } } return false; }
/** * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it). * * @param s * The ObjectOutputStream * @throws IOException * * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted * (int), followed by the <i>size</i> of the HashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) for each key-value * mapping represented by the HashMap The key-value mappings are emitted in the * order that they are returned by <tt>entrySet().iterator()</tt>. * */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) for (Iterator<Entry<V>> i = entrySet().iterator(); i.hasNext();) { Entry<V> e = i.next(); s.writeInt(e.getKey()); s.writeObject(e.getValue()); } }