6 added files
lcsim/src/org/lcsim/util/decision
diff -N DecisionMakerPair.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DecisionMakerPair.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,19 @@
+package org.lcsim.util.decision;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * A templated interface for a DecisionMaker that acts on a pair of objects.
+ *
+ * @version $Id: DecisionMakerPair.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+public interface DecisionMakerPair<E,T> {
+
+ /**
+ * Check the pair of objects for validity.
+ * Return true if valid, false if not.
+ */
+ public boolean valid(E objectToTest1, T objectToTest2);
+
+}
lcsim/src/org/lcsim/util/decision
diff -N DecisionMakerSingle.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DecisionMakerSingle.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,16 @@
+package org.lcsim.util.decision;
+
+/**
+ * A templated interface for a DecisionMaker which takes a single
+ * object as input.
+ *
+ * @version $Id: DecisionMakerSingle.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+public interface DecisionMakerSingle<E> {
+
+ /**
+ * Return true if the object is valid, false if not.
+ */
+ public boolean valid(E objectToTest);
+
+}
lcsim/src/org/lcsim/util/decision
diff -N DummyDecisionMakerPair.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DummyDecisionMakerPair.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,12 @@
+package org.lcsim.util.decision;
+
+/**
+ * A dummy decision maker which always returns valid.
+ *
+ * @version $Id: DummyDecisionMakerPair.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+
+public class DummyDecisionMakerPair<E,T> implements DecisionMakerPair<E,T> {
+ public DummyDecisionMakerPair () {}
+ public boolean valid(E objectToTest1, T objectToTest2) { return true; }
+}
lcsim/src/org/lcsim/util/decision
diff -N DummyDecisionMakerSingle.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DummyDecisionMakerSingle.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,12 @@
+package org.lcsim.util.decision;
+
+/**
+ * A dummy decision maker which always returns valid.
+ *
+ * @version $Id: DummyDecisionMakerSingle.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+
+public class DummyDecisionMakerSingle<E> implements DecisionMakerSingle<E> {
+ public DummyDecisionMakerSingle () {}
+ public boolean valid(E objectToTest) { return true; }
+}
lcsim/src/org/lcsim/util/decision
diff -N ExactMatchDecision.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ExactMatchDecision.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,27 @@
+package org.lcsim.util.decision;
+
+/**
+ * A decision maker that requires an exact match.
+ *
+ * @version $Id: ExactMatchDecision.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+
+public class ExactMatchDecision<T> implements DecisionMakerSingle<T> {
+ /**
+ * Constructor.
+ *
+ * @param toBeMatched The value required for a valid match
+ */
+ public ExactMatchDecision(T toBeMatched) {
+ m_toBeMatched = toBeMatched;
+ }
+
+ /**
+ * Check whether test == toBeMatched
+ */
+ public boolean valid(T test) {
+ return (m_toBeMatched == test);
+ }
+
+ protected T m_toBeMatched;
+}
lcsim/src/org/lcsim/util/decision
diff -N ListFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ListFilter.java 2 Jan 2006 21:16:14 -0000 1.1
@@ -0,0 +1,49 @@
+package org.lcsim.util.decision;
+
+import java.util.*;
+
+/**
+ * A templated filter which applies a DecisionMakerSingle to each element in a list.
+ *
+ * @version $Id: ListFilter.java,v 1.1 2006/01/02 21:16:14 mcharles Exp $
+ */
+public class ListFilter<E>
+{
+ /**
+ * Constructor.
+ *
+ * @param dec The DecisionMaker which will be applied.
+ */
+ public ListFilter (DecisionMakerSingle<E> dec) {
+ m_dec = dec;
+ }
+
+ /**
+ * Apply the filter to a list. The input list is unmodified;
+ * all elements that pass the filter are added to an output list
+ * which is supplied as the second parameter. The output is
+ * not wiped before the filtered elements of the input list are added.
+ *
+ * @param inputList The input list (remains unmodified)
+ * @param outputList The output list (also the return value)
+ */
+ public List<E> filterList(List<E> inputList, List<E> outputList) {
+ for (E item : inputList) {
+ if (m_dec.valid(item)) {
+ outputList.add(item);
+ }
+ }
+ return outputList;
+ }
+
+ /**
+ * Apply the filter to a list. Returns a new List containing the
+ * filtered elements; the input list is not modified.
+ */
+ public List<E> filterList(List<E> inputList) {
+ List<E> emptyList = new ArrayList<E>();
+ return filterList(inputList, emptyList);
+ }
+
+ protected DecisionMakerSingle<E> m_dec = null;
+}
CVSspam 0.2.8