@SuppressWarnings("unchecked") @Override // IntrusiveCollection.Element public void insertInternal(IntrusiveCollection<? extends Element> list, Element prev, Element next) { assert this.pool == null; this.pool = ((CachePool.DirectiveList)list).getCachePool(); this.prev = prev; this.next = next; }
@Override // IntrusiveCollection.Element public void removeInternal(IntrusiveCollection<? extends Element> list) { assert list == pool.getDirectiveList(); this.pool = null; this.prev = null; this.next = null; }
@Override // IntrusiveCollection.Element public Element getPrev(IntrusiveCollection<? extends Element> list) { if (list != pool.getDirectiveList()) { return null; } return this.prev; }
@Override // IntrusiveCollection.Element public Element getNext(IntrusiveCollection<? extends Element> list) { if (list != pool.getDirectiveList()) { return null; } return this.next; }
@Override public void insertInternal(IntrusiveCollection<? extends Element> list, Element prev, Element next) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { throw new RuntimeException("Trying to re-insert an element that " + "is already in the list."); } } Object newTriplets[] = Arrays.copyOf(triplets, triplets.length + 3); newTriplets[triplets.length] = list; newTriplets[triplets.length + 1] = prev; newTriplets[triplets.length + 2] = next; triplets = newTriplets; }
@Override public void setPrev(IntrusiveCollection<? extends Element> list, Element prev) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { triplets[i + 1] = prev; return; } } throw new RuntimeException("Called setPrev on an element that wasn't " + "in the list."); }
@Override public void setNext(IntrusiveCollection<? extends Element> list, Element next) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { triplets[i + 2] = next; return; } } throw new RuntimeException("Called setNext on an element that wasn't " + "in the list."); }
@Override public void removeInternal(IntrusiveCollection<? extends Element> list) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { Object[] newTriplets = new Object[triplets.length - 3]; System.arraycopy(triplets, 0, newTriplets, 0, i); System.arraycopy(triplets, i + 3, newTriplets, i, triplets.length - (i + 3)); triplets = newTriplets; return; } } throw new RuntimeException("Called remove on an element that wasn't " + "in the list."); }
@Override public Element getPrev(IntrusiveCollection<? extends Element> list) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { return (Element)triplets[i + 1]; } } throw new RuntimeException("Called getPrev on an element that wasn't " + "in the list."); }
@Override public Element getNext(IntrusiveCollection<? extends Element> list) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { return (Element)triplets[i + 2]; } } throw new RuntimeException("Called getNext on an element that wasn't " + "in the list."); }
@Override public boolean isInList(IntrusiveCollection<? extends Element> list) { for (int i = 0; i < triplets.length; i += 3) { if (triplets[i] == list) { return true; } } return false; }