@GuardedBy("Segment.this") <K, V> void copyEvictableEntry(ReferenceEntry<K, V> original, ReferenceEntry<K, V> newEntry) { // TODO(fry): when we link values instead of entries this method can go // away, as can connectEvictables, nullifyEvictable. connectEvictables(original.getPreviousEvictable(), newEntry); connectEvictables(newEntry, original.getNextEvictable()); nullifyEvictable(original); } }
@GuardedBy("Segment.this") <K, V> void copyEvictableEntry(ReferenceEntry<K, V> original, ReferenceEntry<K, V> newEntry) { // TODO(fry): when we link values instead of entries this method can go // away, as can connectEvictables, nullifyEvictable. connectEvictables(original.getPreviousEvictable(), newEntry); connectEvictables(newEntry, original.getNextEvictable()); nullifyEvictable(original); } }
@Override @SuppressWarnings("unchecked") public boolean remove(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; ReferenceEntry<K, V> previous = e.getPreviousEvictable(); ReferenceEntry<K, V> next = e.getNextEvictable(); connectEvictables(previous, next); nullifyEvictable(e); return next != NullEntry.INSTANCE; }
@Override public ReferenceEntry<K, V> poll() { ReferenceEntry<K, V> next = head.getNextEvictable(); if (next == head) { return null; } remove(next); return next; }
@Override public ReferenceEntry<K, V> peek() { ReferenceEntry<K, V> next = head.getNextEvictable(); return (next == head) ? null : next; }
@Override public ReferenceEntry<K, V> peek() { ReferenceEntry<K, V> next = head.getNextEvictable(); return (next == head) ? null : next; }
@Override @SuppressWarnings("unchecked") public boolean remove(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; ReferenceEntry<K, V> previous = e.getPreviousEvictable(); ReferenceEntry<K, V> next = e.getNextEvictable(); connectEvictables(previous, next); nullifyEvictable(e); return next != NullEntry.INSTANCE; }
@Override public int size() { int size = 0; for (ReferenceEntry<K, V> e = head.getNextEvictable(); e != head; e = e.getNextEvictable()) { size++; } return size; }
@Override @SuppressWarnings("unchecked") public boolean contains(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; return e.getNextEvictable() != NullEntry.INSTANCE; }
@Override public boolean offer(ReferenceEntry<K, V> entry) { // unlink connectEvictables(entry.getPreviousEvictable(), entry.getNextEvictable()); // add to tail connectEvictables(head.getPreviousEvictable(), entry); connectEvictables(entry, head); return true; }
@Override protected ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> previous) { ReferenceEntry<K, V> next = previous.getNextEvictable(); return (next == head) ? null : next; } };
@Override public ReferenceEntry<K, V> poll() { ReferenceEntry<K, V> next = head.getNextEvictable(); if (next == head) { return null; } remove(next); return next; }
@Override public ReferenceEntry<K, V> peek() { ReferenceEntry<K, V> next = head.getNextEvictable(); return (next == head) ? null : next; }
@Override public void clear() { ReferenceEntry<K, V> e = head.getNextEvictable(); while (e != head) { ReferenceEntry<K, V> next = e.getNextEvictable(); nullifyEvictable(e); e = next; } head.setNextEvictable(head); head.setPreviousEvictable(head); }
@Override public int size() { int size = 0; for (ReferenceEntry<K, V> e = head.getNextEvictable(); e != head; e = e.getNextEvictable()) { size++; } return size; }
@Override public boolean offer(ReferenceEntry<K, V> entry) { // unlink connectEvictables(entry.getPreviousEvictable(), entry.getNextEvictable()); // add to tail connectEvictables(head.getPreviousEvictable(), entry); connectEvictables(entry, head); return true; }
@Override protected ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> previous) { ReferenceEntry<K, V> next = previous.getNextEvictable(); return (next == head) ? null : next; } };
@Override @SuppressWarnings("unchecked") public boolean contains(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; return e.getNextEvictable() != NullEntry.INSTANCE; }
@Override @SuppressWarnings("unchecked") public boolean remove(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; ReferenceEntry<K, V> previous = e.getPreviousEvictable(); ReferenceEntry<K, V> next = e.getNextEvictable(); connectEvictables(previous, next); nullifyEvictable(e); return next != NullEntry.INSTANCE; }
@Override protected ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> previous) { ReferenceEntry<K, V> next = previous.getNextEvictable(); return (next == head) ? null : next; } };