/** * @param capacity maximum size (larger capacities improve accuracy) */ public StreamSummary(int capacity) { this.capacity = capacity; counterMap = new HashMap<T, ListNode2<Counter<T>>>(); bucketList = new DoublyLinkedList<Bucket>(); }
@SuppressWarnings("unchecked") @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.bucketList = new DoublyLinkedList<Bucket>(); this.capacity = in.readInt(); int size = in.readInt(); this.counterMap = new HashMap<T, ListNode2<Counter<T>>>(size); Bucket currentBucket = null; ListNode2<Bucket> currentBucketNode = null; for (int i = 0; i < size; i++) { Counter<T> c = (Counter<T>) in.readObject(); if (currentBucket == null || c.count != currentBucket.count) { currentBucket = new Bucket(c.count); currentBucketNode = bucketList.add(currentBucket); } c.bucketNode = currentBucketNode; counterMap.put(c.item, currentBucket.counterList.add(c)); } }
@Test public void testDoublyLinkedList() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); assertIsEmpty(list); }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModification() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.add(1); list.add(2); list.add(3); for (int i : list) { if (i == 2) { list.add(4); } } }
@Test public void testAddAfter() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.add(1); ListNode2<Integer> node2 = list.add(2); ListNode2<Integer> node4 = list.add(4); list.addAfter(node2, 3); assertEquals(4, list.size()); assertArrayEquals(new Integer[]{1, 2, 3, 4}, list.toArray()); ListNode2<Integer> node5 = list.addAfter(node4, 5); assertEquals(5, list.size()); assertArrayEquals(new Integer[]{1, 2, 3, 4, 5}, list.toArray()); assertEquals(new Integer(5), list.last()); assertEquals(node5, list.head()); }
@Test public void testEnqueue() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.enqueue(1); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertArrayEquals(new Integer[]{1}, list.toArray()); list.enqueue(2); assertFalse(list.isEmpty()); assertEquals(2, list.size()); assertArrayEquals(new Integer[]{2, 1}, list.toArray()); list.enqueue(3); assertFalse(list.isEmpty()); assertEquals(3, list.size()); assertArrayEquals(new Integer[]{3, 2, 1}, list.toArray()); assertEquals(new Integer(3), list.first()); assertEquals(new Integer(1), list.last()); }
@Test public void testAdd() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.add(1); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertArrayEquals(new Integer[]{1}, list.toArray()); list.add(2); assertFalse(list.isEmpty()); assertEquals(2, list.size()); assertArrayEquals(new Integer[]{1, 2}, list.toArray()); list.add(3); assertFalse(list.isEmpty()); assertEquals(3, list.size()); assertArrayEquals(new Integer[]{1, 2, 3}, list.toArray()); assertEquals(new Integer(1), list.first()); }
@Test public void testAddNode() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.add(new ListNode2<Integer>(1)); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertArrayEquals(new Integer[]{1}, list.toArray()); list.add(new ListNode2<Integer>(2)); assertFalse(list.isEmpty()); assertEquals(2, list.size()); assertArrayEquals(new Integer[]{1, 2}, list.toArray()); list.add(new ListNode2<Integer>(3)); assertFalse(list.isEmpty()); assertEquals(3, list.size()); assertArrayEquals(new Integer[]{1, 2, 3}, list.toArray()); assertEquals(new Integer(1), list.first()); }
@Test public void testRemove() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); ListNode2<Integer> node1 = list.add(1); list.remove(node1);
/** * @param capacity maximum size (larger capacities improve accuracy) */ public StreamSummary(int capacity) { this.capacity = capacity; counterMap = new HashMap<T, ListNode2<Counter<T>>>(); bucketList = new DoublyLinkedList<Bucket>(); }
/** * @param capacity maximum size (larger capacities improve accuracy) */ public StreamSummary(int capacity) { this.capacity = capacity; counterMap = new HashMap<>(); bucketList = new DoublyLinkedList<>(); }
DoublyLinkedList listTwo = new DoublyLinkedList(); for (int x = (localDoublyLinkedList.size() / 2) + 1; x < localDoublyLinkedList.size(); x++) { listTwo.add(x, localDoublyLinkedList.getValue(x)); }
DoublyLinkedList listTwo = new DoublyLinkedList(); for (int x = (localDoublyLinkedList.size() / 2) + 1, offset = x; x < localDoublyLinkedList.size(); x++) { listTwo.add(x - offset, localDoublyLinkedList.getValue(x)); }
@SuppressWarnings("unchecked") @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.bucketList = new DoublyLinkedList<Bucket>(); this.capacity = in.readInt(); int size = in.readInt(); this.counterMap = new HashMap<T, ListNode2<Counter<T>>>(size); Bucket currentBucket = null; ListNode2<Bucket> currentBucketNode = null; for (int i = 0; i < size; i++) { Counter<T> c = (Counter<T>) in.readObject(); if (currentBucket == null || c.count != currentBucket.count) { currentBucket = new Bucket(c.count); currentBucketNode = bucketList.add(currentBucket); } c.bucketNode = currentBucketNode; counterMap.put(c.item, currentBucket.counterList.add(c)); } }