Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/NullObjectTransformer.java')
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/NullObjectTransformer.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/NullObjectTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/NullObjectTransformer.java
new file mode 100644
index 0000000000..27e107802b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/transformer/NullObjectTransformer.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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 org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * A {@link NullObjectTransformer} will transform an object to a
+ * {@link Boolean}:<ul>
+ * <li>If the object is <code>null</code>,
+ * the transformer will return {@link Boolean#TRUE}.
+ * <li>If the object is <em>not</em> <code>null</code>,
+ * the transformer will return {@link Boolean#FALSE}.
+ * </ul>
+ *
+ * @param <T> the type of the object passed to the transformer
+ */
+public class NullObjectTransformer<T>
+ implements Transformer<T, Boolean>, Serializable
+{
+ @SuppressWarnings("rawtypes")
+ public static final Transformer INSTANCE = new NullObjectTransformer();
+
+ @SuppressWarnings("unchecked")
+ public static <S> Transformer<S, Boolean> instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private NullObjectTransformer() {
+ super();
+ }
+
+ public Boolean transform(T o) {
+ return Boolean.valueOf(o == 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;
+ }
+}

Back to the top