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.mtc.parameterization.AbstractDataStartingValueGenerator.java

protected List<EstimateWithPrecision> estimateRelativeEffects(final BasicParameter p) {
    final Pair<Treatment> treatments = new Pair<Treatment>(p.getBaseline(), p.getSubject());
    Set<Study> studies = new HashSet<Study>(d_network.getStudies());
    CollectionUtils.filter(studies, new Predicate<Study>() {
        public boolean evaluate(Study study) {
            return study.getTreatments().containsAll(treatments);
        }//from   w ww  .  j  av a 2 s. c  om
    });

    List<EstimateWithPrecision> estimates = new ArrayList<EstimateWithPrecision>(studies.size());
    for (Study s : studies) {
        estimates.add(estimateRelativeEffect(s, p));
    }
    return estimates;
}

From source file:org.drugis.mtc.parameterization.InconsistencyBaselineSearchProblem.java

public List<Map<Study, Treatment>> getSuccessors(final Map<Study, Treatment> state) {
    // Find the first study without a baseline
    Study study = CollectionUtils.find(d_studies, new Predicate<Study>() {
        public boolean evaluate(Study study) {
            return !state.containsKey(study);
        }/*  ww  w  .  j a v  a2 s  .co m*/
    });

    if (study == null) {
        return Collections.emptyList();
    }

    // Each treatment generates a successor
    Set<Treatment> treatments = new TreeSet<Treatment>(new TreatmentComparator());
    treatments.addAll(study.getTreatments());
    List<Map<Study, Treatment>> succ = new ArrayList<Map<Study, Treatment>>(treatments.size());
    for (Treatment treatment : treatments) {
        Map<Study, Treatment> map = new HashMap<Study, Treatment>(state);
        map.put(study, treatment);
        succ.add(map);
    }

    return succ;
}

From source file:org.drugis.mtc.parameterization.InconsistencyBaselineSearchProblem.java

private boolean existsNoneMissing(Set<List<Treatment>> cycles,
        final Set<FoldedEdge<Treatment, Study>> covered) {
    return CollectionUtils.exists(cycles, new Predicate<List<Treatment>>() {
        public boolean evaluate(List<Treatment> cycle) {
            return countMissingEdges(cycle, covered) == 0;
        }/*www .  j a v  a 2s.  c  o m*/
    });
}

From source file:org.drugis.mtc.parameterization.InconsistencyBaselineSearchProblem.java

private boolean existsTooManyMissing(Set<List<Treatment>> cycles,
        final Set<FoldedEdge<Treatment, Study>> covered) {
    return CollectionUtils.exists(cycles, new Predicate<List<Treatment>>() {
        public boolean evaluate(List<Treatment> cycle) {
            return countMissingEdges(cycle, covered) < -1;
        }/*from   w w w . j  a  v  a2 s  .c o  m*/
    });
}

From source file:org.drugis.mtc.parameterization.NetworkModel.java

public static Measurement findMeasurement(final Study study, final Treatment treatment) {
    return CollectionUtils.find(study.getMeasurements(), new Predicate<Measurement>() {
        public boolean evaluate(Measurement m) {
            return m.getTreatment().equals(treatment);
        }/*w ww . j  a  va  2  s .c o  m*/
    });
}

From source file:org.drugis.mtc.parameterization.Part.java

/**
 * A part represents an undirected comparison measured by a set of studies.
 * Hence, (new Part(ta, tb, s)).equals(new Part(tb, ta, s)).
 *///from  w w  w .  j  av a 2  s.c  o m
public Part(final Treatment t1, final Treatment t2, final Set<Study> studies) {
    if (studies.isEmpty()) {
        throw new IllegalArgumentException("The given list of studies may not be empty.");
    }
    if (CollectionUtils.exists(studies, new Predicate<Study>() {
        public boolean evaluate(Study s) {
            return !s.containsTreatment(t1) || !s.containsTreatment(t2);
        }
    })) {
        throw new IllegalArgumentException("All studies must contain both treatments");
    }

    d_treatments.add(t1);
    d_treatments.add(t2);
    d_studies = studies;
}

From source file:org.echocat.jomon.runtime.util.ExtendingHints.java

@Override
public Iterator<Entry<Key<Object>, Object>> iterator() {
    return new FilterIterator<>(concat(super.iterator(), _superHints.iterator()),
            new Predicate<Entry<Key<Object>, Object>>() {
                @Override//from  w  w  w .  j  a va 2  s . c  o  m
                public boolean evaluate(Entry<Key<Object>, Object> entry) {
                    // noinspection ObjectEquality
                    return entry != null && entry.getValue() != NULL;
                }
            });
}

From source file:org.eknet.neoswing.loader.DefaultGraphLoaderManager.java

@Override
public Iterable<String> getRegisteredLoaders() {
    return new Iterable<String>() {
        @Override//from  w  w  w.j ava2 s . c  o m
        public Iterator<String> iterator() {
            return new FilterIterator<String>(loaders.keySet().iterator(), new Predicate<String>() {
                @Override
                public boolean evaluate(String s) {
                    GraphLoader gl = loaders.get(s);
                    return gl != null && gl.isSupported();
                }
            });
        }
    };
}

From source file:org.encog.workbench.tabs.visualize.epl.EPLTreeTab.java

public EPLTreeTab(final EncogProgram prg) {
    super(null);//from  w w  w.ja  v a 2s . c  o m

    // Graph<V, E> where V is the type of the vertices
    // and E is the type of the edges
    // Graph<V, E> where V is the type of the vertices 
    // and E is the type of the edges
    this.graph = new DelegateForest<ProgramNode, Integer>(
            new DirectedOrderedSparseMultigraph<ProgramNode, Integer>());

    buildGraph(prg);
    // Add some vertices. From above we defined these to be type Integer.
    // The Layout<V, E> is parameterized by the vertex and edge types
    TreeLayout<ProgramNode, Integer> treeLayout = new TreeLayout<ProgramNode, Integer>(graph);

    Transformer<ProgramNode, Paint> vertexPaint = new Transformer<ProgramNode, Paint>() {
        public Paint transform(ProgramNode v) {
            return Color.white;
        }
    };

    //layout.setSize(new Dimension(5000,5000)); // sets the initial size of the space
    // The BasicVisualizationServer<V,E> is parameterized by the edge types
    //BasicVisualizationServer<DrawnNeuron, DrawnConnection> vv = new BasicVisualizationServer<DrawnNeuron, DrawnConnection>(
    //      layout);

    //Dimension d = new Dimension(600,600);

    vv = new VisualizationViewer<ProgramNode, Integer>(treeLayout, new Dimension(600, 600));

    //vv.setPreferredSize(d); //Sets the viewing area size

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<ProgramNode, String>() {

        @Override
        public String transform(ProgramNode node) {
            ProgramExtensionTemplate temp = node.getTemplate();
            if (temp == StandardExtensions.EXTENSION_VAR_SUPPORT) {
                int varIndex = (int) node.getData()[0].toIntValue();
                return prg.getVariables().getVariableName(varIndex);
            } else if (temp == StandardExtensions.EXTENSION_CONST_SUPPORT) {
                ExpressionValue expr = node.getData()[0];
                if (expr.isFloat()) {
                    return Format.formatDouble(expr.toFloatValue(), 2);
                } else {
                    return node.getData()[0].toStringValue();
                }
            } else if (node.getTemplate().getNodeType().isOperator()) {
                return node.getTemplate().getName();
            } else {
                return node.getTemplate().getName() + "()";
            }

        }
    });

    vv.setVertexToolTipTransformer(new ToStringLabeller<ProgramNode>());

    vv.setVertexToolTipTransformer(new Transformer<ProgramNode, String>() {
        public String transform(ProgramNode node) {
            ProgramExtensionTemplate temp = node.getTemplate();
            if (temp == StandardExtensions.EXTENSION_CONST_SUPPORT) {
                return node.getData()[0].toStringValue();
            } else {
                return null;
            }
        }
    });

    /*vv.setEdgeToolTipTransformer(new Transformer<DrawnConnection,String>() {
       public String transform(DrawnConnection edge) {
    return edge.getToolTip();
       }});*/

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    this.setLayout(new BorderLayout());
    add(panel, BorderLayout.CENTER);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<ProgramNode, Integer>();
    vv.setGraphMouse(graphMouse);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setEdgeArrowPredicate(new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    Predicate d;

    vv.addKeyListener(graphMouse.getModeKeyListener());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.setLayout(new FlowLayout(FlowLayout.LEFT));
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    Border border = BorderFactory.createEtchedBorder();
    controls.setBorder(border);
    add(controls, BorderLayout.NORTH);

}

From source file:org.jcodec.containers.mp4.boxes.Box.java

public static Predicate<Box> not(final String type) {
    return new Predicate<Box>() {
        public boolean evaluate(Box object) {
            return !object.getHeader().getFourcc().equals(type);
        }/* w ww . jav  a 2 s  .c  o m*/
    };
}