@Override @SuppressWarnings("unchecked") public T[] getValues(T[] array) { Node<Object> h = head; int s = size(); 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) { Node<Object> next = h.get(); array[i] = (T)next.value; i++; h = next; } if (array.length > s) { array[s] = null; } } return array; }
@Override @Nullable @SuppressWarnings("unchecked") public T getValue() { Node<Object> prev = null; Node<Object> h = head; for (;;) { Node<Object> next = h.get(); if (next == null) { break; } prev = h; h = next; } Object v = h.value; if (v == null) { return null; } if (NotificationLite.isComplete(v) || NotificationLite.isError(v)) { return (T)prev.value; } return (T)v; }
@Override public int size() { int s = 0; Node<Object> h = head; while (s != Integer.MAX_VALUE) { Node<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; } }
SizeBoundReplayBuffer(int maxSize) { this.maxSize = ObjectHelper.verifyPositive(maxSize, "maxSize"); Node<Object> h = new Node<Object>(null); this.tail = h; this.head = h; }
@Override @SuppressWarnings("unchecked") public T[] getValues(T[] array) { Node<Object> h = head; int s = size(); 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) { Node<Object> next = h.get(); array[i] = (T)next.value; i++; h = next; } if (array.length > s) { array[s] = null; } } return array; }
void trim() { if (size > maxSize) { size--; Node<Object> h = head; head = h.get(); } }
@Override @Nullable @SuppressWarnings("unchecked") public T getValue() { Node<Object> prev = null; Node<Object> h = head; for (;;) { Node<Object> next = h.get(); if (next == null) { break; } prev = h; h = next; } Object v = h.value; if (v == null) { return null; } if (NotificationLite.isComplete(v) || NotificationLite.isError(v)) { return (T)prev.value; } return (T)v; }
@Override public int size() { int s = 0; Node<Object> h = head; while (s != Integer.MAX_VALUE) { Node<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; } }
SizeBoundReplayBuffer(int maxSize) { this.maxSize = ObjectHelper.verifyPositive(maxSize, "maxSize"); Node<Object> h = new Node<Object>(null); this.tail = h; this.head = h; }
void trim() { if (size > maxSize) { size--; Node<Object> h = head; head = h.get(); } }