Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2015-10-16 17:44:57 -0400
committerBrian Vosburgh2015-10-16 17:44:57 -0400
commit9cad45998a8b4e5da0014376f61238c40df834db (patch)
tree7a5bb9bbc6a525918bc59ed834c83a1d68d0fae4
parent806185961a09d34efb657ee8ec3938d9ee38818d (diff)
downloadwebtools.dali-9cad45998a8b4e5da0014376f61238c40df834db.tar.gz
webtools.dali-9cad45998a8b4e5da0014376f61238c40df834db.tar.xz
webtools.dali-9cad45998a8b4e5da0014376f61238c40df834db.zip
add some bit mask IntPredicates
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreOff.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreSet.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsOff.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsSet.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IntPredicateTools.java64
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsEven.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsOdd.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsOff.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsSet.java32
9 files changed, 354 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreOff.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreOff.java
new file mode 100644
index 0000000000..c15ab2457d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreOff.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has cleared <em>any</em> of the flags specified during construction.
+ */
+public class AnyFlagsAreOff
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has cleared <em>any</em> of the specified flags.
+ */
+ public AnyFlagsAreOff(int flags) {
+ super(flags);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.anyFlagsAreOff(variable, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreSet.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreSet.java
new file mode 100644
index 0000000000..59a5c97347
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/AnyFlagsAreSet.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has set <em>any</em> of the flags specified during construction.
+ */
+public class AnyFlagsAreSet
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has set <em>any</em> of the specified flags.
+ */
+ public AnyFlagsAreSet(int flags) {
+ super(flags);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.anyFlagsAreSet(variable, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsOff.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsOff.java
new file mode 100644
index 0000000000..f104522b89
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsOff.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has cleared the flag specified during construction.
+ */
+public class FlagIsOff
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has cleared the specified flag.
+ */
+ public FlagIsOff(int flag) {
+ super(flag);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.flagIsOff(variable, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsSet.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsSet.java
new file mode 100644
index 0000000000..b449bd27c9
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/FlagIsSet.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has set the flag specified during construction.
+ */
+public class FlagIsSet
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has set the specified flag.
+ */
+ public FlagIsSet(int flag) {
+ super(flag);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.flagIsSet(variable, this.criterion);
+ }
+}
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
index 33393f9947..d40fbe547c 100644
--- 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
@@ -37,6 +37,22 @@ public class IntPredicateTools {
}
/**
+ * Return a predicate that will evaluate to <code>true</code>
+ * if the variable is even.
+ */
+ public static IntPredicate isEven() {
+ return IsEven.instance();
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * if the variable is odd.
+ */
+ public static IntPredicate isOdd() {
+ return IsOdd.instance();
+ }
+
+ /**
* Return a predicate that will throw an exception when it is
* evaluated.
*/
@@ -97,6 +113,54 @@ public class IntPredicateTools {
return new IsLessThanOrEqual(criterion);
}
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has set the specified flag.
+ */
+ public static IntPredicate flagIsSet(int flag) {
+ return new FlagIsSet(flag);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has cleared the specified flag.
+ */
+ public static IntPredicate flagIsOff(int flag) {
+ return new FlagIsOff(flag);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has set <em>only</em> the specified flag.
+ */
+ public static IntPredicate onlyFlagIsSet(int flag) {
+ return new OnlyFlagIsSet(flag);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has cleared <em>only</em> the specified flag.
+ */
+ public static IntPredicate onlyFlagIsOff(int flag) {
+ return new OnlyFlagIsOff(flag);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has set <em>any</em> of the specified flags.
+ */
+ public static IntPredicate anyFlagsAreSet(int flags) {
+ return new AnyFlagsAreSet(flags);
+ }
+
+ /**
+ * Return a predicate that will evaluate to <code>true</code>
+ * for any variable that has cleared <em>any</em> of the specified flags.
+ */
+ public static IntPredicate anyFlagsAreOff(int flags) {
+ return new AnyFlagsAreOff(flags);
+ }
+
// ********** AND **********
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsEven.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsEven.java
new file mode 100644
index 0000000000..32944b5b15
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsEven.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.internal.BitTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Singleton predicate that returns <code>true</code> if the variable is even.
+ *
+ * @see IsOdd
+ */
+public final class IsEven
+ implements IntPredicate, Serializable
+{
+ public static final IntPredicate INSTANCE = new IsEven();
+
+ public static IntPredicate instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private IsEven() {
+ super();
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.isEven(variable);
+ }
+
+ @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_/IsOdd.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsOdd.java
new file mode 100644
index 0000000000..753f6589d7
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/IsOdd.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.internal.BitTools;
+import org.eclipse.jpt.common.utility.predicate.IntPredicate;
+
+/**
+ * Singleton predicate that returns <code>true</code> if the variable is odd.
+ *
+ * @see IsEven
+ */
+public final class IsOdd
+ implements IntPredicate, Serializable
+{
+ public static final IntPredicate INSTANCE = new IsOdd();
+
+ public static IntPredicate instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private IsOdd() {
+ super();
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.isOdd(variable);
+ }
+
+ @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_/OnlyFlagIsOff.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsOff.java
new file mode 100644
index 0000000000..0f54af1688
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsOff.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has cleared <em>only</em> the flag specified during construction.
+ */
+public class OnlyFlagIsOff
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has cleared <em>only</em> the specified flag.
+ */
+ public OnlyFlagIsOff(int flag) {
+ super(flag);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.onlyFlagIsOff(variable, this.criterion);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsSet.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsSet.java
new file mode 100644
index 0000000000..e0bba43fb6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/predicate/int_/OnlyFlagIsSet.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 org.eclipse.jpt.common.utility.internal.BitTools;
+
+/**
+ * This predicate evaluates to <code>true</code> if the variable
+ * has set <em>only</em> the flag specified during construction.
+ */
+public class OnlyFlagIsSet
+ extends IntCriterionIntPredicate
+{
+ /**
+ * Construct a predicate that will evaluate to <code>true</code> if the
+ * variable has set <em>only</em> the specified flag.
+ */
+ public OnlyFlagIsSet(int flag) {
+ super(flag);
+ }
+
+ public boolean evaluate(int variable) {
+ return BitTools.onlyFlagIsSet(variable, this.criterion);
+ }
+}

Back to the top