/** * Returns a string representation of this map. The string representation consists of a list of * key-value mappings in the order returned by the map's <tt>entrySet</tt> view's iterator, * enclosed in braces (<tt>"{}"</tt>). Adjacent mappings are separated by the characters * <tt>", "</tt> (comma and space). Each key-value mapping is rendered as the key followed by an * equals sign (<tt>"="</tt>) followed by the associated value. Keys and values are converted to * strings as by {@link String#valueOf(Object)}. * * @return a string representation of this map */ public String toString() { Iterator<Entry> i = entrySet().iterator(); if (!i.hasNext()) return "{}"; StringBuilder sb = new StringBuilder(); sb.append('{'); for (;;) { Entry e = i.next(); Object key = e.getKey(); int value = e.getValue(); sb.append(key == this ? "(this Map)" : key); sb.append('='); sb.append(value); if (!i.hasNext()) return sb.append('}').toString(); sb.append(", "); } }
/** * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it). * * @serialData The <i>capacity</i> of the IntHashMap (the length of the bucket array) is emitted * (int), followed by the <i>size</i> (an int, the number of key-value mappings), * followed by the key (Object) and value (Object) for each key-value mapping. The * key-value mappings are emitted in no particular order. */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { Iterator<Entry> i = (size > 0) ? entrySet0().iterator() : null; // 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) if (i != null) { while (i.hasNext()) { Entry e = i.next(); s.writeObject(e.getKey()); s.writeInt(e.getValue()); } } }
private void putAllForCreate(ObjectIntHashMap m) { for (Iterator i = m.entrySet().iterator(); i.hasNext();) { Entry e = (Entry) i.next(); putForCreate(e.getKey(), e.getValue()); } }
while (i.hasNext()) { Entry e = i.next(); Object key = e.getKey(); int value = e.getValue(); if (!(m.containsKey(key))) {
put(e.getKey(), e.getValue());
/** * Special version of remove for EntrySet. */ Entry removeMapping(Object o) { if (!(o instanceof Entry)) return null; Entry entry = (Entry) o; Object key = entry.getKey(); int hash = (key == null) ? 0 : hash(hashingStrategy.hashCode(key)); int i = indexFor(hash, table.length); Entry prev = table[i]; Entry e = prev; while (e != null) { Entry next = e.next; if (e.hash == hash && e.equals(entry)) { modCount++; size--; if (prev == e) table[i] = next; else prev.next = next; e.recordRemoval(this); return e; } prev = e; e = next; } return e; }
@Override public void toData(DataOutput out) throws IOException { DataSerializer.writeObject(this.elementType, out); out.writeInt(this.size()); this.writeNumNulls(out); // TODO:Asif: Should we actually pass the limit in serialization? // For the time being not passing , assuming PR Has parsed // it // out.writeInt(this.limit); int numLeft = this.size() - this.numNulls; for (Iterator<Entry> itr = this.map.entrySet().iterator(); itr.hasNext() && numLeft > 0;) { Entry entry = itr.next(); Object key = entry.getKey(); DataSerializer.writeObject(key, out); int occurrence = entry.getValue(); if (numLeft < occurrence) { occurrence = numLeft; } out.writeInt(occurrence); numLeft -= occurrence; } }
public String toString() { return getKey() + "=" + getValue(); }
@Override protected Object keyFromEntry(Object entry) { return ((Entry) entry).getKey(); }
@Override public Object next() { return nextEntry().getKey(); } }
@Override public boolean contains(Object o) { if (!(o instanceof Entry)) return false; Entry e = (Entry) o; Entry candidate = getEntry(e.getKey()); return candidate != null && candidate.equals(e); }