Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-08-10 17:17:17 +0000
committerBrian Vosburgh2017-05-18 22:38:48 +0000
commit5545b00610a722b22e80c97481996f284d17785e (patch)
treec0ec6cf70bfcd32209154e4aa6e4f4bdf1ae64df
parent483d225def0875941fba5cef7642cde054271465 (diff)
downloadwebtools.dali-5545b00610a722b22e80c97481996f284d17785e.tar.gz
webtools.dali-5545b00610a722b22e80c97481996f284d17785e.tar.xz
webtools.dali-5545b00610a722b22e80c97481996f284d17785e.zip
begin converting Transformers to lambdas
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer_.java55
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer.java55
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer_.java56
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionSingleElementTransformer.java53
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java24
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformer_Tests.java64
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformerTests.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformer_Tests.java64
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java6
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/TransformerToolsTests.java182
14 files changed, 198 insertions, 614 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer.java
deleted file mode 100644
index ed9a07877d..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.transformer;
-
-import java.io.Serializable;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Transformer that transforms a collection into its first element.
- * If the collection is empty, the transformer returns <code>null</code>.
- *
- * @param <E> the type of elements held by the collection
- *
- * @see CollectionFirstElementTransformer_
- */
-public final class CollectionFirstElementTransformer<E>
- implements Transformer<Collection<? extends E>, E>, Serializable
-{
- @SuppressWarnings("rawtypes")
- public static final Transformer INSTANCE = new CollectionFirstElementTransformer();
-
- @SuppressWarnings("unchecked")
- public static <E> Transformer<Collection<? extends E>, E> instance() {
- return INSTANCE;
- }
-
- // ensure single instance
- private CollectionFirstElementTransformer() {
- super();
- }
-
- public E transform(Collection<? extends E> collection) {
- return collection.isEmpty() ? null : collection.iterator().next();
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer_.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer_.java
deleted file mode 100644
index 9c6d36f63c..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionFirstElementTransformer_.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.transformer;
-
-import java.io.Serializable;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Transformer that transforms a collection into its first element.
- * If the collection is empty, the transformer throws a
- * {@link java.util.NoSuchElementException}.
- *
- * @param <E> the type of elements held by the collection
- *
- * @see CollectionFirstElementTransformer
- */
-public final class CollectionFirstElementTransformer_<E>
- implements Transformer<Collection<? extends E>, E>, Serializable
-{
- @SuppressWarnings("rawtypes")
- public static final Transformer INSTANCE = new CollectionFirstElementTransformer_();
-
- @SuppressWarnings("unchecked")
- public static <E> Transformer<Collection<? extends E>, E> instance() {
- return INSTANCE;
- }
-
- // ensure single instance
- private CollectionFirstElementTransformer_() {
- super();
- }
-
- public E transform(Collection<? extends E> collection) {
- return collection.iterator().next();
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer.java
deleted file mode 100644
index 5b07acc7cf..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.transformer;
-
-import java.io.Serializable;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Transformer that transforms a collection into its last element.
- * If the collection is empty, the transformer returns <code>null</code>.
- *
- * @param <E> the type of elements held by the collection
- *
- * @see CollectionLastElementTransformer_
- */
-public final class CollectionLastElementTransformer<E>
- implements Transformer<Collection<? extends E>, E>, Serializable
-{
- @SuppressWarnings("rawtypes")
- public static final Transformer INSTANCE = new CollectionLastElementTransformer();
-
- @SuppressWarnings("unchecked")
- public static <E> Transformer<Collection<? extends E>, E> instance() {
- return INSTANCE;
- }
-
- // ensure single instance
- private CollectionLastElementTransformer() {
- super();
- }
-
- public E transform(Collection<? extends E> collection) {
- return collection.isEmpty() ? null : IterableTools.last(collection);
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer_.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer_.java
deleted file mode 100644
index f3f253f3cb..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionLastElementTransformer_.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.transformer;
-
-import java.io.Serializable;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Transformer that transforms a collection into its last element.
- * If the collection is empty, the transformer throws a
- * {@link java.util.NoSuchElementException}.
- *
- * @param <E> the type of elements held by the collection
- *
- * @see CollectionLastElementTransformer
- */
-public final class CollectionLastElementTransformer_<E>
- implements Transformer<Collection<? extends E>, E>, Serializable
-{
- @SuppressWarnings("rawtypes")
- public static final Transformer INSTANCE = new CollectionLastElementTransformer_();
-
- @SuppressWarnings("unchecked")
- public static <E> Transformer<Collection<? extends E>, E> instance() {
- return INSTANCE;
- }
-
- // ensure single instance
- private CollectionLastElementTransformer_() {
- super();
- }
-
- public E transform(Collection<? extends E> collection) {
- return IterableTools.last(collection);
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionSingleElementTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionSingleElementTransformer.java
deleted file mode 100644
index 44eec81d91..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/CollectionSingleElementTransformer.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.transformer;
-
-import java.io.Serializable;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Transformer that transforms a collection into its <em>single</em> element.
- * If the collection is empty or contains more than one element,
- * the transformer returns <code>null</code>.
- *
- * @param <E> the type of elements held by the collection
- */
-public final class CollectionSingleElementTransformer<E>
- implements Transformer<Collection<? extends E>, E>, Serializable
-{
- @SuppressWarnings("rawtypes")
- public static final Transformer INSTANCE = new CollectionSingleElementTransformer();
-
- @SuppressWarnings("unchecked")
- public static <E> Transformer<Collection<? extends E>, E> instance() {
- return INSTANCE;
- }
-
- // ensure single instance
- private CollectionSingleElementTransformer() {
- super();
- }
-
- public E transform(Collection<? extends E> collection) {
- return (collection.size() == 1) ? collection.iterator().next() : null;
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java
deleted file mode 100644
index 8843f8c730..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/PredicateTransformer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013, 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.internal.transformer;
-
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.predicate.Predicate;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Adapt the {@link Predicate} interface to the {@link Transformer} interface.
- *
- * @param <I> input: the type of the object passed to the transformer (and
- * forwarded to the wrapped predicate)
- * @see Predicate
- */
-public class PredicateTransformer<I>
- implements Transformer<I, Boolean>
-{
- private final Predicate<? super I> predicate;
-
-
- public PredicateTransformer(Predicate<? super I> predicate) {
- super();
- if (predicate == null) {
- throw new NullPointerException();
- }
- this.predicate = predicate;
- }
-
- public Boolean transform(I input) {
- return Boolean.valueOf(this.predicate.evaluate(input));
- }
-
- public Predicate<? super I> getPredicate() {
- return this.predicate;
- }
-
- @Override
- public String toString() {
- return ObjectTools.toString(this, this.predicate);
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java
index f4bcfb54f8..1d2402777c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/TransformerTools.java
@@ -25,6 +25,7 @@ import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ClassTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.exception.DefaultExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.internal.transformer.int_.IntObjectTransformerAdapter;
import org.eclipse.jpt.common.utility.predicate.Predicate;
@@ -280,7 +281,6 @@ public final class TransformerTools {
* @param <I> input: the type of the object passed to the transformer (and
* forwarded to the wrapped predicate)
*
- * @see PredicateTransformer
* @see #adapt(Predicate, Boolean)
* @see #adapt(Predicate)
*/
@@ -299,7 +299,6 @@ public final class TransformerTools {
* @param <I> input: the type of the object passed to the transformer (and
* forwarded to the wrapped predicate)
*
- * @see PredicateTransformer
* @see #adapt_(Predicate)
* @see #adapt(Predicate)
*/
@@ -317,12 +316,11 @@ public final class TransformerTools {
* @param <I> input: the type of the object passed to the transformer (and
* forwarded to the wrapped predicate)
*
- * @see PredicateTransformer
* @see #adapt_(Predicate)
* @see #adapt(Predicate, Boolean)
*/
public static <I> Transformer<I, Boolean> adapt(Predicate<? super I> predicate) {
- return new PredicateTransformer<>(predicate);
+ return input -> Boolean.valueOf(predicate.evaluate(input));
}
@@ -428,9 +426,11 @@ public final class TransformerTools {
* If the collection is empty, the transformer returns <code>null</code>.
*
* @param <E> the type of elements held by the collection
+ *
+ * @see #collectionFirstElementTransformer_()
*/
public static <E> Transformer<Collection<? extends E>, E> collectionFirstElementTransformer() {
- return CollectionFirstElementTransformer.instance();
+ return collection -> collection.isEmpty() ? null : collection.iterator().next();
}
/**
@@ -439,9 +439,11 @@ public final class TransformerTools {
* {@link java.util.NoSuchElementException}.
*
* @param <E> the type of elements held by the collection
+ *
+ * @see #collectionFirstElementTransformer()
*/
public static <E> Transformer<Collection<? extends E>, E> collectionFirstElementTransformer_() {
- return CollectionFirstElementTransformer_.instance();
+ return collection -> collection.iterator().next();
}
/**
@@ -449,9 +451,11 @@ public final class TransformerTools {
* If the collection is empty, the transformer returns <code>null</code>.
*
* @param <E> the type of elements held by the collection
+ *
+ * @see #collectionLastElementTransformer_()
*/
public static <E> Transformer<Collection<? extends E>, E> collectionLastElementTransformer() {
- return CollectionLastElementTransformer.instance();
+ return collection -> collection.isEmpty() ? null : IterableTools.last(collection);
}
/**
@@ -460,9 +464,11 @@ public final class TransformerTools {
* {@link java.util.NoSuchElementException}.
*
* @param <E> the type of elements held by the collection
+ *
+ * @see #collectionLastElementTransformer()
*/
public static <E> Transformer<Collection<? extends E>, E> collectionLastElementTransformer_() {
- return CollectionLastElementTransformer_.instance();
+ return collection -> IterableTools.last(collection);
}
/**
@@ -473,7 +479,7 @@ public final class TransformerTools {
* @param <E> the type of elements held by the collection
*/
public static <E> Transformer<Collection<? extends E>, E> collectionSingleElementTransformer() {
- return CollectionSingleElementTransformer.instance();
+ return collection -> (collection.size() == 1) ? collection.iterator().next() : null;
}
/**
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java
deleted file mode 100644
index f6d1227d7f..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformerTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.transformer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class CollectionFirstElementTransformerTests
- extends TestCase
-{
- public CollectionFirstElementTransformerTests(String name) {
- super(name);
- }
-
- public void testEvaluate() {
- Collection<String> list = new ArrayList<>();
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
- assertNull(transformer.transform(list));
- list.add("foo");
- assertEquals("foo", transformer.transform(list));
- list.add("bar");
- assertEquals("foo", transformer.transform(list));
- list.remove("foo");
- assertEquals("bar", transformer.transform(list));
- list.remove("bar");
- assertNull(transformer.transform(list));
- }
-
- public void testToString() {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
- assertEquals("CollectionFirstElementTransformer", transformer.toString());
- }
-
- public void testSerialization() throws Exception {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
- assertSame(transformer, TestTools.serialize(transformer));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformer_Tests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformer_Tests.java
deleted file mode 100644
index 22d105e3af..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionFirstElementTransformer_Tests.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.transformer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class CollectionFirstElementTransformer_Tests
- extends TestCase
-{
- public CollectionFirstElementTransformer_Tests(String name) {
- super(name);
- }
-
- public void testEvaluate() {
- Collection<String> list = new ArrayList<>();
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer_();
- boolean exCaught = false;
- try {
- String bogus = transformer.transform(list);
- fail("bogus output: " + bogus);
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- list.add("foo");
- assertEquals("foo", transformer.transform(list));
- list.add("bar");
- assertEquals("foo", transformer.transform(list));
- list.remove("foo");
- assertEquals("bar", transformer.transform(list));
- list.remove("bar");
- exCaught = false;
- try {
- String bogus = transformer.transform(list);
- fail("bogus output: " + bogus);
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- }
-
- public void testToString() {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer_();
- assertEquals("CollectionFirstElementTransformer_", transformer.toString());
- }
-
- public void testSerialization() throws Exception {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer_();
- assertSame(transformer, TestTools.serialize(transformer));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformerTests.java
deleted file mode 100644
index 4db7c09526..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformerTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.transformer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class CollectionLastElementTransformerTests
- extends TestCase
-{
- public CollectionLastElementTransformerTests(String name) {
- super(name);
- }
-
- public void testEvaluate() {
- Collection<String> list = new ArrayList<>();
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer();
- assertNull(transformer.transform(list));
- list.add("foo");
- assertEquals("foo", transformer.transform(list));
- list.add("bar");
- assertEquals("bar", transformer.transform(list));
- list.remove("foo");
- assertEquals("bar", transformer.transform(list));
- list.remove("bar");
- assertNull(transformer.transform(list));
- }
-
- public void testToString() {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer();
- assertEquals("CollectionLastElementTransformer", transformer.toString());
- }
-
- public void testSerialization() throws Exception {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer();
- assertSame(transformer, TestTools.serialize(transformer));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformer_Tests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformer_Tests.java
deleted file mode 100644
index a57a806c64..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionLastElementTransformer_Tests.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.transformer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class CollectionLastElementTransformer_Tests
- extends TestCase
-{
- public CollectionLastElementTransformer_Tests(String name) {
- super(name);
- }
-
- public void testEvaluate() {
- Collection<String> list = new ArrayList<>();
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
- boolean exCaught = false;
- try {
- String bogus = transformer.transform(list);
- fail("bogus output: " + bogus);
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- list.add("foo");
- assertEquals("foo", transformer.transform(list));
- list.add("bar");
- assertEquals("bar", transformer.transform(list));
- list.remove("foo");
- assertEquals("bar", transformer.transform(list));
- list.remove("bar");
- exCaught = false;
- try {
- String bogus = transformer.transform(list);
- fail("bogus output: " + bogus);
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- }
-
- public void testToString() {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
- assertEquals("CollectionLastElementTransformer_", transformer.toString());
- }
-
- public void testSerialization() throws Exception {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
- assertSame(transformer, TestTools.serialize(transformer));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java
deleted file mode 100644
index fa116241e4..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/CollectionSingleElementTransformerTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.transformer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class CollectionSingleElementTransformerTests
- extends TestCase
-{
- public CollectionSingleElementTransformerTests(String name) {
- super(name);
- }
-
- public void testEvaluate() {
- Collection<String> list = new ArrayList<>();
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
- assertNull(transformer.transform(list));
- list.add("foo");
- assertEquals("foo", transformer.transform(list));
- list.add("bar");
- assertNull(transformer.transform(list));
- list.remove("foo");
- assertEquals("bar", transformer.transform(list));
- list.remove("bar");
- assertNull(transformer.transform(list));
- }
-
- public void testToString() {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
- assertEquals("CollectionSingleElementTransformer", transformer.toString());
- }
-
- public void testSerialization() throws Exception {
- Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
- assertSame(transformer, TestTools.serialize(transformer));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
index 526bf09835..bb05362276 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/JptCommonUtilityTransformerTests.java
@@ -20,15 +20,11 @@ public class JptCommonUtilityTransformerTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptCommonUtilityTransformerTests.class.getPackage().getName());
- suite.addTestSuite(CollectionFirstElementTransformerTests.class);
- suite.addTestSuite(CollectionFirstElementTransformer_Tests.class);
- suite.addTestSuite(CollectionLastElementTransformerTests.class);
- suite.addTestSuite(CollectionLastElementTransformer_Tests.class);
- suite.addTestSuite(CollectionSingleElementTransformerTests.class);
suite.addTestSuite(FilteringTransformerTests.class);
suite.addTestSuite(ListLastElementTransformerTests.class);
suite.addTestSuite(ListLastElementTransformer_Tests.class);
suite.addTestSuite(NullCheckTransformerTests.class);
+ suite.addTestSuite(TransformerToolsTests.class);
suite.addTestSuite(XMLStringDecoderTests.class);
suite.addTestSuite(XMLStringEncoderTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/TransformerToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/TransformerToolsTests.java
new file mode 100644
index 0000000000..61377af2b4
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/transformer/TransformerToolsTests.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 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.transformer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class TransformerToolsTests
+ extends TestCase
+{
+ public TransformerToolsTests(String name) {
+ super(name);
+ }
+
+ public void testCollectionFirstElementTransformer() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
+ assertNull(transformer.transform(list));
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertEquals("foo", transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ assertNull(transformer.transform(list));
+ }
+
+ public void testCollectionFirstElementTransformer_NPE() {
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer();
+ boolean exCaught = false;
+ try {
+ String s = transformer.transform(null);
+ fail("bogus: " + s);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCollectionFirstElementTransformer_() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
+ boolean exCaught = false;
+ try {
+ String bogus = transformer.transform(list);
+ fail("bogus output: " + bogus);
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ exCaught = false;
+ try {
+ String bogus = transformer.transform(list);
+ fail("bogus output: " + bogus);
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ }
+
+ public void testCollectionFirstElementTransformer__NPE() {
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionFirstElementTransformer_();
+ boolean exCaught = false;
+ try {
+ String s = transformer.transform(null);
+ fail("bogus: " + s);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCollectionLastElementTransformer() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer();
+ assertNull(transformer.transform(list));
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ assertNull(transformer.transform(list));
+ }
+
+ public void testCollectionLastElementTransformer_NPE() {
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer();
+ boolean exCaught = false;
+ try {
+ String s = transformer.transform(null);
+ fail("bogus: " + s);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCollectionLastElementTransformer_() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
+ boolean exCaught = false;
+ try {
+ String bogus = transformer.transform(list);
+ fail("bogus output: " + bogus);
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ exCaught = false;
+ try {
+ String bogus = transformer.transform(list);
+ fail("bogus output: " + bogus);
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ }
+
+ public void testCollectionLastElementTransformer__NPE() {
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionLastElementTransformer_();
+ boolean exCaught = false;
+ try {
+ String s = transformer.transform(null);
+ fail("bogus: " + s);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCollectionSingleElementTransformer() {
+ Collection<String> list = new ArrayList<>();
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
+ assertNull(transformer.transform(list));
+ list.add("foo");
+ assertEquals("foo", transformer.transform(list));
+ list.add("bar");
+ assertNull(transformer.transform(list));
+ list.remove("foo");
+ assertEquals("bar", transformer.transform(list));
+ list.remove("bar");
+ assertNull(transformer.transform(list));
+ }
+
+ public void testCollectionSingleElementTransformer_NPE() {
+ Transformer<Collection<? extends String>, String> transformer = TransformerTools.collectionSingleElementTransformer();
+ boolean exCaught = false;
+ try {
+ String s = transformer.transform(null);
+ fail("bogus: " + s);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+}

Back to the top