@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.capacity); out.writeInt(this.size()); for (ListNode2<Bucket> bNode = bucketList.tail(); bNode != null; bNode = bNode.getNext()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { out.writeObject(c); } } }
/** * @param item stream element (<i>e</i>) * @return Pair<isNewItem, itemDropped> where isNewItem is the return value of offer() and itemDropped is null if no item was dropped */ public Pair<Boolean, T> offerReturnAll(T item, int incrementCount) { ListNode2<Counter<T>> counterNode = counterMap.get(item); boolean isNewItem = (counterNode == null); T droppedItem = null; if (isNewItem) { if (size() < capacity) { counterNode = bucketList.enqueue(new Bucket(0)).getValue().counterList.add(new Counter<T>(bucketList.tail(), item)); } else { Bucket min = bucketList.first(); counterNode = min.counterList.tail(); Counter<T> counter = counterNode.getValue(); droppedItem = counter.item; counterMap.remove(droppedItem); counter.item = item; counter.error = min.count; } counterMap.put(item, counterNode); } incrementCounter(counterNode, incrementCount); return new Pair<Boolean, T>(isNewItem, droppedItem); }
private <T> void assertIsEmpty(DoublyLinkedList<T> list) { assertNull(list.tail()); assertNull(list.head()); assertNull(list.first()); assertNull(list.last()); assertTrue(list.isEmpty()); assertEquals(0, list.size()); for (T i : list) { fail("What is this: " + i + " ?"); } }
list.remove(node2); assertEquals(2, list.size()); assertEquals(node1, list.tail()); assertEquals(new Integer(3), list.last()); assertArrayEquals(new Integer[]{1, 3}, list.toArray());
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.capacity); out.writeInt(this.size()); for (ListNode2<Bucket> bNode = bucketList.tail(); bNode != null; bNode = bNode.getNext()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { out.writeObject(c); } } }
/** * @param item stream element (<i>e</i>) * @return Pair<isNewItem, itemDropped> where isNewItem is the return value of offer() and itemDropped is null if no item was dropped */ public Pair<Boolean, T> offerReturnAll(T item, int incrementCount) { ListNode2<Counter<T>> counterNode = counterMap.get(item); boolean isNewItem = (counterNode == null); T droppedItem = null; if (isNewItem) { if (size() < capacity) { counterNode = bucketList.enqueue(new Bucket(0)).getValue().counterList.add(new Counter<T>(bucketList.tail(), item)); } else { Bucket min = bucketList.first(); counterNode = min.counterList.tail(); Counter<T> counter = counterNode.getValue(); droppedItem = counter.item; counterMap.remove(droppedItem); counter.item = item; counter.error = min.count; } counterMap.put(item, counterNode); } incrementCounter(counterNode, incrementCount); return new Pair<Boolean, T>(isNewItem, droppedItem); }
/** * @param item stream element (<i>e</i>) * @return Pair<isNewItem, itemDropped> where isNewItem is the return * value of offer() and itemDropped is null if no item was dropped */ public Pair<Boolean, T> offerReturnAll(T item, int incrementCount) { ListNode2<Counter<T>> counterNode = counterMap.get(item); boolean isNewItem = (counterNode == null); T droppedItem = null; if (isNewItem) { if (size() < capacity) { counterNode = bucketList.enqueue(new Bucket(0)).getValue().counterList .add(new Counter<>(bucketList.tail(), item)); } else { Bucket min = bucketList.first(); counterNode = min.counterList.tail(); Counter<T> counter = counterNode.getValue(); droppedItem = counter.item; counterMap.remove(droppedItem); counter.item = item; counter.error = min.count; } counterMap.put(item, counterNode); } incrementCounter(counterNode, incrementCount); return new Pair<>(isNewItem, droppedItem); }
public static <T> void write(Kryo kryo, Output output, StreamSummary<T> obj) { output.writeInt(obj.capacity); output.writeInt(obj.size()); for (ListNode2<StreamSummary<T>.Bucket> bNode = obj.bucketList.tail(); bNode != null; bNode = bNode.getNext()) { StreamSummary<T>.Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { kryo.writeObject(output, c); } } }