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.jcodec.containers.mp4.boxes.TrakBox.java

public static Predicate<TrakBox> videoTrack() {
    return new Predicate<TrakBox>() {
        public boolean evaluate(TrakBox box) {
            return box.isVideo();
        }//from   ww  w  .j a va  2 s  . com
    };
}

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

public static Predicate<Box> audioTrack() {
    return new Predicate<Box>() {
        public boolean evaluate(Box box) {
            if (!(box instanceof TrakBox))
                return false;
            if (((TrakBox) box).isAudio())
                return true;
            return false;
        }//from   w  ww. j a  va2  s.c o  m
    };
}

From source file:org.mathIT.gui.GraphViewer.java

/**
 * This method is called from within the constructor to initialize the frame.
 *//*from  w  w  w .ja v a2 s  .  c  o m*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initComponents() {
    layout = new KKLayout<>(this.graph);
    //layout = new FRLayout<>(this.graph);
    //layout = new CircleLayout<>(this.graph);

    // Dimension preferredSize = new Dimension(840, 585); // old!
    Dimension preferredSize = new Dimension(900, 585);
    final VisualizationModel<V, E> visualizationModel = new DefaultVisualizationModel<>(layout, preferredSize);
    canvas = new GraphCanvas<>(this, visualizationModel, preferredSize);

    final PredicatedParallelEdgeIndexFunction<V, E> eif = PredicatedParallelEdgeIndexFunction.getInstance();
    final Set<E> exclusions = new HashSet<>();
    eif.setPredicate(new Predicate<E>() {
        @Override
        public boolean evaluate(E e) {
            return exclusions.contains(e);
        }
    });

    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(GraphViewer.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(GraphViewer.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(GraphViewer.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(GraphViewer.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }

    canvas.setBackground(Color.white);

    // --- Vertex configuration: ---
    //canvas.getRenderContext().setVertexShapeTransformer(new GraphViewer.ClusterVertexShapeFunction());
    // ---- Vertex color: ----
    canvas.getRenderer()
            .setVertexRenderer(new edu.uci.ics.jung.visualization.renderers.GradientVertexRenderer<>(
                    Color.yellow, Color.yellow, // colors in normal state
                    Color.white, Color.red, // colors in picked state
                    canvas.getPickedVertexState(), false));
    //canvas.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer<V>(canvas.getPickedVertexState(), Color.red, Color.yellow));

    pickActivated();

    // --- Vertex labels: -----
    canvas.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<>());
    canvas.getRenderer().getVertexLabelRenderer()
            .setPositioner(new BasicVertexLabelRenderer.InsidePositioner());
    canvas.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    // add a listener for ToolTips
    canvas.setVertexToolTipTransformer(new ToStringLabeller<V>() {
        /* (non-Javadoc)
         * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object)
         */
        @Override
        public String transform(V v) {
            if (v instanceof Graph) {
                return ((Graph<V>) v).getVertices().toString();
            }
            //return super.transform((V) v);
            return v.toString();
        }
    });

    // add a listener for ToolTips
    canvas.setEdgeToolTipTransformer(new ToStringLabeller<E>() {
        /* (non-Javadoc)
         * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object)
         */
        @Override
        public String transform(E e) {
            return e.toString();
        }
    });

    // ---  Edge Labels: ---
    canvas.getRenderContext().setParallelEdgeIndexFunction(eif);
    canvas.getRenderContext().getEdgeLabelRenderer();

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse<V, E> graphMouse = new DefaultModalGraphMouse<>();

    canvas.setGraphMouse(graphMouse);

    // --- Control Panel: ---------------
    content = getContentPane();
    gzsp = new GraphZoomScrollPane(canvas);
    content.add(gzsp);

    modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    //graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    modePanel = new JPanel();
    modePanel.setBorder(BorderFactory.createTitledBorder("Selection Mode"));
    modePanel.setLayout(new java.awt.GridLayout(3, 1));
    modePanel.add(modeBox);

    if (invokerGraph instanceof NetworkOfActivatables) {
        JButton next = new JButton("Next Activation Step");
        next.addActionListener((ActionEvent e) -> {
            nextActivationStep();
        });
        modePanel.add(next);
        JButton runAll = new JButton("Run Entire Activation");
        runAll.addActionListener((ActionEvent e) -> {
            runActivation();
        });
        modePanel.add(runAll);
    }

    scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener((ActionEvent e) -> {
        scaler.scale(canvas, 1.1f, canvas.getCenter());
    });
    JButton minus = new JButton("-");
    minus.addActionListener((ActionEvent e) -> {
        scaler.scale(canvas, 1 / 1.1f, canvas.getCenter());
    });

    buttonPanel = new JPanel();
    buttonPanel.setLayout(new java.awt.GridLayout(4, 1));
    print = new JButton("Print");
    print.addActionListener((ActionEvent e) -> {
        canvas.startPrinterJob();
    });
    buttonPanel.add(print);

    help = new JButton("Help");
    help.addActionListener((ActionEvent e) -> {
        JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help",
                JOptionPane.PLAIN_MESSAGE);
    });
    buttonPanel.add(help);

    load = new JButton("Load CSV File");
    load.addActionListener((ActionEvent e) -> {
        //content.setCursor(new Cursor(Cursor.WAIT_CURSOR)); // funktioniert nicht...
        if (invokerGraph instanceof SocialNetwork) {
            SocialNetwork g = SocialNetwork.createNetworkFromCSVFile();
            if (g != null) {
                this.setVisible(false);
                //invokerGraph.shutDisplay();
                visualize(g);
            }
        } else if (invokerGraph instanceof WeightedGraph) {
            WeightedGraph<SimpleVertex> g = WeightedGraph.createWeightedGraphFromCSVFile();
            if (g != null) {
                this.setVisible(false);
                //invokerGraph.shutDisplay();
                visualize(g);
            }
        } else {
            org.mathIT.graphs.Graph<SimpleVertex> g = org.mathIT.graphs.Graph.createGraphFromCSVFile();
            if (g != null) {
                this.setVisible(false);
                //invokerGraph.shutDisplay();
                visualize(g);
            }
        }
        // content.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); // funktioniert nicht...
    });
    buttonPanel.add(load);

    save = new JButton("Save as CSV");
    save.addActionListener((ActionEvent e) -> {
        if (invokerGraph instanceof SocialNetwork) {
            for (V v : graph.getVertices()) {
                Activatable a = (Activatable) v;
                if (canvas.getPickedVertexState().isPicked(v)) {
                    ((NetworkOfActivatables<Activatable>) invokerGraph).setActive(true);
                    a.setActive(true);
                    //} else {
                    //   a.setActive(false);
                }
            }
            ((SocialNetwork) invokerGraph).saveAsCSV();
        } else if (invokerGraph instanceof WeightedGraph) {
            ((WeightedGraph<V>) invokerGraph).saveAsCSV();
        } else {
            invokerGraph.saveAsCSV();
        }
    });
    buttonPanel.add(save);

    Class<? extends Layout<?, ?>>[] combos = getCombos();
    jcb = new JComboBox<>(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new GraphViewer.LayoutChooser(jcb, canvas));
    //jcb.setSelectedItem(KKLayout.class);
    //jcb.setSelectedItem(FRLayout.class);
    //jcb.setSelectedItem(CircleLayout.class);
    jcb.setSelectedItem(layout.getClass());

    layoutChoice = new JPanel();
    layoutChoice.setBorder(BorderFactory.createTitledBorder("Graph Layout"));
    layoutChoice.setLayout(new java.awt.GridLayout(2, 1));
    layoutChoice.add(jcb);

    // Edge labels:
    edgePanel = new JPanel();
    edgeLabels = new javax.swing.JCheckBox("Edge Labels");
    edgePanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
    edgeLabels.addActionListener((java.awt.event.ActionEvent evt) -> {
        writeEdgeLabels();
    });
    edgePanel.add(edgeLabels);
    edgePanel.add(edgeLabels);
    layoutChoice.add(edgePanel);

    clusterControls = new JPanel(new GridLayout(3, 1));
    if (invokerGraph instanceof org.mathIT.graphs.Graph) {
        clusterControls.setBorder(BorderFactory.createTitledBorder("Clusters"));
        JButton detect = new JButton("Detect (Greedy)");
        detect.addActionListener((ActionEvent e) -> {
            detectClusters();
        });
        clusterControls.add(detect);

        JButton detectExactly = new JButton("Detect (Brute force)");
        detectExactly.addActionListener((ActionEvent e) -> {
            detectClustersExactly();
        });
        clusterControls.add(detectExactly);

        JButton influencers = new JButton("Network Relevance");
        influencers.addActionListener((ActionEvent e) -> {
            displayRelevanceClusters();
        });
        clusterControls.add(influencers);
    }

    matrixControls = new JPanel(new GridLayout(3, 1));
    if (invokerGraph instanceof org.mathIT.graphs.Graph) {
        matrixControls.setBorder(BorderFactory.createTitledBorder("Matrices"));
        JButton adjacency = new JButton("Adjacency");
        adjacency.addActionListener((ActionEvent e) -> {
            org.mathIT.algebra.Matrix A = new org.mathIT.algebra.Matrix(invokerGraph.getAdjacency());
            new org.mathIT.gui.MatrixAlgebra("Adjacency matrix", A);
        });
        matrixControls.add(adjacency);

        JButton computeHashimoto = new JButton("Hashimoto");
        computeHashimoto.addActionListener((ActionEvent e) -> {
            org.mathIT.algebra.Matrix B = new org.mathIT.algebra.Matrix(invokerGraph.computeHashimoto());
            new org.mathIT.gui.MatrixAlgebra("Hashimoto matrix", B);
        });
        matrixControls.add(computeHashimoto);
    }

    // --- Build up Control Panel: ----
    controls = new JPanel();
    //controls.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER));
    zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    controls.add(layoutChoice);
    controls.add(modePanel);
    if (invokerGraph instanceof org.mathIT.graphs.Graph) {
        controls.add(clusterControls);
        controls.add(matrixControls);
    }
    controls.add(buttonPanel);
    content.add(controls, BorderLayout.SOUTH);

    // Frame Properties:
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
    //layout.setSize(canvas.getSize());
    //scaler.scale(canvas, 1.f, canvas.getCenter());
    setVisible(true);
}

From source file:org.opendaylight.nemo.intent.algorithm.RoutingAlgorithm.java

/**
 * Compute a shortest path with the given bandwidth from the given
 * source vertex to target one.//w  ww .  j av  a2 s.  c  o m
 *
 * @param source The given source vertex.
 * @param target The given target vertex.
 * @param bandwidth The given bandwidth for the path.
 * @return A list of the edges on the shortest path, in order of
 * their occurrence on this path.
 */
public List<Edge> computePath(Vertex source, Vertex target, final long bandwidth) {
    EdgePredicateFilter<Vertex, Edge> edgeEdgePredicateFilter = new EdgePredicateFilter<Vertex, Edge>(
            new Predicate<Edge>() {
                @Override
                public boolean evaluate(Edge edge) {
                    return edge.getBandwidth() >= bandwidth;
                }
            });

    Graph<Vertex, Edge> filteredGraph = edgeEdgePredicateFilter.transform(graph);
    DijkstraShortestPath<Vertex, Edge> tempDijkstraShortestPath = new DijkstraShortestPath<Vertex, Edge>(
            filteredGraph, new Transformer<Edge, Number>() {
                @Override
                public Number transform(Edge edge) {
                    return edge.getMetric();
                }
            }, false);

    return tempDijkstraShortestPath.getPath(source, target);
}

From source file:org.risk.model.MapVisualization.java

/**
 * This method is used to customize the graph which represents map of the
 * game/*from   ww w.j a  v a2  s . c  o  m*/
 * @param map 
 */
private void customizeGraph(final Map map) {

    Transformer<Integer, Point2D> locationTransformer = new Transformer<Integer, Point2D>() {

        @Override
        public Point2D transform(Integer v) {

            float xPoint = states.get(v - 1).getxPoint();
            float yPoint = states.get(v - 1).getyPoint();
            return new Point2D.Float(xPoint, yPoint);
        }
    };

    StaticLayout<Integer, Number> layout = new StaticLayout<Integer, Number>(graph, locationTransformer);
    vv = new VisualizationViewer<Integer, Number>(layout);

    //vv.setBackground(Color.white);
    // add my listener for ToolTips

    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, Number>());
    vv.setVertexToolTipTransformer(new stateInfoTip<Number>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    // Remove Arrows
    vv.getRenderContext().setEdgeArrowPredicate(new Predicate<Context<Graph<Integer, Number>, Number>>() {
        public boolean evaluate(Context<Graph<Integer, Number>, Number> context) {
            return false;
        }
    });

    final PickedState<Integer> pickedState = vv.getPickedVertexState();

    pickedState.addItemListener(new ItemListener() {

        /**
         * This method is used to override itemStateChanged
         */
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object selectedNode = e.getItem();
            if (selectedNode instanceof Integer) {
                Integer vertex = (Integer) selectedNode;

                if (pickedState.isPicked(vertex)) {
                    String inspectionDetail = inspectState(map, vertex);
                    JOptionPane.showMessageDialog(vv, inspectionDetail);
                }
            }
        }
    });
}

From source file:vnreal.network.substrate.SubstrateNetwork.java

public void precalculatedBackupPath(int k) {
    for (SubstrateLink sl : this.getEdges()) {
        Predicate<SubstrateLink> pre = new Predicate<SubstrateLink>() {
            @Override//  www .j  a va  2 s  .c o  m
            public boolean evaluate(SubstrateLink arg0) {
                if (arg0.equals(sl))
                    return false;
                return true;
            }
        };
        EdgePredicateFilter<SubstrateNode, SubstrateLink> filter = new EdgePredicateFilter<SubstrateNode, SubstrateLink>(
                pre);
        Graph<SubstrateNode, SubstrateLink> tmp = filter.transform(this);
        Transformer<SubstrateLink, Number> bbc = new Transformer<SubstrateLink, Number>() {
            @Override
            public Number transform(SubstrateLink arg0) {
                return 1;
            }
        };
        Yen<SubstrateNode, SubstrateLink> yen = new Yen<SubstrateNode, SubstrateLink>(tmp, bbc);
        sl.setKsp(yen.getShortestPaths(this.getEndpoints(sl).getFirst(), this.getEndpoints(sl).getSecond(), k));
    }
}