/** {@inheritDoc} */ @Override public K getKey() { return iterator.getKey(); }
/** {@inheritDoc} */ @Override public void remove() { iterator.remove(); }
MultiKeyMap multiKeyMap = new MultiKeyMap(); multiKeyMap.put("Key 1A","Key 1B","Value 1"); multiKeyMap.put("Key 2A","Key 2B","Value 2"); multiKeyMap.put("Key 3A","Key 3B","Value 3"); MapIterator it = multiKeyMap.mapIterator(); while (it.hasNext()) { it.next(); MultiKey mk = (MultiKey) it.getKey(); // Option 1 System.out.println(mk.getKey(0)); System.out.println(mk.getKey(1)); // Option 2 for (Object subkey : mk.getKeys()) System.out.println(subkey); System.out.println(it.getValue()); }
/** * Removes all mappings where the first key is that specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has one or more keys, and the first matches that specified. * * @param key1 the first key * @return true if any elements were removed */ public boolean removeAll(final Object key1) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 1 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) { it.remove(); modified = true; } } return modified; }
private MapIterator<Key, Value> removeFromMapToEmit(MapIterator<Key, Value> iterCache) { if (urm) { if (iterCache == null) iterCache = cache.mapIterator(); iterCache.next(); emitKey = iterCache.getKey(); emitValue = iterCache.getValue(); iterCache.remove(); return iterCache; } else { emitKey = ((LRUMap<Key,Value>)cache).firstKey(); // LRU emitValue = cache.remove(emitKey); return null; } }
/** {@inheritDoc} */ @Override public V getValue() { return iterator.getValue(); }
/** {@inheritDoc} */ @Override public K next() { return iterator.next(); }
@Override public boolean hasNext() { return iterator.hasNext(); }
/** * Removes all mappings where the first two keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has two or more keys, and the first two match those specified. * * @param key1 the first key * @param key2 the second key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 2 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) { it.remove(); modified = true; } } return modified; }
@Override public V getValue() { return iterator.getValue(); }
@Override public K next() { return iterator.next(); }
/** {@inheritDoc} */ @Override public boolean hasNext() { return iterator.hasNext(); }
/** * Gets the hash code value for this map as per the API. * * @param dataElement either {@link DataElement#KEY} key} * or the {@link DataElement#VALUE value}. * @return the hash code value for this map */ private int doHashCode(final DataElement dataElement) { int total = 0; if (nodeCount > 0) { for (final MapIterator<?, ?> it = getMapIterator(dataElement); it.hasNext(); ) { final Object key = it.next(); final Object value = it.getValue(); total += key.hashCode() ^ value.hashCode(); } } return total; }
/** * Removes all mappings where the first three keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has three or more keys, and the first three match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2, final Object key3) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 3 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)))) { it.remove(); modified = true; } } return modified; }
@Override public K getKey() { return iterator.getKey(); }
/** * Write the map out using a custom routine. * * @param out the output stream * @throws IOException if an error occurs while writing to the stream */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(size()); for (final MapIterator<?, ?> it = mapIterator(); it.hasNext();) { out.writeObject(it.next()); // key out.writeObject(it.getValue()); // value } }
/** * Removes all mappings where the first four keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has four or more keys, and the first four match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2, final Object key3, final Object key4) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 4 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)))) { it.remove(); modified = true; } } return modified; }
/** * Gets the string form of this map as per AbstractMap. * * @param dataElement either {@link DataElement#KEY} key} * or the {@link DataElement#VALUE value}. * @return the string form of this map */ private String doToString(final DataElement dataElement) { if (nodeCount == 0) { return "{}"; } final StringBuilder buf = new StringBuilder(nodeCount * 32); buf.append('{'); final MapIterator<?, ?> it = getMapIterator(dataElement); boolean hasNext = it.hasNext(); while (hasNext) { final Object key = it.next(); final Object value = it.getValue(); buf.append(key == this ? "(this Map)" : key) .append('=') .append(value == this ? "(this Map)" : value); hasNext = it.hasNext(); if (hasNext) { buf.append(", "); } } buf.append('}'); return buf.toString(); }