/** * Gets the last key in the map, which is the first inserted. * * @return the eldest key */ public Object lastKey() { if (size == 0) { throw new NoSuchElementException("Map is empty"); } return header.before.getKey(); }
public void remove() { if (last == null) { throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID); } if (parent.modCount != expectedModCount) { throw new ConcurrentModificationException(); } parent.remove(last.getKey()); last = null; expectedModCount = parent.modCount; }
/** * Gets the first key in the map, which is the most recently inserted. * * @return the most recently inserted key */ public Object firstKey() { if (size == 0) { throw new NoSuchElementException("Map is empty"); } return header.after.getKey(); }
public Object previous() { return super.previousEntry().getKey(); }
public void testRemoveLRU() { MockLRUMapSubclass map = new MockLRUMapSubclass(2); assertNull(map.entry); map.put("A", "a"); assertNull(map.entry); map.put("B", "b"); assertNull(map.entry); map.put("C", "c"); // removes oldest, which is A=a assertNotNull(map.entry); assertEquals("A", map.key); assertEquals("a", map.value); assertEquals("C", map.entry.getKey()); // entry is reused assertEquals("c", map.entry.getValue()); // entry is reused assertEquals(false, map.containsKey("A")); assertEquals(true, map.containsKey("B")); assertEquals(true, map.containsKey("C")); }
public Object next() { return super.nextEntry().getKey(); }
public void remove() { if (last == null) { throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID); } if (parent.modCount != expectedModCount) { throw new ConcurrentModificationException(); } parent.remove(last.getKey()); last = null; expectedModCount = parent.modCount; }
/** * Gets the key at the specified index. * * @param index the index to retrieve * @return the key at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public Object get(int index) { return getEntry(index).getKey(); }
/** * Gets the last key in the map, which is the first inserted. * * @return the eldest key */ public Object lastKey() { if (size == 0) { throw new NoSuchElementException("Map is empty"); } return header.before.getKey(); }
public String toString() { if (last != null) { return "Iterator[" + last.getKey() + "=" + last.getValue() + "]"; } else { return "Iterator[]"; } } }
/** * Gets the previous key in sequence. * * @param key the key to get before * @return the previous key */ public Object previousKey(Object key) { LinkEntry entry = (LinkEntry) getEntry(key); return (entry == null || entry.before == header ? null : entry.before.getKey()); }
public Object previous() { return super.previousEntry().getKey(); }
public Object next() { return super.nextEntry().getKey(); }
/** * Gets the next key in sequence. * * @param key the key to get after * @return the next key */ public Object nextKey(Object key) { LinkEntry entry = (LinkEntry) getEntry(key); return (entry == null || entry.after == header ? null : entry.after.getKey()); }
/** * Gets the previous key in sequence. * * @param key the key to get before * @return the previous key */ public Object previousKey(Object key) { LinkEntry entry = (LinkEntry) getEntry(key); return (entry == null || entry.before == header ? null : entry.before.getKey()); }
/** * Gets the next key in sequence. * * @param key the key to get after * @return the next key */ public Object nextKey(Object key) { LinkEntry entry = (LinkEntry) getEntry(key); return (entry == null || entry.after == header ? null : entry.after.getKey()); }
public Object previous() { return super.previousEntry().getKey(); } }
protected boolean removeLRU(LinkEntry entry) { this.entry = entry; this.key = entry.getKey(); this.value = entry.getValue(); return true; } }
/** * Gets the key at the specified index. * * @param index the index to retrieve * @return the key at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public Object get(int index) { return getEntry(index).getKey(); }
public String toString() { if (last != null) { return "Iterator[" + last.getKey() + "=" + last.getValue() + "]"; } else { return "Iterator[]"; } } }