Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-02-26 20:39:13 +0000
committerBrian Vosburgh2017-05-18 22:36:46 +0000
commit72419e50e9a624fd9deab3cea612aafe41fd7f35 (patch)
treea1d3a44590523972bee8a1be210d8a96727ac414 /common/tests
parent207544a489a8348e2aab8620a0da4054e32f6c15 (diff)
downloadwebtools.dali-72419e50e9a624fd9deab3cea612aafe41fd7f35.tar.gz
webtools.dali-72419e50e9a624fd9deab3cea612aafe41fd7f35.tar.xz
webtools.dali-72419e50e9a624fd9deab3cea612aafe41fd7f35.zip
remove Queue Node caches
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueue.java282
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueueTests.java228
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java1
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java155
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java27
5 files changed, 511 insertions, 182 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueue.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueue.java
new file mode 100644
index 0000000000..ca1f9399a8
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueue.java
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.queue;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Linked FIFO implementation of the {@link Queue} interface.
+ * @param <E> the type of elements maintained by the queue
+ */
+public class CachingLinkedQueue<E>
+ implements Queue<E>, Cloneable, Serializable
+{
+ private final NodeFactory<E> nodeFactory;
+ private transient Node<E> head; // next element to dequeue
+ private transient Node<E> tail; // last element
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty queue with no node cache.
+ */
+ public CachingLinkedQueue() {
+ this(0);
+ }
+
+ /**
+ * Construct an empty queue with a node cache with the specified size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public CachingLinkedQueue(int cacheSize) {
+ this(CachingLinkedQueue.<E>buildNodeFactory(cacheSize));
+ this.head = null;
+ }
+
+ private static <E> NodeFactory<E> buildNodeFactory(int cacheSize) {
+ if (cacheSize < -1) {
+ throw new IllegalArgumentException("Cache size must be greater than or equal to -1: " + cacheSize); //$NON-NLS-1$
+ }
+ return (cacheSize == 0) ? SimpleNodeFactory.<E>instance() : new CachingNodeFactory<>(cacheSize);
+ }
+
+ private CachingLinkedQueue(NodeFactory<E> nodeFactory) {
+ super();
+ this.nodeFactory = nodeFactory;
+ this.head = null;
+ this.tail = null;
+ }
+
+
+ // ********** Queue implementation **********
+
+ public void enqueue(E element) {
+ Node<E> newNode = this.nodeFactory.buildNode(element, null);
+ if (this.tail == null) {
+ this.head = newNode; // first node
+ } else {
+ this.tail.next = newNode;
+ }
+ this.tail = newNode;
+ }
+
+ public E dequeue() {
+ if (this.head == null) {
+ throw new NoSuchElementException();
+ }
+ Node<E> node = this.head;
+ this.head = node.next;
+ if (this.head == null) {
+ this.tail = null; // last node
+ }
+ E element = node.element;
+ this.nodeFactory.release(node);
+ return element;
+ }
+
+ public E peek() {
+ if (this.head == null) {
+ throw new NoSuchElementException();
+ }
+ return this.head.element;
+ }
+
+ public boolean isEmpty() {
+ return this.head == null;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public CachingLinkedQueue<E> clone() {
+ CachingLinkedQueue<E> clone = new CachingLinkedQueue<>(this.nodeFactory.copy());
+ E[] elements = this.buildElements();
+ for (E element : elements) {
+ clone.enqueue(element);
+ }
+ return clone;
+ }
+
+ @SuppressWarnings("unchecked")
+ private E[] buildElements() {
+ int size = this.size();
+ if (size == 0) {
+ return (E[]) ObjectTools.EMPTY_OBJECT_ARRAY;
+ }
+ E[] elements = (E[]) new Object[size];
+ int i = 0;
+ for (Node<E> node = this.head; node != null; node = node.next) {
+ elements[i++] = node.element;
+ }
+ return elements;
+ }
+
+ private int size() {
+ int size = 0;
+ for (Node<E> node = this.head; node != null; node = node.next) {
+ size++;
+ }
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.buildElements());
+ }
+
+
+ // ********** Serializable "implementation" **********
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
+ // write nodeFactory (and any hidden stuff)
+ stream.defaultWriteObject();
+ Object[] elements = this.buildElements();
+ stream.writeInt(elements.length);
+ for (Object element : elements) {
+ stream.writeObject(element);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
+ // read nodeFactory (and any hidden stuff)
+ stream.defaultReadObject();
+ int len = stream.readInt();
+ for (int i = len; i-- > 0; ) {
+ this.enqueue((E) stream.readObject());
+ }
+ }
+
+
+ // ********** Node classes **********
+
+ private static final class Node<E> {
+ E element;
+ Node<E> next;
+
+ Node(E element, Node<E> next) {
+ super();
+ this.element = element;
+ this.next = next;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.element);
+ }
+ }
+
+ private abstract static class NodeFactory<E> {
+ NodeFactory() {
+ super();
+ }
+
+ Node<E> buildNode(E element, Node<E> next) {
+ return new Node<>(element, next);
+ }
+
+ abstract void release(Node<E> node);
+
+ abstract NodeFactory<E> copy();
+ }
+
+ private static class SimpleNodeFactory<E>
+ extends NodeFactory<E>
+ implements Serializable
+ {
+ @SuppressWarnings("rawtypes")
+ public static final NodeFactory INSTANCE = new SimpleNodeFactory();
+ @SuppressWarnings("unchecked")
+ public static <E> NodeFactory<E> instance() {
+ return INSTANCE;
+ }
+
+ private SimpleNodeFactory() {
+ super();
+ }
+
+ @Override
+ void release(Node<E> node) {
+ // NOP
+ }
+
+ @Override
+ NodeFactory<E> copy() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+ private static final class CachingNodeFactory<E>
+ extends NodeFactory<E>
+ implements Serializable
+ {
+ private final int maxCacheSize;
+ private transient int cacheSize = 0;
+ private transient Node<E> cacheHead;
+ private static final long serialVersionUID = 1L;
+
+ CachingNodeFactory(int maxCacheSize) {
+ super();
+ this.maxCacheSize = maxCacheSize;
+ }
+
+ @Override
+ Node<E> buildNode(E element, Node<E> next) {
+ if (this.cacheHead == null) {
+ return super.buildNode(element, next);
+ }
+ Node<E> node = this.cacheHead;
+ this.cacheHead = node.next;
+ this.cacheSize--;
+ node.element = element;
+ node.next = next;
+ return node;
+ }
+
+ @Override
+ void release(Node<E> node) {
+ if ((this.maxCacheSize == -1) || (this.cacheSize < this.maxCacheSize)) {
+ node.element = null; // allow GC to work
+ node.next = this.cacheHead;
+ this.cacheHead = node;
+ this.cacheSize++;
+ }
+ }
+
+ @Override
+ NodeFactory<E> copy() {
+ return new CachingNodeFactory<>(this.maxCacheSize);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.cacheSize);
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueueTests.java
new file mode 100644
index 0000000000..b1a894b69f
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/CachingLinkedQueueTests.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.queue;
+
+import java.util.Arrays;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+
+@SuppressWarnings("nls")
+public class CachingLinkedQueueTests
+ extends QueueTests
+{
+ public CachingLinkedQueueTests(String name) {
+ super(name);
+ }
+
+ @Override
+ Queue<String> buildQueue() {
+ return new CachingLinkedQueue<>();
+ }
+
+ public void testConstructorInt_IAE() {
+ boolean exCaught = false;
+ try {
+ Queue<String> queue = new CachingLinkedQueue<>(-3);
+ fail("bogus queue: " + queue);
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testSize() {
+ Queue<String> queue = this.buildQueue();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+
+ assertEquals(0, ((Integer) ObjectTools.execute(queue, "size")).intValue());
+ queue.enqueue(first);
+ queue.enqueue(second);
+ assertEquals(2, ((Integer) ObjectTools.execute(queue, "size")).intValue());
+ queue.enqueue(third);
+ assertEquals(3, ((Integer) ObjectTools.execute(queue, "size")).intValue());
+ queue.dequeue();
+ assertEquals(2, ((Integer) ObjectTools.execute(queue, "size")).intValue());
+ queue.dequeue();
+ queue.dequeue();
+ assertEquals(0, ((Integer) ObjectTools.execute(queue, "size")).intValue());
+ }
+
+ public void testBuildElements() {
+ Queue<String> queue = this.buildQueue();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ queue.enqueue(first);
+ queue.enqueue(second);
+ queue.enqueue(third);
+
+ Object[] elements = new Object[] { first, second, third };
+ assertTrue(Arrays.equals(elements, ((Object[]) ObjectTools.execute(queue, "buildElements"))));
+ }
+
+ public void testNodeCache_max() {
+ Queue<String> queue = new CachingLinkedQueue<>(2);
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ String fourth = "fourth";
+ String fifth = "fifth";
+
+ Object factory = ObjectTools.get(queue, "nodeFactory");
+
+ this.verifyNodeCache(0, factory);
+ queue.enqueue(first);
+ this.verifyNodeCache(0, factory);
+ queue.enqueue(second);
+ queue.enqueue(third);
+ queue.enqueue(fourth);
+ queue.enqueue(fifth);
+ this.verifyNodeCache(0, factory);
+ assertNull(ObjectTools.get(factory, "cacheHead"));
+
+ queue.dequeue();
+ this.verifyNodeCache(1, factory);
+ queue.dequeue();
+ this.verifyNodeCache(2, factory);
+ queue.dequeue();
+ this.verifyNodeCache(2, factory);
+ queue.dequeue();
+ this.verifyNodeCache(2, factory);
+ queue.dequeue();
+ this.verifyNodeCache(2, factory);
+ queue.enqueue(first);
+ this.verifyNodeCache(1, factory);
+ queue.enqueue(second);
+ this.verifyNodeCache(0, factory);
+ queue.enqueue(third);
+ this.verifyNodeCache(0, factory);
+ }
+
+ public void testNodeCache_unlimited() {
+ Queue<String> queue = new CachingLinkedQueue<>(-1);
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ String fourth = "fourth";
+ String fifth = "fifth";
+
+ Object factory = ObjectTools.get(queue, "nodeFactory");
+
+ this.verifyNodeCache(0, factory);
+ queue.enqueue(first);
+ this.verifyNodeCache(0, factory);
+ queue.enqueue(second);
+ queue.enqueue(third);
+ queue.enqueue(fourth);
+ queue.enqueue(fifth);
+ this.verifyNodeCache(0, factory);
+ assertNull(ObjectTools.get(factory, "cacheHead"));
+
+ queue.dequeue();
+ this.verifyNodeCache(1, factory);
+ queue.dequeue();
+ this.verifyNodeCache(2, factory);
+ queue.dequeue();
+ this.verifyNodeCache(3, factory);
+ queue.dequeue();
+ this.verifyNodeCache(4, factory);
+ queue.dequeue();
+ this.verifyNodeCache(5, factory);
+ queue.enqueue(first);
+ this.verifyNodeCache(4, factory);
+ queue.enqueue(second);
+ this.verifyNodeCache(3, factory);
+ queue.enqueue(third);
+ this.verifyNodeCache(2, factory);
+ queue.enqueue(fourth);
+ this.verifyNodeCache(1, factory);
+ queue.enqueue(fifth);
+ this.verifyNodeCache(0, factory);
+ }
+
+ public void verifyNodeCache(int size, Object factory) {
+ assertEquals(size, ((Integer) ObjectTools.get(factory, "cacheSize")).intValue());
+ int nodeCount = 0;
+ for (Object node = ObjectTools.get(factory, "cacheHead"); node != null; node = ObjectTools.get(node, "next")) {
+ nodeCount++;
+ }
+ assertEquals(size, nodeCount);
+ }
+
+ public void testNodeToString() {
+ Queue<String> queue = new CachingLinkedQueue<>();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ queue.enqueue(first);
+ queue.enqueue(second);
+ queue.enqueue(third);
+
+ Object head = ObjectTools.get(queue, "head");
+ assertTrue(head.toString().startsWith("CachingLinkedQueue.Node"));
+ assertTrue(head.toString().endsWith("(first)"));
+ }
+
+ public void testSimpleNodeFactoryToString() {
+ Queue<String> queue = new CachingLinkedQueue<>();
+ Object factory = ObjectTools.get(queue, "nodeFactory");
+ assertEquals("CachingLinkedQueue.SimpleNodeFactory", factory.toString());
+ }
+
+ public void testCachingNodeFactoryToString() {
+ Queue<String> queue = new CachingLinkedQueue<>(20);
+ Object factory = ObjectTools.get(queue, "nodeFactory");
+ assertTrue(factory.toString().startsWith("CachingLinkedQueue.CachingNodeFactory"));
+ assertTrue(factory.toString().endsWith("(0)"));
+ }
+
+ public void testClone_caching() throws Exception {
+ CachingLinkedQueue<String> original = new CachingLinkedQueue<>(20);
+ original.enqueue("first");
+
+ CachingLinkedQueue<String> clone = original.clone();
+ assertEquals(original.peek(), clone.peek());
+ assertEquals(original.dequeue(), clone.dequeue());
+ assertNotSame(original, clone);
+ assertTrue(original.isEmpty());
+ assertEquals(original.isEmpty(), clone.isEmpty());
+
+ original.enqueue("second");
+ assertFalse(original.isEmpty());
+ // clone should still be empty
+ assertTrue(clone.isEmpty());
+
+ Object factory = ObjectTools.get(original, "nodeFactory");
+ assertTrue(factory.toString().startsWith("CachingLinkedQueue.CachingNodeFactory"));
+ }
+
+ public void testSerialization_caching() throws Exception {
+ Queue<String> original = new CachingLinkedQueue<>(20);
+ original.enqueue("first");
+
+ Queue<String> clone = TestTools.serialize(original);
+ assertEquals(original.peek(), clone.peek());
+ assertEquals(original.dequeue(), clone.dequeue());
+ assertNotSame(original, clone);
+ assertTrue(original.isEmpty());
+ assertEquals(original.isEmpty(), clone.isEmpty());
+
+ original.enqueue("second");
+ assertFalse(original.isEmpty());
+ // clone should still be empty
+ assertTrue(clone.isEmpty());
+
+ Object factory = ObjectTools.get(original, "nodeFactory");
+ assertTrue(factory.toString().startsWith("CachingLinkedQueue.CachingNodeFactory"));
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java
index 82ef34512b..217cd6002c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java
@@ -21,6 +21,7 @@ public class JptCommonUtilityQueueTests {
TestSuite suite = new TestSuite(JptCommonUtilityQueueTests.class.getPackage().getName());
suite.addTestSuite(ArrayQueueTests.class);
+ suite.addTestSuite(CachingLinkedQueueTests.class);
suite.addTestSuite(ConcurrentQueueTests.class);
suite.addTestSuite(DequeQueueTests.class);
suite.addTestSuite(EmptyQueueTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java
index bc1ef8a78c..9ec0885ac9 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java
@@ -11,10 +11,8 @@ package org.eclipse.jpt.common.utility.tests.internal.queue;
import java.util.Arrays;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.queue.LinkedQueue;
import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
import org.eclipse.jpt.common.utility.queue.Queue;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
public class LinkedQueueTests
@@ -29,17 +27,6 @@ public class LinkedQueueTests
return QueueTools.linkedQueue();
}
- public void testConstructorInt_IAE() {
- boolean exCaught = false;
- try {
- Queue<String> queue = QueueTools.linkedQueue(-3);
- fail("bogus queue: " + queue);
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
public void testSize() {
Queue<String> queue = this.buildQueue();
String first = "first";
@@ -72,95 +59,6 @@ public class LinkedQueueTests
assertTrue(Arrays.equals(elements, ((Object[]) ObjectTools.execute(queue, "buildElements"))));
}
- public void testNodeCache_max() {
- Queue<String> queue = new LinkedQueue<>(2);
- String first = "first";
- String second = "second";
- String third = "third";
- String fourth = "fourth";
- String fifth = "fifth";
-
- Object factory = ObjectTools.get(queue, "nodeFactory");
-
- this.verifyNodeCache(0, factory);
- queue.enqueue(first);
- this.verifyNodeCache(0, factory);
- queue.enqueue(second);
- queue.enqueue(third);
- queue.enqueue(fourth);
- queue.enqueue(fifth);
- this.verifyNodeCache(0, factory);
- assertNull(ObjectTools.get(factory, "cacheHead"));
-
- queue.dequeue();
- this.verifyNodeCache(1, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.enqueue(first);
- this.verifyNodeCache(1, factory);
- queue.enqueue(second);
- this.verifyNodeCache(0, factory);
- queue.enqueue(third);
- this.verifyNodeCache(0, factory);
- }
-
- public void testNodeCache_unlimited() {
- Queue<String> queue = new LinkedQueue<>(-1);
- String first = "first";
- String second = "second";
- String third = "third";
- String fourth = "fourth";
- String fifth = "fifth";
-
- Object factory = ObjectTools.get(queue, "nodeFactory");
-
- this.verifyNodeCache(0, factory);
- queue.enqueue(first);
- this.verifyNodeCache(0, factory);
- queue.enqueue(second);
- queue.enqueue(third);
- queue.enqueue(fourth);
- queue.enqueue(fifth);
- this.verifyNodeCache(0, factory);
- assertNull(ObjectTools.get(factory, "cacheHead"));
-
- queue.dequeue();
- this.verifyNodeCache(1, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(3, factory);
- queue.dequeue();
- this.verifyNodeCache(4, factory);
- queue.dequeue();
- this.verifyNodeCache(5, factory);
- queue.enqueue(first);
- this.verifyNodeCache(4, factory);
- queue.enqueue(second);
- this.verifyNodeCache(3, factory);
- queue.enqueue(third);
- this.verifyNodeCache(2, factory);
- queue.enqueue(fourth);
- this.verifyNodeCache(1, factory);
- queue.enqueue(fifth);
- this.verifyNodeCache(0, factory);
- }
-
- public void verifyNodeCache(int size, Object factory) {
- assertEquals(size, ((Integer) ObjectTools.get(factory, "cacheSize")).intValue());
- int nodeCount = 0;
- for (Object node = ObjectTools.get(factory, "cacheHead"); node != null; node = ObjectTools.get(node, "next")) {
- nodeCount++;
- }
- assertEquals(size, nodeCount);
- }
-
public void testNodeToString() {
Queue<String> queue = QueueTools.linkedQueue();
String first = "first";
@@ -174,57 +72,4 @@ public class LinkedQueueTests
assertTrue(head.toString().startsWith("LinkedQueue.Node"));
assertTrue(head.toString().endsWith("(first)"));
}
-
- public void testSimpleNodeFactoryToString() {
- Queue<String> queue = QueueTools.linkedQueue();
- Object factory = ObjectTools.get(queue, "nodeFactory");
- assertEquals("LinkedQueue.SimpleNodeFactory", factory.toString());
- }
-
- public void testCachingNodeFactoryToString() {
- Queue<String> queue = QueueTools.linkedQueue(20);
- Object factory = ObjectTools.get(queue, "nodeFactory");
- assertTrue(factory.toString().startsWith("LinkedQueue.CachingNodeFactory"));
- assertTrue(factory.toString().endsWith("(0)"));
- }
-
- public void testClone_caching() throws Exception {
- LinkedQueue<String> original = QueueTools.linkedQueue(20);
- original.enqueue("first");
-
- LinkedQueue<String> clone = original.clone();
- assertEquals(original.peek(), clone.peek());
- assertEquals(original.dequeue(), clone.dequeue());
- assertNotSame(original, clone);
- assertTrue(original.isEmpty());
- assertEquals(original.isEmpty(), clone.isEmpty());
-
- original.enqueue("second");
- assertFalse(original.isEmpty());
- // clone should still be empty
- assertTrue(clone.isEmpty());
-
- Object factory = ObjectTools.get(original, "nodeFactory");
- assertTrue(factory.toString().startsWith("LinkedQueue.CachingNodeFactory"));
- }
-
- public void testSerialization_caching() throws Exception {
- Queue<String> original = QueueTools.linkedQueue(20);
- original.enqueue("first");
-
- Queue<String> clone = TestTools.serialize(original);
- assertEquals(original.peek(), clone.peek());
- assertEquals(original.dequeue(), clone.dequeue());
- assertNotSame(original, clone);
- assertTrue(original.isEmpty());
- assertEquals(original.isEmpty(), clone.isEmpty());
-
- original.enqueue("second");
- assertFalse(original.isEmpty());
- // clone should still be empty
- assertTrue(clone.isEmpty());
-
- Object factory = ObjectTools.get(original, "nodeFactory");
- assertTrue(factory.toString().startsWith("LinkedQueue.CachingNodeFactory"));
- }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java
index 852ed96a0a..534ee84d38 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java
@@ -339,11 +339,6 @@ public class QueueToolsTests
assertTrue(queue.isEmpty());
}
- public void testLinkedQueueInt() {
- LinkedQueue<String> queue = QueueTools.linkedQueue(20);
- assertTrue(queue.isEmpty());
- }
-
public void testLinkedQueueIterable() {
ArrayList<String> iterable = new ArrayList<>();
iterable.add("one");
@@ -355,17 +350,6 @@ public class QueueToolsTests
assertEquals("three", queue.dequeue());
}
- public void testLinkedQueueIterableInt() {
- ArrayList<String> iterable = new ArrayList<>();
- iterable.add("one");
- iterable.add("two");
- iterable.add("three");
- Queue<String> queue = QueueTools.linkedQueue(iterable, 5);
- assertEquals("one", queue.dequeue());
- assertEquals("two", queue.dequeue());
- assertEquals("three", queue.dequeue());
- }
-
public void testLinkedQueueIterator() {
ArrayList<String> iterable = new ArrayList<>();
iterable.add("one");
@@ -377,17 +361,6 @@ public class QueueToolsTests
assertEquals("three", queue.dequeue());
}
- public void testLinkedQueueIteratorInt() {
- ArrayList<String> iterable = new ArrayList<>();
- iterable.add("one");
- iterable.add("two");
- iterable.add("three");
- Queue<String> queue = QueueTools.linkedQueue(iterable.iterator(), 5);
- assertEquals("one", queue.dequeue());
- assertEquals("two", queue.dequeue());
- assertEquals("three", queue.dequeue());
- }
-
public void testLinkedQueueArray() {
ArrayList<String> iterable = new ArrayList<>();
iterable.add("one");

Back to the top