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:netInt.utilities.predicates.Predicates.java

/**
 * Evaluates if a given node belongs to the named community
 * //from   w w  w .  j a  v  a  2s. c om
 * @param communityName
 *            the community
 * 
 * @return predicate with the boolean for a node
 */
public static Predicate<Node> nodeInCommunity(final String communityName) {
    Predicate<Node> nodeIncludedInSubgraph = new Predicate<Node>() {
        public boolean evaluate(Node nodo) {
            return nodo.belongsTo(communityName);
        }
    };
    return nodeIncludedInSubgraph;
}

From source file:netInt.utilities.predicates.Predicates.java

/**
 * Evaluates if the source and target of a given edge belong to the same
 * community/*from w  ww. ja v a  2s  .co  m*/
 * 
 * @param communityName communityName
 * @return predicate with the boolean for an edge
 */
public static Predicate<Edge> edgeInCommunity(final String communityName) {
    Predicate<Edge> rtnPredicate = new Predicate<Edge>() {
        public boolean evaluate(Edge edge) {
            Node source = edge.getSource();
            Node target = edge.getTarget();
            if (source.belongsTo(communityName) && target.belongsTo(communityName)) {
                return true;
            } else {
                return false;
            }
        }
    };
    return rtnPredicate;
}

From source file:netInt.utilities.predicates.Predicates.java

/**
 * Evaluates if a given edge links nodes from two communities. It checks if
 * either source and target belong to one of the two communities but both
 * cannot belong to the same community/* w  w  w  . j  ava 2  s. com*/
 * 
 * @param communityNameA communityName
 * @param communityNameB communityName
 * @return predicate with the boolean for an edge
 */
public static Predicate<Edge> edgeLinkingCommunities(final String communityNameA, final String communityNameB) {
    Predicate<Edge> rtnPredicate = new Predicate<Edge>() {
        public boolean evaluate(Edge edge) {
            Node source = edge.getSource();
            Node target = edge.getTarget();
            if (source.belongsTo(communityNameA) && target.belongsTo(communityNameB)) {
                return true;
            } else if (source.belongsTo(communityNameB) && target.belongsTo(communityNameA)) {
                return true;
            } else {
                return false;
            }
        }
    };
    return rtnPredicate;
}

From source file:nubisave.component.graph.splitteradaption.NubisaveEditor.java

/**
 * create an instance of a simple graph with popup controls to
 * create a graph.//from  ww w. j  a  v a  2s .  c  o  m
 *
 */
public NubisaveEditor() {

    // create a simple graph for the demo
    graph = new SortedSparseMultiGraph<NubiSaveVertex, NubiSaveEdge>();
    this.layout = new StaticLayout<NubiSaveVertex, NubiSaveEdge>(graph, new Dimension(600, 600));
    vv = new VisualizationViewer<NubiSaveVertex, NubiSaveEdge>(layout);
    dataVertexEdgeFactory = new DataVertexEdgeFactory();
    storage_directory = new PropertiesUtil("nubi.properties").getProperty("storage_configuration_directory");

    //Immediate Adaption to external changes
    int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;
    boolean watchSubtree = false;
    //        try {
    //            JNotify.addWatch(Nubisave.mainSplitter.getConfigDir(), mask, watchSubtree, new JNotifyConfigUpdater(dataVertexEdgeFactory, graph, vv));
    //        } catch (Exception ex) {
    //            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
    //        }

    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeStrokeTransformer(new EdgeWeightStrokeFunction<NubiSaveEdge>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<NubiSaveEdge>());
    vv.getRenderContext()
            .setVertexShapeTransformer(new BufferedImageDelegatorVertexShapeTransformer<NubiSaveVertex>());
    vv.getRenderContext()
            .setVertexIconTransformer(new BufferedImageDelegatorVertexIconTransformer<NubiSaveVertex>());
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new GenericComponentLabeller<NubiSaveVertex>());
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<NubiSaveVertex, NubiSaveEdge>());

    new BufferedImageDelegatorHighlighter(vv.getPickedVertexState());

    Container content = this;
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    final StatefulNubiSaveComponentFactory vertexFactory = new StatefulNubiSaveComponentFactory();
    Factory<? extends NubiSaveEdge> edgeFactory = new WeightedNubisaveVertexEdgeFactory();
    final PluggableGraphMouse graphMouse = createPluggableGraphMouse(vv.getRenderContext(), vertexFactory,
            edgeFactory, dataVertexEdgeFactory);
    //        try {
    //            // the EditingGraphMouse will pass mouse event coordinates to the
    //            // vertexLocations function to set the locations of the vertices as
    //            // they are created
    //graphMouse.setVertexLocations(vertexLocations);
    //            nubiSaveComponent = new NubiSaveComponent();
    //            nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2));
    //        } catch (IOException ex) {
    //            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
    //        }
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(new ActionKeyAdapter(vv.getPickedVertexState(), graph));

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(vv, instructions);
        }
    });
    addServicesToGraph();
    Graph<AbstractNubisaveComponent, Object> nubisaveComponentGraph = new VertexPredicateFilter(
            new Predicate() {
                @Override
                public boolean evaluate(Object vertex) {
                    return vertex instanceof AbstractNubisaveComponent;
                }
            }).transform(graph);
    interconnectNubisaveComponents(nubisaveComponentGraph, edgeFactory);
    //interconnectNubisaveComponents();

    JPanel controls = new JPanel();
    JButton chooseLocalComponent = new JButton("Custom Storage/Modification/Splitter Module");
    chooseLocalComponent.addActionListener(new ActionListener() {
        /**
         * Create new {@link StorageService} from chosen file and set it as the next Vertex to create in {@link StatefulNubiSaveComponentFactory}
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            CustomServiceDlg cusDlg = new CustomServiceDlg();
            cusDlg.pack();
            cusDlg.setLocationRelativeTo(null);
            cusDlg.setTitle("Module Selection");
            cusDlg.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            cusDlg.setVisible(true);
            String module = (String) cusDlg.getItemName();
            if (module != null) {
                module = module.split("\\.")[0];
            }
            if (module != null) {
                if (cusDlg.okstatus == "True") {
                    if (module.toLowerCase().equals("nubisave")) {
                        StorageService newService = new StorageService(module);
                        try {
                            vertexFactory.setNextInstance(new NubiSaveComponent(newService));
                            //nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2));
                        } catch (IOException ex) {
                            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        nubisave.Nubisave.services.addNubisave(newService);
                    } else {
                        StorageService newService = new StorageService(module);
                        try {
                            vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService));
                        } catch (IOException ex) {
                            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        nubisave.Nubisave.services.add(newService);
                    }
                }
            } else {
                JFileChooser customStorageserviceChooser = new javax.swing.JFileChooser();
                customStorageserviceChooser.setCurrentDirectory(
                        new java.io.File(nubisave.Nubisave.mainSplitter.getMountScriptDir()));
                customStorageserviceChooser.setDialogTitle("Custom Service");
                customStorageserviceChooser.setFileFilter(new IniFileFilter());
                int returnVal = customStorageserviceChooser.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = customStorageserviceChooser.getSelectedFile();
                    if (file.getName().toLowerCase().equals("nubisave.ini")) {
                        StorageService newService = new StorageService(file);
                        try {
                            vertexFactory.setNextInstance(new NubiSaveComponent(newService));
                            //nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2));
                        } catch (IOException ex) {
                            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        nubisave.Nubisave.services.addNubisave(newService);
                    } else {
                        StorageService newService = new StorageService(file);
                        try {
                            vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService));
                        } catch (IOException ex) {
                            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        nubisave.Nubisave.services.add(newService);
                    }
                }
            }
        }
    });
    controls.add(chooseLocalComponent);
    JButton searchServiceComponent = new JButton("Storage Service Directory");
    searchServiceComponent.addActionListener(new ActionListener() {
        /**
         * Create new {@link StorageService} from chosen file and set it as the next Vertex to create in {@link StatefulNubiSaveComponentFactory}
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            AddServiceDialog addServiceDlg = new AddServiceDialog(null, true);
            addServiceDlg.setVisible(true);

            for (MatchmakerService newService : addServiceDlg.getSelectedServices()) {
                try {
                    vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService));
                } catch (IOException ex) {
                    Logger.getLogger(AddServiceDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    controls.add(searchServiceComponent);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:org.drugis.addis.entities.analysis.RandomEffectsMetaAnalysis.java

List<RelativeEffect<? extends Measurement>> getFilteredRelativeEffects(
        Class<? extends RelativeEffect<?>> type) {
    final List<RelativeEffect<? extends Measurement>> relativeEffects = getRelativeEffects(type);
    CollectionUtils.filter(relativeEffects, new Predicate<RelativeEffect<? extends Measurement>>() {
        public boolean evaluate(RelativeEffect<? extends Measurement> re) {
            return re.isDefined();
        }/*from   w ww .  j a  v a2s .c  o m*/
    });
    return relativeEffects;
}

From source file:org.drugis.addis.entities.DomainImpl.java

public DomainImpl() {
    d_pairWiseMetaAnalyses = new FilteredObservableList<MetaAnalysis>(getMetaAnalyses(),
            new Predicate<MetaAnalysis>() {
                public boolean evaluate(MetaAnalysis obj) {
                    return obj instanceof PairWiseMetaAnalysis;
                }//from  w ww.  jav  a 2s.  co m
            });
    d_networkMetaAnalyses = new FilteredObservableList<MetaAnalysis>(getMetaAnalyses(),
            new Predicate<MetaAnalysis>() {
                public boolean evaluate(MetaAnalysis obj) {
                    return obj instanceof NetworkMetaAnalysis;
                }
            });
    d_units.add(GRAM);
    d_units.add(LITER);
}

From source file:org.drugis.addis.entities.DomainImpl.java

public ObservableList<TreatmentCategorization> getCategorizations(final Drug drug) {
    return new FilteredObservableList<TreatmentCategorization>(getTreatmentCategorizations(),
            new Predicate<TreatmentCategorization>() {
                public boolean evaluate(TreatmentCategorization obj) {
                    return obj.getDrug().equals(drug);
                }//from w w  w  .ja va 2 s . c  o m
            });
}

From source file:org.drugis.addis.entities.Study.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends Variable> ObservableList<StudyOutcomeMeasure<T>> convert(final Class<T> cls,
        final ObservableList<StudyOutcomeMeasure<? extends Variable>> list) {
    return (ObservableList) new FilteredObservableList<StudyOutcomeMeasure<? extends Variable>>(list,
            new Predicate<StudyOutcomeMeasure<? extends Variable>>() {
                @Override/*  www  .j av  a 2 s  . c om*/
                public boolean evaluate(final StudyOutcomeMeasure<? extends Variable> obj) {
                    return cls.equals(obj.getValueClass());
                }
            });
}

From source file:org.drugis.addis.entities.treatment.TreatmentCategorizationTest.java

private static DecisionTreeEdge findTypeEdge(final Collection<DecisionTreeEdge> edges, final Class<?> type) {
    final DecisionTreeEdge find = CollectionUtils.find(edges, new Predicate<DecisionTreeEdge>() {
        @Override/*from  w  w  w. jav a2  s. c  o  m*/
        public boolean evaluate(final DecisionTreeEdge object) {
            return (object instanceof TypeEdge) && object.decide(type);
        }
    });
    return find;
}

From source file:org.drugis.addis.gui.wizard.RangeInputPresentation.java

public RangeInputPresentation(final TreatmentCategorizationWizardPresentation presentationModel,
        final DecisionTreeNode parent, final String nextPropertyName) {
    d_pm = presentationModel;/*from w ww  .  ja  v  a2  s .c  o m*/
    d_parent = parent;
    d_nextPropertyName = nextPropertyName;

    d_edges = new DecisionTreeOutEdgesModel(d_pm.getBean().getDecisionTree(), d_parent);
    final TransformedObservableList<DecisionTreeEdge, DecisionTreeNode> selections = new TransformedObservableList<DecisionTreeEdge, DecisionTreeNode>(
            d_edges, new Transform<DecisionTreeEdge, DecisionTreeNode>() {
                @Override
                public DecisionTreeNode transform(final DecisionTreeEdge e) {
                    final DecisionTree tree = d_pm.getBean().getDecisionTree();
                    return tree.containsEdge(e) ? tree.getEdgeTarget(e) : null;
                }
            });

    final FilteredObservableList<DecisionTreeNode> choiceNodesSelected = new FilteredObservableList<DecisionTreeNode>(
            selections, new Predicate<DecisionTreeNode>() {
                @Override
                public boolean evaluate(final DecisionTreeNode obj) {
                    return obj != null && obj instanceof ChoiceNode;
                }
            });

    final ListMinimumSizeModel model = new ListMinimumSizeModel(choiceNodesSelected, 1);

    d_considerNext = new ValueModelWrapper<Boolean>(model);
}