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:ch.algotrader.service.HistoricalDataServiceImpl.java

private void updateBars(final long securityId, final Duration barSize, List<Bar> bars) {

    // get the last Bar int the Database
    final Bar lastBar = CollectionUtil
            .getSingleElementOrNull(this.barDao.findBarsBySecurityAndBarSize(1, securityId, barSize));

    // remove all Bars prior to the lastBar
    if (lastBar != null) {

        CollectionUtils.filter(bars, new Predicate<Bar>() {
            @Override//www.java2  s  .  c o  m
            public boolean evaluate(Bar bar) {
                return bar.getDateTime().compareTo(lastBar.getDateTime()) > 0;
            }
        });
    }

    // save the Bars
    this.barDao.saveAll(bars);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("created {} new bars for security {}", bars.size(), securityId);
    }
}

From source file:ch.algotrader.esper.EngineManagerImpl.java

@Override
@SuppressWarnings("unchecked")
public void logStatementMetrics() {

    for (Map.Entry<String, Engine> entry : this.engineMap.entrySet()) {
        Engine engine = entry.getValue();

        if (engine.isDeployed("METRICS")) {

            List<StatementMetricVO> metrics = engine.getAllEvents("METRICS");

            // consolidate ON_TRADE_COMPLETED and ON_FIRST_TICK
            for (final String statementName : new String[] { "ON_TRADE_COMPLETED", "ON_FIRST_TICK" }) {

                // select metrics where the statementName startsWith
                Collection<StatementMetricVO> selectedMetrics = CollectionUtils.select(metrics,
                        new Predicate<StatementMetricVO>() {
                            @Override
                            public boolean evaluate(StatementMetricVO metric) {
                                return metric.getStatementName() != null
                                        && metric.getStatementName().startsWith(statementName);
                            }/* w  ww . j a va2 s. c  o m*/
                        });

                // add cpuTime, wallTime and numInput
                if (selectedMetrics.size() > 0) {

                    long cpuTime = 0;
                    long wallTime = 0;
                    long numInput = 0;
                    for (StatementMetricVO metric : selectedMetrics) {

                        cpuTime += metric.getCpuTime();
                        wallTime += metric.getWallTime();
                        numInput += metric.getNumInput();

                        // remove the original metric
                        metrics.remove(metric);
                    }

                    // add a consolidated metric
                    metrics.add(new StatementMetricVO(engine.getStrategyName(), statementName, cpuTime,
                            wallTime, numInput));
                }
            }

            if (LOGGER.isInfoEnabled()) {
                for (StatementMetricVO metric : metrics) {
                    LOGGER.info("{}.{}: {} millis {} events", metric.getEngineURI(), metric.getStatementName(),
                            metric.getWallTime(), metric.getNumInput());
                }
            }
        }
    }
}

From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java

public VertexCollapseDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();
    collapser = new GraphCollapser(graph);

    layout = new FRLayout(graph);

    Dimension preferredSize = new Dimension(400, 400);
    final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize);
    vv = new VisualizationViewer(visualizationModel, preferredSize);

    vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction());

    final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance();
    final Set exclusions = new HashSet();
    eif.setPredicate(new Predicate() {

        public boolean evaluate(Object e) {

            return exclusions.contains(e);
        }//from  w  ww  . j av  a 2  s.c o m
    });

    vv.getRenderContext().setParallelEdgeIndexFunction(eif);

    vv.setBackground(Color.white);

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller() {

        /* (non-Javadoc)
         * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object)
         */
        @Override
        public String transform(Object v) {
            if (v instanceof Graph) {
                return ((Graph) v).getVertices().toString();
            }
            return super.transform(v);
        }
    });

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    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 collapse = new JButton("Collapse");
    collapse.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            if (picked.size() > 1) {
                Graph inGraph = layout.getGraph();
                Graph clusterGraph = collapser.getClusterGraph(inGraph, picked);

                Graph g = collapser.collapse(layout.getGraph(), clusterGraph);
                double sumx = 0;
                double sumy = 0;
                for (Object v : picked) {
                    Point2D p = (Point2D) layout.transform(v);
                    sumx += p.getX();
                    sumy += p.getY();
                }
                Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size());
                vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                layout.setGraph(g);
                layout.setLocation(clusterGraph, cp);
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

    JButton compressEdges = new JButton("Compress Edges");
    compressEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.addAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expandEdges = new JButton("Expand Edges");
    expandEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.removeAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expand = new JButton("Expand");
    expand.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            for (Object v : picked) {
                if (v instanceof Graph) {

                    Graph g = collapser.expand(layout.getGraph(), (Graph) v);
                    vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                    layout.setGraph(g);
                }
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

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

        public void actionPerformed(ActionEvent e) {
            layout.setGraph(graph);
            exclusions.clear();
            vv.repaint();
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help",
                    JOptionPane.PLAIN_MESSAGE);
        }
    });

    JPanel controls = new JPanel();
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    JPanel collapseControls = new JPanel(new GridLayout(3, 1));
    collapseControls.setBorder(BorderFactory.createTitledBorder("Picked"));
    collapseControls.add(collapse);
    collapseControls.add(expand);
    collapseControls.add(compressEdges);
    collapseControls.add(expandEdges);
    collapseControls.add(reset);
    controls.add(collapseControls);
    controls.add(modeBox);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemoWithLayouts.java

public VertexCollapseDemoWithLayouts() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();
    collapsedGraph = graph;/*ww  w.  j  a  v  a  2  s.  co m*/
    collapser = new GraphCollapser(graph);

    layout = new FRLayout(graph);

    Dimension preferredSize = new Dimension(400, 400);
    final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize);
    vv = new VisualizationViewer(visualizationModel, preferredSize);

    vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction());

    final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance();
    final Set exclusions = new HashSet();
    eif.setPredicate(new Predicate() {

        public boolean evaluate(Object e) {

            return exclusions.contains(e);
        }
    });

    vv.getRenderContext().setParallelEdgeIndexFunction(eif);

    vv.setBackground(Color.white);

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller() {

        /* (non-Javadoc)
         * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object)
         */
        @Override
        public String transform(Object v) {
            if (v instanceof Graph) {
                return ((Graph) v).getVertices().toString();
            }
            return super.transform(v);
        }
    });

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    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 collapse = new JButton("Collapse");
    collapse.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            if (picked.size() > 1) {
                Graph inGraph = layout.getGraph();
                Graph clusterGraph = collapser.getClusterGraph(inGraph, picked);

                Graph g = collapser.collapse(layout.getGraph(), clusterGraph);
                collapsedGraph = g;
                double sumx = 0;
                double sumy = 0;
                for (Object v : picked) {
                    Point2D p = (Point2D) layout.transform(v);
                    sumx += p.getX();
                    sumy += p.getY();
                }
                Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size());
                vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                layout.setGraph(g);
                layout.setLocation(clusterGraph, cp);
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

    JButton compressEdges = new JButton("Compress Edges");
    compressEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.addAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expandEdges = new JButton("Expand Edges");
    expandEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.removeAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expand = new JButton("Expand");
    expand.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            for (Object v : picked) {
                if (v instanceof Graph) {

                    Graph g = collapser.expand(layout.getGraph(), (Graph) v);
                    vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                    layout.setGraph(g);
                }
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

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

        public void actionPerformed(ActionEvent e) {
            layout.setGraph(graph);
            exclusions.clear();
            vv.repaint();
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help",
                    JOptionPane.PLAIN_MESSAGE);
        }
    });
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        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 LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel controls = new JPanel();
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    JPanel collapseControls = new JPanel(new GridLayout(3, 1));
    collapseControls.setBorder(BorderFactory.createTitledBorder("Picked"));
    collapseControls.add(collapse);
    collapseControls.add(expand);
    collapseControls.add(compressEdges);
    collapseControls.add(expandEdges);
    collapseControls.add(reset);
    controls.add(collapseControls);
    controls.add(modeBox);
    controls.add(help);
    controls.add(jcb);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:com.bluexml.tools.graph.engines.jung.transformer.GraphFilter.java

public static <V, E> Graph<V, E> applyVertexTypeFilter(final Graph<V, E> graph, final String vertexTypeFilter,
        final boolean includesAscendant, final boolean includesdescendant, final boolean caseSensitive) {
    logger.debug("Apply Vertex Type Filter" + vertexTypeFilter);
    if (!vertexTypeFilter.equals("")) {

        final List<String> vertexTypes = new ArrayList<String>();

        String[] split = vertexTypeFilter.split(",");
        for (String string : split) {
            vertexTypes.add(string);/* w w w . ja va  2  s . co m*/
        }

        Predicate<V> vertex_pred = new Predicate<V>() {
            public boolean evaluate(V object) {
                // TODO Auto-generated method stub
                boolean matches = match(vertexTypes, object);
                boolean isAscendant = false, isdecendant = false;

                if (includesAscendant) {
                    // search if this vertex is an ascendent of matching vertex

                    isAscendant = ascandantMatches(vertexTypes, object);
                }

                if (includesdescendant) {
                    isdecendant = descendantMatches(vertexTypes, object);
                }
                return matches || isAscendant || isdecendant;
            }

            private boolean ascandantMatches(final List<String> vertexTypes, V object) {
                boolean matches = match(vertexTypes, object);
                if (!matches) {
                    // try to search for children
                    Collection<V> successors = graph.getSuccessors(object);
                    for (V componant : successors) {
                        if (ascandantMatches(vertexTypes, componant)) {
                            matches = true;
                            break;
                        }
                    }
                }
                return matches;
            }

            private boolean descendantMatches(final List<String> vertexTypes, V object) {
                boolean matches = match(vertexTypes, object);
                if (!matches) {
                    // try to search for children
                    Collection<V> predecessors = graph.getPredecessors(object);
                    for (V componant : predecessors) {
                        if (descendantMatches(vertexTypes, componant)) {
                            matches = true;
                            break;
                        }
                    }
                }
                return matches;
            }

            private boolean match(List<String> vertexTypes, V object) {
                boolean ok = false;
                for (String string2 : vertexTypes) {
                    ok = testClassName(object, string2);
                    break;
                }
                return ok;
            }
        };

        VertexPredicateFilter<V, E> vf = new VertexPredicateFilter<V, E>(vertex_pred);

        return vf.transform(graph);
    } else {
        return graph;
    }
}

From source file:com.bluexml.side.build.tools.graph.jung.algorithms.GraphFilter.java

public static Graph<Componant, String> applyVertexTypeFilter(final Graph<Componant, String> graph,
        final String vertexTypeFilter, final boolean includesAscendant, final boolean includesdescendant,
        final boolean caseSensitive) {
    logger.debug("Apply Vertex Type Filter" + vertexTypeFilter);
    if (!vertexTypeFilter.equals("")) {

        final List<String> vertexTypes = new ArrayList<String>();

        String[] split = vertexTypeFilter.split(",");
        for (String string : split) {
            vertexTypes.add(string);//from   w w  w.  j  a v  a 2 s.  c o m
        }

        Predicate<Componant> vertex_pred = new Predicate<Componant>() {
            public boolean evaluate(Componant object) {
                // TODO Auto-generated method stub
                boolean matches = match(vertexTypes, object);
                boolean isAscendant = false, isdecendant = false;

                if (includesAscendant) {
                    // search if this vertex is an ascendent of matching vertex

                    isAscendant = ascandantMatches(vertexTypes, object);
                }

                if (includesdescendant) {
                    isdecendant = descendantMatches(vertexTypes, object);
                }
                return matches || isAscendant || isdecendant;
            }

            private boolean ascandantMatches(final List<String> vertexTypes, Componant object) {
                boolean matches = match(vertexTypes, object);
                if (!matches) {
                    // try to search for children
                    Collection<Componant> successors = graph.getSuccessors(object);
                    for (Componant componant : successors) {
                        if (ascandantMatches(vertexTypes, componant)) {
                            matches = true;
                            break;
                        }
                    }
                }
                return matches;
            }

            private boolean descendantMatches(final List<String> vertexTypes, Componant object) {
                boolean matches = match(vertexTypes, object);
                if (!matches) {
                    // try to search for children
                    Collection<Componant> predecessors = graph.getPredecessors(object);
                    for (Componant componant : predecessors) {
                        if (descendantMatches(vertexTypes, componant)) {
                            matches = true;
                            break;
                        }
                    }
                }
                return matches;
            }

            private boolean match(List<String> vertexTypes, Componant object) {
                boolean ok = false;
                for (String string2 : vertexTypes) {
                    ok = testClassName(object, string2);
                    break;
                }
                return ok;
            }
        };

        VertexPredicateFilter<Componant, String> vf = new VertexPredicateFilter<Componant, String>(vertex_pred);

        return vf.transform(graph);
    } else {
        return graph;
    }
}

From source file:ch.algotrader.service.CombinationServiceImpl.java

/**
 * {@inheritDoc}/*from  w ww. j  a  v  a2  s  .c  o  m*/
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public Combination removeComponent(final long combinationId, final long securityId) {

    Combination combination = this.combinationDao.get(combinationId);

    if (combination == null) {
        throw new IllegalArgumentException("combination does not exist: " + combinationId);
    }

    String combinationString = combination.toString();

    if (this.securityDao.load(securityId) == null) {
        throw new IllegalArgumentException("security does not exist: " + securityId);
    }

    // find the component to the specified security
    Component component = CollectionUtils.find(combination.getComponents(), new Predicate<Component>() {
        @Override
        public boolean evaluate(Component component) {
            return component.getSecurity().getId() == securityId;
        }
    });

    if (component != null) {

        // update the combination
        combination.getComponents().remove(component);

        // delete the component
        this.componentDao.delete(component);

        // remove the component from the ComponentWindow
        removeFromComponentWindow(component);

        // update the ComponentWindow
        insertIntoComponentWindow(combination);

    } else {

        throw new IllegalArgumentException("component on securityId " + securityId + " does not exist");
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("removed component {} from combination {}", component, combinationString);
    }

    return combination;

}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java

public void initialise() {

    plotInfoByPlotId.clear();/* ww w.  j  a v a2s. c  o m*/
    try {

        KDSmartDatabase.WithPlotAttributesOption wpa = KDSmartDatabase.WithPlotAttributesOption.WITHOUT_PLOT_ATTRIBUTES;

        Map<Integer, Plot> plotById = kdxdb
                .getPlots(trial, SampleGroupChoice.create(sampleGroup.getSampleGroupId()), wpa).stream()
                .collect(Collectors.toMap(Plot::getPlotId, java.util.function.Function.identity()));

        traitById = kdxdb.getKDXploreKSmartDatabase().getTraitMap();

        KDSmartDatabase.WithTraitOption wto = KDSmartDatabase.WithTraitOption.ALL_WITH_TRAITS;
        Predicate<TraitInstance> tiVisitor = new Predicate<TraitInstance>() {
            @Override
            public boolean evaluate(TraitInstance ti) {
                String key = makeTiKey(ti.getTraitId(), ti.getInstanceNumber());
                tiByKey.put(key, ti);
                return true;
            }
        };
        kdxdb.getKDXploreKSmartDatabase().visitTraitInstancesForTrial(trial.getTrialId(), wto, tiVisitor);

        Set<Integer> traitIdsSeen = new HashSet<>();
        //            sampleGroup.getTrialId();
        java.util.function.Predicate<KdxSample> visitor = new java.util.function.Predicate<KdxSample>() {
            @Override
            public boolean test(KdxSample s) {
                Plot plot = plotById.get(s.getPlotId());
                if (plot == null) {
                    System.err.println("Missing Plot#" + s.getPlotId());
                } else {
                    PlotInfo pinfo = plotInfoByPlotId.get(plot.getPlotId());
                    if (pinfo == null) {
                        pinfo = new PlotInfo(plot);
                        plotInfoByPlotId.put(plot.getPlotId(), pinfo);
                    }
                    Integer traitId = s.getTraitId();
                    traitIdsSeen.add(traitId);

                    pinfo.addSample(s);
                }
                return true;
            }
        };
        boolean scored = false;
        kdxdb.visitKdxSamplesForSampleGroup(sampleGroup, KdxploreDatabase.SampleLevel.BOTH, scored, visitor);
    } catch (IOException e) {
        MsgBox.error(SampleGroupViewer.this, e, "Database Error");
        return;
    }
}

From source file:mulavito.algorithms.shortestpath.ksp.Yen.java

/**
 * Blocks all incident edges of the vertices in head as well as the edge
 * connecting head to the next node by creating a new filtered graph.
 * //from  w  ww  .  j av  a2  s . com
 * @param head
 *            The current head, from source to deviation node
 * @param deviation
 *            The edge to the next node
 * @param foundPaths
 *            The solutions already found and to check against
 * @return The filtered graph without the blocked edges.
 */
private Graph<V, E> blockFilter(List<E> head, V deviation, List<V> curShortestPathNodes,
        List<List<E>> foundPaths) {
    final Set<E> blocked = new HashSet<E>();

    // Block incident edges to make all vertices in head unreachable.
    for (V v : curShortestPathNodes) {
        if (v.equals(deviation))
            break;
        for (E e2 : graph.getIncidentEdges(v))
            blocked.add(e2);
    }
    /*for (E e : head)
       for (E e2 : graph.getIncidentEdges(graph.getEndpoints(e).getFirst()))
    blocked.add(e2);*/

    // Block all outgoing edges that have been used at deviation vertex
    for (List<E> path : foundPaths)
        if (path.size() > head.size() && ListUtils.isEqualList(path.subList(0, head.size()), head))
            for (E e : path)

                if (graph.getEndpoints(e).contains(deviation)) {
                    blocked.add(e);
                    //break; // Continue with next path.
                }

    EdgePredicateFilter<V, E> filter = new EdgePredicateFilter<V, E>(new Predicate<E>() {
        @Override
        public boolean evaluate(E e) {
            return !blocked.contains(e);
        }
    });

    return filter.transform(graph);
}

From source file:net.schweerelos.parrot.ui.GraphViewComponent.java

@SuppressWarnings("serial")
private void setupRenderContext(final VisualizationViewer<NodeWrapper, NodeWrapper> vis) {
    vis.setRenderer(new ParrotGraphRenderer());
    vis.setPickSupport(new ParrotPickSupport(vis));

    RenderContext<NodeWrapper, NodeWrapper> renderContext = vis.getRenderContext();

    final PickedInfo<NodeWrapper> vertexPickInfo = vis.getPickedVertexState();
    final PickedState<NodeWrapper> edgePickInfo = vis.getPickedEdgeState();

    // hide all edge arrows except for those on outgoing edges of picked
    // nodes//from www . ja  v  a 2  s. c o  m
    renderContext.setEdgeArrowPredicate(new Predicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>() {
        @Override
        public boolean evaluate(Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper> context) {
            NodeWrapper edge = context.element;
            NodeWrapper source = graph.getSource(edge);
            return vertexPickInfo.isPicked(source);
        }
    });

    // make edges straight lines to collapse parallel edges
    renderContext.setEdgeShapeTransformer(new EdgeShape.Line<NodeWrapper, NodeWrapper>());

    // hide text of all edges except for outgoing edges of picked nodes
    renderContext.setEdgeLabelTransformer(new Transformer<NodeWrapper, String>() {
        @Override
        public String transform(NodeWrapper edge) {
            NodeWrapper source = graph.getSource(edge);
            NodeWrapper destination = graph.getDest(edge);
            if (vertexPickInfo.isPicked(source) && !vertexPickInfo.isPicked(destination)) {
                return edge.toString();
            } else {
                return "";
            }
        }
    });
    renderContext.setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(COLOR_EDGE_LABEL) {
        @Override
        public <E> Component getEdgeLabelRendererComponent(JComponent vv, Object value, Font font,
                boolean isSelected, E edge) {
            Component component = super.getEdgeLabelRendererComponent(vv, value, font, isSelected, edge);
            component.setForeground(COLOR_EDGE_LABEL);
            return component;
        }

    });

    // start from VertexLabelAsShapeDemo

    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper> vlasr = new VertexLabelAsShapeRenderer<NodeWrapper, NodeWrapper>(
            renderContext);
    renderContext.setVertexShapeTransformer(vlasr);

    vis.setForeground(COLOR_NODE_TEXT);

    // customize the render context

    renderContext.setVertexLabelTransformer(new ToStringLabeller<NodeWrapper>());

    renderContext.setVertexLabelRenderer(new DefaultVertexLabelRenderer(COLOR_NODE_PICKED_TEXT) {
        @Override
        public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font,
                boolean isSelected, V vertexToRender) {
            Component component = super.getVertexLabelRendererComponent(vv, value, font, isSelected,
                    vertexToRender);
            if (component instanceof JLabel) {
                JLabel label = (JLabel) component;
                // add a little bit of padding around the text
                Border originalBorder = label.getBorder();
                label.setBorder(BorderFactory.createCompoundBorder(originalBorder,
                        BorderFactory.createEmptyBorder(3, 2, 4, 2)));
            }
            // now set the colour/font too
            if (vertexToRender instanceof NodeWrapper) {
                NodeWrapper vertex = (NodeWrapper) vertexToRender;
                if (vertexPickInfo.isPicked(vertex)) {
                    component.setForeground(COLOR_NODE_PICKED_TEXT);
                } else if (vertex.isHighlighted()) {
                    component.setForeground(COLOR_NODE_HIGHLIGHTED_TEXT);
                    component.setFont(font.deriveFont(Font.BOLD));
                } else if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    component.setForeground(COLOR_NODE_WITH_PICKED_NEIGHBOUR_TEXT);
                } else if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    component.setForeground(COLOR_NODE_ADJACENT_EDGE_PICKED_TEXT);
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    component.setForeground(COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_TEXT);
                } else {
                    component.setForeground(COLOR_NODE_TEXT);
                }
            }

            return component;
        }
    });

    // end from VertexLabelAsShapeDemo

    vis.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    vis.setVertexToolTipTransformer(new Transformer<NodeWrapper, String>() {
        @Override
        public String transform(NodeWrapper vertex) {
            return vertex.getToolTipText(model);
        }
    });

    // inspired by PluggableRendererDemo
    Transformer<NodeWrapper, Paint> vertexOutline = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return COLOR_NODE_PICKED_BORDER;
            } else if (vertex.isHighlighted()) {
                return COLOR_NODE_HIGHLIGHTED_BORDER;
            } else {
                if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    return COLOR_NODE_ADJACENT_EDGE_PICKED_BORDER;
                }
                if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BORDER;
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BORDER;
                }
                // will get here only if no neighbour is picked/highlighted
                return COLOR_NODE_BORDER;
            }
        }
    };
    renderContext.setVertexDrawPaintTransformer(vertexOutline);

    Transformer<NodeWrapper, Paint> vertexBackground = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return COLOR_NODE_PICKED_BG;
            } else if (vertex.isHighlighted()) {
                return COLOR_NODE_HIGHLIGHTED_BG;
            } else {
                if (GraphViewHelper.hasPickedAdjacentEdge(vertex, edgePickInfo, graph)) {
                    return COLOR_NODE_ADJACENT_EDGE_PICKED_BG;
                }
                if (GraphViewHelper.hasPickedNeighbour(vertex, vertexPickInfo, graph)) {
                    return COLOR_NODE_WITH_PICKED_NEIGHBOUR_BG;
                } else if (GraphViewHelper.hasHighlightedNeighbour(vertex, graph)) {
                    return COLOR_NODE_WITH_HIGHLIGHTED_NEIGHBOUR_BG;
                }
                return COLOR_NODE_BG;
            }
        }
    };
    renderContext.setVertexFillPaintTransformer(vertexBackground);

    Transformer<NodeWrapper, Stroke> vertexStroke = new Transformer<NodeWrapper, Stroke>() {
        @Override
        public Stroke transform(NodeWrapper vertex) {
            if (vertexPickInfo.isPicked(vertex)) {
                return STROKE_VERTEX_PICKED;
            } else if (vertex.isHighlighted()) {
                return STROKE_VERTEX_HIGHLIGHTED;
            }

            Collection<NodeWrapper> edges = graph.getInEdges(vertex);
            for (NodeWrapper edge : edges) {
                if (edgePickInfo.isPicked(edge)) {
                    return STROKE_VERTEX_INCOMING_EDGE_PICKED;
                }
            }
            edges = graph.getOutEdges(vertex);
            for (NodeWrapper edge : edges) {
                if (edgePickInfo.isPicked(edge)) {
                    return STROKE_VERTEX_OUTGOING_EDGE_PICKED;
                }
            }

            // we'll only get here if none of the cases above applies
            return STROKE_VERTEX_DEFAULT;
        }
    };
    renderContext.setVertexStrokeTransformer(vertexStroke);

    Transformer<NodeWrapper, Stroke> edgeStroke = new Transformer<NodeWrapper, Stroke>() {
        @Override
        public Stroke transform(NodeWrapper edge) {
            NodeWrapper edgeSource = graph.getSource(edge);
            if (edgePickInfo.isPicked(edge)) {
                return STROKE_EDGE_PICKED;
            } else if (vertexPickInfo.isPicked(edgeSource)) {
                return STROKE_EDGE_ADJACENT_NODE_PICKED;
            } else {
                return STROKE_EDGE_DEFAULT;
            }
        }
    };
    renderContext.setEdgeStrokeTransformer(edgeStroke);

    Transformer<NodeWrapper, Paint> edgeColor = new Transformer<NodeWrapper, Paint>() {
        @Override
        public Paint transform(NodeWrapper edge) {
            if (edgePickInfo.isPicked(edge)) {
                return COLOR_EDGE_PICKED;
            } else if (GraphViewHelper.hasPickedAdjacentVertex(edge, vertexPickInfo, graph)) {
                return COLOR_EDGE_ADJACENT_VERTEX_PICKED;
            } else if (edge.isHighlighted()) {
                return COLOR_EDGE_HIGHLIGHTED;
            } else if (GraphViewHelper.hasHighlightedAdjacentVertex(edge, graph)) {
                return COLOR_EDGE_ADJACENT_VERTEX_HIGHLIGHTED;
            } else {
                return COLOR_EDGE;
            }
        }
    };
    renderContext.setEdgeDrawPaintTransformer(edgeColor);
    // draw arrows in the same colour as edges
    renderContext.setArrowDrawPaintTransformer(edgeColor);
    renderContext.setArrowFillPaintTransformer(edgeColor);

    includePredicate = new IncludePredicate<Context<Graph<NodeWrapper, NodeWrapper>, NodeWrapper>>();
    renderContext.setEdgeIncludePredicate(includePredicate);
    renderContext.setVertexIncludePredicate(includePredicate);

    vis.setBackground(COLOR_BACKGROUND);

    mouse = new DoubleClickPickingModalGraphMouse<NodeWrapper, NodeWrapper>();
    mouse.add(new AbstractPopupGraphMousePlugin() {
        @Override
        protected void handlePopup(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                return;
            }
            GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport();
            if (pickSupport == null) {
                return;
            }

            NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY());
            if (node == null) {
                node = pickSupport.getEdge(layout, e.getX(), e.getY());
            }
            if (node == null) {
                return;
            }
            popup.setNodeWrapper(node);
            popup.show(vis, e.getX(), e.getY());
        }
    });
    mouse.setDoubleClickPickingPlugin(new DoubleClickPickingPlugin() {
        @Override
        void doubleClickOccurred(MouseEvent e) {
            GraphElementAccessor<NodeWrapper, NodeWrapper> pickSupport = vis.getPickSupport();
            if (pickSupport == null) {
                return;
            }

            NodeWrapper node = pickSupport.getVertex(layout, e.getX(), e.getY());
            if (node == null) {
                return;
            }
            fireNodeSelected(node);
        }
    });
    vis.setGraphMouse(mouse);

}