@Override @SuppressWarnings("unchecked") public T[] getValues(T[] array) { TimedNode<Object> h = getHead(); int s = size(h); if (s == 0) { if (array.length != 0) { array[0] = null; } } else { if (array.length < s) { array = (T[])Array.newInstance(array.getClass().getComponentType(), s); } int i = 0; while (i != s) { TimedNode<Object> next = h.get(); array[i] = (T)next.value; i++; h = next; } if (array.length > s) { array[s] = null; } } return array; }
@Override @SuppressWarnings("unchecked") public T[] getValues(T[] array) { TimedNode<Object> h = getHead(); int s = size(h); if (s == 0) { if (array.length != 0) { array[0] = null; } } else { if (array.length < s) { array = (T[])Array.newInstance(array.getClass().getComponentType(), s); } int i = 0; while (i != s) { TimedNode<Object> next = h.get(); array[i] = (T)next.value; i++; h = next; } if (array.length > s) { array[s] = null; } } return array; }
void trimFinal() { long limit = scheduler.now(unit) - maxAge; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next.get() == null) { if (h.value != null) { TimedNode<Object> lasth = new TimedNode<Object>(null, 0L); lasth.lazySet(h.get()); head = lasth; } else { head = h; } break; } if (next.time > limit) { if (h.value != null) { TimedNode<Object> lasth = new TimedNode<Object>(null, 0L); lasth.lazySet(h.get()); head = lasth; } else { head = h; } break; } h = next; } }
@Override @Nullable @SuppressWarnings("unchecked") public T getValue() { TimedNode<Object> prev = null; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next == null) { break; } prev = h; h = next; } long limit = scheduler.now(unit) - maxAge; if (h.time < limit) { return null; } Object v = h.value; if (v == null) { return null; } if (NotificationLite.isComplete(v) || NotificationLite.isError(v)) { return (T)prev.value; } return (T)v; }
void trim() { if (size > maxSize) { size--; TimedNode<Object> h = head; head = h.get(); } long limit = scheduler.now(unit) - maxAge; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next == null) { head = h; break; } if (next.time > limit) { head = h; break; } h = next; } }
int size(TimedNode<Object> h) { int s = 0; while (s != Integer.MAX_VALUE) { TimedNode<Object> next = h.get(); if (next == null) { Object o = h.value; if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { s--; } break; } s++; h = next; } return s; } }
void trimFinal() { long limit = scheduler.now(unit) - maxAge; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next.get() == null) { if (h.value != null) { TimedNode<Object> lasth = new TimedNode<Object>(null, 0L); lasth.lazySet(h.get()); head = lasth; } else { head = h; } break; } if (next.time > limit) { if (h.value != null) { TimedNode<Object> lasth = new TimedNode<Object>(null, 0L); lasth.lazySet(h.get()); head = lasth; } else { head = h; } break; } h = next; } }
/** * Replace a non-empty head node with an empty one to * allow the GC of the inaccessible old value. */ @Override public void trimHead() { TimedNode<Object> h = head; if (h.value != null) { TimedNode<Object> n = new TimedNode<Object>(null, 0); n.lazySet(h.get()); head = n; } }
@Override @Nullable @SuppressWarnings("unchecked") public T getValue() { TimedNode<Object> prev = null; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next == null) { break; } prev = h; h = next; } long limit = scheduler.now(unit) - maxAge; if (h.time < limit) { return null; } Object v = h.value; if (v == null) { return null; } if (NotificationLite.isComplete(v) || NotificationLite.isError(v)) { return (T)prev.value; } return (T)v; }
void trim() { if (size > maxSize) { size--; TimedNode<Object> h = head; head = h.get(); } long limit = scheduler.now(unit) - maxAge; TimedNode<Object> h = head; for (;;) { TimedNode<Object> next = h.get(); if (next == null) { head = h; break; } if (next.time > limit) { head = h; break; } h = next; } }
int size(TimedNode<Object> h) { int s = 0; while (s != Integer.MAX_VALUE) { TimedNode<Object> next = h.get(); if (next == null) { Object o = h.value; if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { s--; } break; } s++; h = next; } return s; } }
/** * Replace a non-empty head node with an empty one to * allow the GC of the inaccessible old value. */ @Override public void trimHead() { TimedNode<Object> h = head; if (h.value != null) { TimedNode<Object> n = new TimedNode<Object>(null, 0); n.lazySet(h.get()); head = n; } }