Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2015-10-16 17:04:57 -0400
committerBrian Vosburgh2015-10-16 17:06:40 -0400
commitaff96c7056f450e7a378fe7592c5fc343b0c8536 (patch)
treeb893da36be13db7f4a9d13e2fc4b621a10a776de
parent801a338c37f6eff6e9b9c4913bb4330e7cf98be4 (diff)
downloadwebtools.dali-aff96c7056f450e7a378fe7592c5fc343b0c8536.tar.gz
webtools.dali-aff96c7056f450e7a378fe7592c5fc343b0c8536.tar.xz
webtools.dali-aff96c7056f450e7a378fe7592c5fc343b0c8536.zip
add IntPredicate etc.
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AND.java52
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AbstractCompoundIntPredicate.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/CriterionIntPredicate.java71
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/DisabledIntPredicate.java50
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/Equals.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/False.java52
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntCriterionIntPredicate.java62
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateAdapter.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateTools.java257
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateWrapper.java62
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThan.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThanOrEqual.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThan.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThanOrEqual.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NOT.java67
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NotEqual.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OR.java51
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/True.java52
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/XOR.java42
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/CompoundIntPredicate.java34
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/IntPredicate.java31
22 files changed, 1189 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
index cab8c0acea..034cdb586f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
@@ -226,6 +226,17 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.jpa.gen,
org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.utility.internal.predicate.int_;
+ x-friends:="org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.ui,
+ org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.prefs;
x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AND.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AND.java
new file mode 100644
index 0000000000..4579a6afca
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AND.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * This compound predicate will evaluate to <code>true</code> if <em>all</em>
+ * its wrapped predicates evaluate to <code>true</code>.
+ * If there are <em>no</em> wrapped
+ * predicates, this predicate will always evaluate to <code>true</code>.
+ * If there are wrapped predicates, this predicate will
+ * exhibit "short-circuit" behavior; i.e. if any wrapped predicate evaluates
+ * to <code>false</code>, no following wrapped predicates will be evaluated.
+ *
+ * @see OR
+ * @see XOR
+ * @see NOT
+ */
+public class AND
+ extends AbstractCompoundIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if <em>all</em>
+ * the specified predicates evaluate to <code>true</code>.
+ */
+ @SafeVarargs
+ public AND(IntPredicate... predicates) {
+ super(predicates);
+ }
+
+ public boolean evaluate(int variable) {
+ for (IntPredicate predicate : this.predicates) {
+ if ( ! predicate.evaluate(variable)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected String operatorString() {
+ return "AND"; //$NON-NLS-1$
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AbstractCompoundIntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AbstractCompoundIntPredicate.java
new file mode 100644
index 0000000000..f221cc2aaf
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AbstractCompoundIntPredicate.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import java.util.Arrays;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.internal.StringBuilderTools;
+import org.eclipse.jpt.common.utility.predicate.CompoundIntPredicate;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * This class provides a simple framework for combining the behavior
+ * of multiple predicates.
+ */
+public abstract class AbstractCompoundIntPredicate
+ implements CompoundIntPredicate
+{
+ protected final IntPredicate[] predicates;
+
+
+ /**
+ * Construct a compound predicate for the specified list of predicates.
+ */
+ @SafeVarargs
+ protected AbstractCompoundIntPredicate(IntPredicate... predicates) {
+ super();
+ if (ArrayTools.isOrContainsNull(predicates)) {
+ throw new NullPointerException();
+ }
+ this.predicates = predicates;
+ }
+
+ /**
+ * Return the predicates.
+ */
+ public IntPredicate[] getPredicates() {
+ return this.predicates;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o.getClass() != this.getClass()) {
+ return false;
+ }
+ AbstractCompoundIntPredicate other = (AbstractCompoundIntPredicate) o;
+ return Arrays.equals(this.predicates, other.predicates);
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(this.predicates);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.appendHashCodeToString(sb, this);
+ sb.append('(');
+ if (this.predicates.length > 0) {
+ String operatorString = this.operatorString();
+ for (IntPredicate predicate : this.predicates) {
+ sb.append(predicate);
+ sb.append(' ');
+ sb.append(operatorString);
+ sb.append(' ');
+ }
+ sb.setLength(sb.length() - operatorString.length() - 2);
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+ /**
+ * Return a string representation of the compound predicate's operator.
+ * Used by {@link #toString()}.
+ */
+ protected abstract String operatorString();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/CriterionIntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/CriterionIntPredicate.java
new file mode 100644
index 0000000000..d895490a86
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/CriterionIntPredicate.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Simple, abstract implementation of {@link IntPredicate}
+ * that holds on to a criterion object that can be used in the
+ * {@link #evaluate(int) evaluate} method.
+ * <p>
+ * This class simplifies the implementation of straightforward inner classes.
+ *
+ * @param <C> the type of the filter's criterion
+ */
+public abstract class CriterionIntPredicate<C>
+ implements IntPredicate
+{
+ protected final C criterion;
+
+
+ /**
+ * Construct a simple predicate with a <code>null</code> criterion.
+ */
+ protected CriterionIntPredicate() {
+ this(null);
+ }
+
+ /**
+ * More useful constructor. The specified criterion can
+ * be used by a subclass to evaluate objects.
+ */
+ protected CriterionIntPredicate(C criterion) {
+ super();
+ this.criterion = criterion;
+ }
+
+ /**
+ * Return the predicate's criterion.
+ */
+ public C getCriterion() {
+ return this.criterion;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o.getClass() != this.getClass()) {
+ return false;
+ }
+ CriterionIntPredicate<?> other = (CriterionIntPredicate<?>) o;
+ return ObjectTools.equals(this.criterion, other.criterion);
+ }
+
+ @Override
+ public int hashCode() {
+ return (this.criterion == null) ? 0 : this.criterion.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/DisabledIntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/DisabledIntPredicate.java
new file mode 100644
index 0000000000..cd4d4fd784
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/DisabledIntPredicate.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Singleton predicate that throws an
+ * {@link UnsupportedOperationException exception} if evaluated.
+ */
+public final class DisabledIntPredicate
+ implements IntPredicate, Serializable
+{
+ public static final IntPredicate INSTANCE = new DisabledIntPredicate();
+
+ public static IntPredicate instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private DisabledIntPredicate() {
+ super();
+ }
+
+ /**
+ * Throw an {@link UnsupportedOperationException exception}.
+ */
+ public boolean evaluate(int variable) {
+ throw new UnsupportedOperationException();
+ }
+
+ @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;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/Equals.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/Equals.java
new file mode 100644
index 0000000000..b84394b2bc
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/Equals.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * equal to the criterion specified during construction.
+ */
+public class Equals
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable is equal to the specified criterion.
+ */
+ public Equals(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable == this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/False.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/False.java
new file mode 100644
index 0000000000..3e36ab4f42
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/False.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Singleton predicate that always evaluates to
+ * <code>false</code>.
+ *
+ * @see True
+ */
+public final class False
+ implements IntPredicate, Serializable
+{
+ public static final IntPredicate INSTANCE = new False();
+
+ public static IntPredicate instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private False() {
+ super();
+ }
+
+ /**
+ * Return <code>false</code>.
+ */
+ public boolean evaluate(int variable) {
+ return false;
+ }
+
+ @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;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntCriterionIntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntCriterionIntPredicate.java
new file mode 100644
index 0000000000..7c3972bfab
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntCriterionIntPredicate.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Simple, abstract implementation of {@link IntPredicate}
+ * that holds on to a criterion object that can be used in the
+ * {@link #evaluate(int) evaluate} method.
+ * <p>
+ * This class simplifies the implementation of straightforward inner classes.
+ */
+public abstract class IntCriterionIntPredicate
+ implements IntPredicate
+{
+ protected final int criterion;
+
+
+ /**
+ * More useful constructor. The specified criterion can
+ * be used by a subclass to evaluate objects.
+ */
+ protected IntCriterionIntPredicate(int criterion) {
+ super();
+ this.criterion = criterion;
+ }
+
+ /**
+ * Return the predicate's criterion.
+ */
+ public int getCriterion() {
+ return this.criterion;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o.getClass() != this.getClass()) {
+ return false;
+ }
+ IntCriterionIntPredicate other = (IntCriterionIntPredicate) o;
+ return this.criterion == other.criterion;
+ }
+
+ @Override
+ public int hashCode() {
+ return this.criterion;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateAdapter.java
new file mode 100644
index 0000000000..f0d13fdaec
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateAdapter.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Convenience predicate implementation that evaluates any <code>int</code> to
+ * <code>false</code> and provides a helpful {@link #toString()}.
+ */
+public class IntPredicateAdapter
+ implements IntPredicate
+{
+ public boolean evaluate(int variable) {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateTools.java
new file mode 100644
index 0000000000..33393f9947
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateTools.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+import java.util.Iterator;
+import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
+import org.eclipse.jpt.common.utility.predicate.CompoundIntPredicate;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * {@link IntPredicate} utility methods.
+ */
+public class IntPredicateTools {
+
+
+ // ********** simple **********
+
+ /**
+ * Return a predicate that will always evaluate to <code>true</code>.
+ */
+ public static IntPredicate true_() {
+ return True.instance();
+ }
+
+ /**
+ * Return a predicate that will always evaluate to <code>false</code>.
+ */
+ public static IntPredicate false_() {
+ return False.instance();
+ }
+
+ /**
+ * Return a predicate that will throw an exception when it is
+ * evaluated.
+ */
+ public static IntPredicate disabledIntPredicate() {
+ return DisabledIntPredicate.instance();
+ }
+
+
+ // ********** criterion **********
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable equal to the specified
+ * criterion.
+ */
+ public static IntPredicate isEqual(int criterion) {
+ return new Equals(criterion);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable not equal to the specified
+ * criterion.
+ */
+ public static IntPredicate notEqual(int criterion) {
+ return new NotEqual(criterion);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable greater than the specified criterion.
+ */
+ public static IntPredicate isGreaterThan(int criterion) {
+ return new IsGreaterThan(criterion);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable greater than or equal to the specified criterion.
+ */
+ public static IntPredicate isGreaterThanOrEqual(int criterion) {
+ return new IsGreaterThanOrEqual(criterion);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable less than the specified criterion.
+ */
+ public static IntPredicate isLessThan(int criterion) {
+ return new IsLessThan(criterion);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable less than or equal to the specified criterion.
+ */
+ public static IntPredicate isLessThanOrEqual(int criterion) {
+ return new IsLessThanOrEqual(criterion);
+ }
+
+
+ // ********** AND **********
+
+ /**
+ * Return a predicate that will AND the results of the specified predicates.
+ */
+ public static CompoundIntPredicate and(Iterable<IntPredicate> predicates) {
+ return and(predicates.iterator());
+ }
+
+ /**
+ * Return a predicate that will AND the results of the specified predicates.
+ */
+ public static CompoundIntPredicate and(Iterator<IntPredicate> predicates) {
+ return and(IteratorTools.toArray(predicates, EMPTY_ARRAY));
+ }
+
+ /**
+ * Return a predicate that will AND the results of the specified predicates.
+ */
+ public static CompoundIntPredicate and(IntPredicate... predicates) {
+ return new AND(predicates);
+ }
+
+
+ // ********** OR **********
+
+ /**
+ * Return a predicate that will OR the results of the specified predicates.
+ */
+ public static CompoundIntPredicate or(Iterable<IntPredicate> predicates) {
+ return or(predicates.iterator());
+ }
+
+ /**
+ * Return a predicate that will OR the results of the specified predicates.
+ */
+ public static CompoundIntPredicate or(Iterator<IntPredicate> predicates) {
+ return or(IteratorTools.toArray(predicates, EMPTY_ARRAY));
+ }
+
+ /**
+ * Return a predicate that will OR the results of the specified predicates.
+ */
+ public static CompoundIntPredicate or(IntPredicate... predicates) {
+ return new OR(predicates);
+ }
+
+
+ // ********** XOR **********
+
+ /**
+ * Return a predicate that will XOR the results of the specified predicates.
+ */
+ public static CompoundIntPredicate xor(IntPredicate predicate1, IntPredicate predicate2) {
+ return new XOR(predicate1, predicate2);
+ }
+
+
+ // ********** NAND **********
+
+ /**
+ * Return a predicate that will NAND the results of the specified predicates.
+ */
+ public static IntPredicate nand(Iterable<IntPredicate> predicates) {
+ return nand(predicates.iterator());
+ }
+
+ /**
+ * Return a predicate that will NAND the results of the specified predicates.
+ */
+ public static IntPredicate nand(Iterator<IntPredicate> predicates) {
+ return nand(IteratorTools.toArray(predicates, EMPTY_ARRAY));
+ }
+
+ /**
+ * Return a predicate that will NAND the results of the specified predicates.
+ */
+ public static IntPredicate nand(IntPredicate... predicates) {
+ return not(and(predicates));
+ }
+
+
+ // ********** NOR **********
+
+ /**
+ * Return a predicate that will NOR the results of the specified predicates.
+ */
+ public static IntPredicate nor(Iterable<IntPredicate> predicates) {
+ return nor(predicates.iterator());
+ }
+
+ /**
+ * Return a predicate that will NOR the results of the specified predicates.
+ */
+ public static IntPredicate nor(Iterator<IntPredicate> predicates) {
+ return nor(IteratorTools.toArray(predicates, EMPTY_ARRAY));
+ }
+
+ /**
+ * Return a predicate that will NOR the results of the specified predicates.
+ */
+ public static IntPredicate nor(IntPredicate... predicates) {
+ return not(or(predicates));
+ }
+
+
+ // ********** XNOR **********
+
+ /**
+ * Return a predicate that will XNOR the results of the specified predicates.
+ */
+ public static IntPredicate xnor(IntPredicate predicate1, IntPredicate predicate2) {
+ return not(xor(predicate1, predicate2));
+ }
+
+
+ // ********** NOT **********
+
+ /**
+ * Return a predicate that will return the NOT of the value returned
+ * by the specified predicate.
+ */
+ public static IntPredicate not(IntPredicate predicate) {
+ return new NOT(predicate);
+ }
+
+
+ // ********** wrappers **********
+
+ /**
+ * Return a predicate that wraps the specified predicate, allowing the
+ * wrapped predicate to be changed as necessary.
+ */
+ public static IntPredicateWrapper wrap(IntPredicate predicate) {
+ return new IntPredicateWrapper(predicate);
+ }
+
+
+ // ********** empty array **********
+
+ public static IntPredicate[] emptyArray() {
+ return EMPTY_ARRAY;
+ }
+
+ public static final IntPredicate[] EMPTY_ARRAY = new IntPredicate[0];
+
+
+ // ********** constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private IntPredicateTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateWrapper.java
new file mode 100644
index 0000000000..be46dc12ed
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateWrapper.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * IntPredicate wrapper that can have its wrapped predicate changed,
+ * allowing a client to change a previously-supplied predicate's
+ * behavior mid-stream.
+ *
+ * @see #setPredicate(IntPredicate)
+ */
+public class IntPredicateWrapper
+ implements IntPredicate
+{
+ protected volatile IntPredicate predicate;
+
+
+ public IntPredicateWrapper(IntPredicate predicate) {
+ super();
+ this.setPredicate(predicate);
+ }
+
+ public boolean evaluate(int variable) {
+ return this.predicate.evaluate(variable);
+ }
+
+ public void setPredicate(IntPredicate predicate) {
+ if (predicate == null) {
+ throw new NullPointerException();
+ }
+ this.predicate = predicate;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( ! (o instanceof IntPredicateWrapper)) {
+ return false;
+ }
+ IntPredicateWrapper other = (IntPredicateWrapper) o;
+ return this.predicate.equals(other.predicate);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.predicate.hashCode();
+ }
+
+ @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/predicate/int_/IsGreaterThan.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThan.java
new file mode 100644
index 0000000000..b2248d7613
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThan.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * greater than the criterion specified during construction.
+ */
+public class IsGreaterThan
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable greater than the specified criterion.
+ */
+ public IsGreaterThan(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable > this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThanOrEqual.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThanOrEqual.java
new file mode 100644
index 0000000000..1682e533f3
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsGreaterThanOrEqual.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * greater than or equal to the criterion specified during construction.
+ */
+public class IsGreaterThanOrEqual
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable is greater than or equal to the specified criterion.
+ */
+ public IsGreaterThanOrEqual(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable >= this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThan.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThan.java
new file mode 100644
index 0000000000..b2141676e1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThan.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * less than the criterion specified during construction.
+ */
+public class IsLessThan
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable is less than the specified criterion.
+ */
+ public IsLessThan(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable < this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThanOrEqual.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThanOrEqual.java
new file mode 100644
index 0000000000..5c138d5147
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsLessThanOrEqual.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * less than or equal to the criterion specified during construction.
+ */
+public class IsLessThanOrEqual
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable is less than or equal to the specified criterion.
+ */
+ public IsLessThanOrEqual(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable <= this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NOT.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NOT.java
new file mode 100644
index 0000000000..2d9d65a426
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NOT.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * This predicate will return the NOT of the value returned by its
+ * wrapped predicate.
+ *
+ * @see AND
+ * @see OR
+ * @see XOR
+ */
+public class NOT
+ implements IntPredicate
+{
+ protected final IntPredicate predicate;
+
+
+ /**
+ * Construct a predicate that will return the NOT of the value returned
+ * by the specified predicate.
+ */
+ public NOT(IntPredicate predicate) {
+ super();
+ if (predicate == null) {
+ throw new NullPointerException();
+ }
+ this.predicate = predicate;
+ }
+
+ public boolean evaluate(int variable) {
+ return ! this.predicate.evaluate(variable);
+ }
+
+ public IntPredicate getIntPredicate() {
+ return this.predicate;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( ! (o instanceof NOT)) {
+ return false;
+ }
+ NOT other = (NOT) o;
+ return this.predicate.equals(other.predicate);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.predicate.hashCode();
+ }
+
+ @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/predicate/int_/NotEqual.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NotEqual.java
new file mode 100644
index 0000000000..22148202e5
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/NotEqual.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 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.predicate.int_;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable is
+ * not equal to the criterion specified during construction.
+ */
+public class NotEqual
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable is not equal to the specified criterion.
+ */
+ public NotEqual(int criterion) {
+ super(criterion);
+ }
+
+ public boolean evaluate(int variable) {
+ return variable != this.criterion;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OR.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OR.java
new file mode 100644
index 0000000000..9340e6403c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OR.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * This compound predicate will evaluate to <code>true</code> if <em>any</em>
+ * its wrapped predicates evaluates to <code>true</code>.
+ * If there are <em>no</em> wrapped
+ * predicates, this predicate will always evaluate to <code>false</code>.
+ * If there are wrapped predicates, this predicate will
+ * exhibit "short-circuit" behavior; i.e. if any wrapped predicate evaluates
+ * to <code>true</code>, no following wrapped predicates will be evaluated.
+ *
+ * @see AND
+ * @see XOR
+ * @see NOT
+ */
+public class OR
+ extends AbstractCompoundIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if <em>any</em>
+ * the specified predicates evaluates to <code>true</code>.
+ */
+ public OR(IntPredicate... predicates) {
+ super(predicates);
+ }
+
+ public boolean evaluate(int variable) {
+ for (IntPredicate predicate : this.predicates) {
+ if (predicate.evaluate(variable)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected String operatorString() {
+ return "OR"; //$NON-NLS-1$
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/True.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/True.java
new file mode 100644
index 0000000000..d0c1951f62
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/True.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Singleton predicate that always evaluates to
+ * <code>true</code>.
+ *
+ * @see False
+ */
+public final class True
+ implements IntPredicate, Serializable
+{
+ public static final IntPredicate INSTANCE = new True();
+
+ public static IntPredicate instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private True() {
+ super();
+ }
+
+ /**
+ * Return <code>true</code>.
+ */
+ public boolean evaluate(int variable) {
+ return true;
+ }
+
+ @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;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/XOR.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/XOR.java
new file mode 100644
index 0000000000..9488916f85
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/XOR.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 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.predicate.int_;
+
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * This compound predicate will evaluate to <code>true</code> if either of
+ * its wrapped predicates evaluates to <code>true</code>, but <em>not</em> both.
+ * Both predicates will <em>always</em> be evaluated.
+ *
+ * @see AND
+ * @see OR
+ * @see NOT
+ */
+public class XOR
+ extends AbstractCompoundIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if either of
+ * the specified predicates evaluates to <code>true</code>, but <em>not</em> both.
+ */
+ public XOR(IntPredicate predicate1, IntPredicate predicate2) {
+ super(predicate1, predicate2);
+ }
+
+ public boolean evaluate(int variable) {
+ return this.predicates[0].evaluate(variable) ^ this.predicates[1].evaluate(variable);
+ }
+
+ @Override
+ protected String operatorString() {
+ return "XOR"; //$NON-NLS-1$
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/CompoundIntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/CompoundIntPredicate.java
new file mode 100644
index 0000000000..e32de569f6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/CompoundIntPredicate.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.predicate;
+
+/**
+ * A predicate that evaulates to the result of some combination of a set of
+ * other predicates (e.g. the compound predicate's value may be the result
+ * of ANDing the values of its child predicates together).
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jpt.common.utility.internal.predicate.int_.IntPredicateTools
+ */
+public interface CompoundIntPredicate
+ extends IntPredicate
+{
+ /**
+ * Return the child predicates used to calculate the compound predicate's
+ * value (e.g. the compound predicate's value may be the result
+ * of ANDing the values of these predicates together).
+ */
+ IntPredicate[] getPredicates();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/IntPredicate.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/IntPredicate.java
new file mode 100644
index 0000000000..4262b88c2c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/predicate/IntPredicate.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.predicate;
+
+/**
+ * A predicate can be used to determine whether an <code>int</code> belongs
+ * to a particular set or has a particular property.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jpt.common.utility.internal.predicate.int_.IntPredicateTools
+ */
+public interface IntPredicate {
+ /**
+ * Return whether the specified variable is a member of the set defined by
+ * the predicate. The semantics of the set is determined by the
+ * contract between the client and the server.
+ */
+ boolean evaluate(int variable);
+}

Back to the top