Example usage for org.apache.commons.collections15 Predicate Predicate

List of usage examples for org.apache.commons.collections15 Predicate Predicate

Introduction

In this page you can find the example usage for org.apache.commons.collections15 Predicate Predicate.

Prototype

Predicate

Source Link

Usage

From source file:org.drugis.addis.presentation.wizard.TreatmentCategorizationWizardPresentation.java

/**
 * In the haystack, find a leaf node with the needle as its category.
 *///www  . ja va 2 s.  c om
public static LeafNode findLeafNode(final Collection<DecisionTreeNode> haystack, final Category needle) {
    return (LeafNode) find(haystack, new Predicate<DecisionTreeNode>() {
        public boolean evaluate(DecisionTreeNode object) {
            if (object instanceof LeafNode) {
                LeafNode node = (LeafNode) object;
                return EqualsUtil.equal(node.getCategory(), needle);
            }
            return false;
        }
    });
}

From source file:org.drugis.addis.presentation.wizard.TreatmentCategorizationWizardPresentation.java

private Predicate<TreatmentCategorization> createDrugFilter(final Drug drug) {
    return new Predicate<TreatmentCategorization>() {
        public boolean evaluate(TreatmentCategorization obj) {
            return EqualsUtil.equal(obj.getDrug(), drug);
        }/*from ww  w .j  ava  2s .c  om*/
    };
}

From source file:org.drugis.addis.presentation.wizard.TreatmentCategorizationWizardPresentationTest.java

private static DoseQuantityChoiceNode findDoseQuantityNode(ObservableList<DecisionTreeNode> options,
        final String propertyName) {
    return (DoseQuantityChoiceNode) CollectionUtils.find(options, new Predicate<DecisionTreeNode>() {
        public boolean evaluate(DecisionTreeNode object) {
            if (object instanceof DoseQuantityChoiceNode) {
                DoseQuantityChoiceNode node = (DoseQuantityChoiceNode) object;
                return propertyName.equals(node.getPropertyName());
            }//ww  w.ja va 2 s  . c o m
            return false;
        }
    });
}

From source file:org.drugis.addis.util.jaxb.TreatmentDefinitionConverter.java

public static TreatmentDefinition load(org.drugis.addis.entities.data.TreatmentDefinition t,
        final Domain domain) {
    TreatmentDefinition td = new TreatmentDefinition();
    for (Object category : t.getRichCategoryOrTrivialCategory()) {
        if (category instanceof org.drugis.addis.entities.data.TrivialCategory) {
            org.drugis.addis.entities.data.TrivialCategory trivial = (org.drugis.addis.entities.data.TrivialCategory) category;
            td.getContents().add(/*from w  w  w.  j  ava2s  .co  m*/
                    Category.createTrivial(JAXBConvertor.findNamedItem(domain.getDrugs(), trivial.getDrug())));
        } else if (category instanceof org.drugis.addis.entities.data.TreatmentCategoryRef) {
            final org.drugis.addis.entities.data.TreatmentCategoryRef rich = (org.drugis.addis.entities.data.TreatmentCategoryRef) category;
            TreatmentCategorization tc = CollectionUtils.find(domain.getTreatmentCategorizations(),
                    new Predicate<TreatmentCategorization>() {
                        public boolean evaluate(TreatmentCategorization object) {
                            Drug drug = JAXBConvertor.findNamedItem(domain.getDrugs(), rich.getDrug());
                            return object.getName().equals(rich.getName()) && object.getDrug().equals(drug);
                        }
                    });
            Category c = CollectionUtils.find(tc.getCategories(), new Predicate<Category>() {
                public boolean evaluate(Category object) {
                    return object.getName().equals(rich.getCategoryName());
                }
            });
            td.getContents().add(c);
        }
    }
    return td;
}

From source file:org.drugis.common.beans.FilteredObservableList.java

/**
 * @return The index i of the first item d_indices.get(i) > x, or d_indices.size() if none exists.
 *//*from   www  .ja  v a2  s  . c  o m*/
private int firstOver(final int x) {
    final int last = findFirstIndex(d_indices, new Predicate<Integer>() {
        @Override
        public boolean evaluate(final Integer index) {
            return index > x;
        }
    });
    return last < 0 ? d_indices.size() : last;
}

From source file:org.drugis.common.beans.FilteredObservableList.java

/**
 * @return The index i of the first item d_indices.get(i) >= x, or d_indices.size() if none exists.
 *//*ww  w .j a v a  2s. com*/
private int firstAtLeast(final int x) {
    final int first = findFirstIndex(d_indices, new Predicate<Integer>() {
        @Override
        public boolean evaluate(final Integer index) {
            return index >= x;
        }
    });
    return first < 0 ? d_indices.size() : first;
}

From source file:org.drugis.common.beans.FilteredObservableListTest.java

@Before
public void setUp() {
    d_inner = new ArrayListModel<String>(Arrays.asList("Gert", "Daan", "Jan", "Klaas"));
    d_filter = new Predicate<String>() {
        public boolean evaluate(String str) {
            return !str.contains("aa");
        }/*  w  w w  . j a  v  a  2s  . com*/
    };
    d_outer = new FilteredObservableList<String>(d_inner, d_filter);
}

From source file:org.drugis.common.beans.FilteredObservableListTest.java

@Test
public void testSetFilter() {
    ListDataListener mock = createStrictMock(ListDataListener.class);
    mock.intervalRemoved(ListDataEventMatcher
            .eqListDataEvent(new ListDataEvent(d_outer, ListDataEvent.INTERVAL_REMOVED, 0, 1)));
    mock.intervalAdded(ListDataEventMatcher
            .eqListDataEvent(new ListDataEvent(d_outer, ListDataEvent.INTERVAL_ADDED, 0, 2)));
    replay(mock);/*from w  ww  . j  a v  a  2s  .co  m*/
    d_outer.addListDataListener(mock);

    d_outer.setFilter(new Predicate<String>() {
        public boolean evaluate(String str) {
            return !str.equals("Gert");
        }
    });
    assertEquals(Arrays.asList("Daan", "Jan", "Klaas"), d_outer);
    verify(mock);
}

From source file:org.drugis.common.beans.FilteredObservableListTest.java

@Test
public void testSublistUpdating() {
    ObservableList<String> list = new SortedSetModel<String>(Arrays.asList("Aa", "Ab", "Ba", "Bb"));
    ObservableList<String> aList = new FilteredObservableList<String>(list, new Predicate<String>() {
        public boolean evaluate(String obj) {
            return obj.charAt(0) == 'A';
        }/*from   ww  w  .  ja v  a2s  . co m*/
    });
    ObservableList<String> bList = new FilteredObservableList<String>(list, new Predicate<String>() {
        public boolean evaluate(String obj) {
            return obj.charAt(0) == 'B';
        }
    });
    assertEquals(Arrays.asList("Aa", "Ab"), aList);
    assertEquals(Arrays.asList("Ba", "Bb"), bList);

    list.add("Ac");
    assertEquals(Arrays.asList("Aa", "Ab", "Ac"), aList);
    assertEquals(Arrays.asList("Ba", "Bb"), bList);
}

From source file:org.drugis.mtc.model.Study.java

public boolean containsTreatment(final Treatment t) {
    return CollectionUtils.exists(getMeasurements(), new Predicate<Measurement>() {
        public boolean evaluate(Measurement m) {
            return m.getTreatment().equals(t);
        }/*from  w  ww . j  a  va2  s .  co m*/
    });
}