01: package prefuse.data.util;
02:
03: import prefuse.data.Graph;
04: import prefuse.data.Node;
05: import prefuse.data.Tuple;
06: import prefuse.data.expression.AbstractPredicate;
07:
08: /**
09: * Filtering predicate over a potential edge table that indicates which
10: * edges are valid edges according to a backing node table. Useful for
11: * creating a pool of edges for which not all node have been created, and
12: * then filtering out the valid edges using the node pool.
13: *
14: * @author <a href="http://jheer.org">jeffrey heer</a>
15: */
16: public class ValidEdgePredicate extends AbstractPredicate {
17:
18: private Graph m_g;
19:
20: /**
21: * Creates a new ValidEdgePredicate.
22: * @param g the backing graph, the node table of this graph will be used
23: * to check for valid edges.
24: */
25: public ValidEdgePredicate(Graph g) {
26: m_g = g;
27: }
28:
29: /**
30: * Indicates if the given tuple can be used as a valid edge for
31: * the nodes of the backing graph.
32: * @param tpl a data tuple from a potential edge table
33: * @return true if the tuple contents allow it to serve as a valid
34: * edge of between nodes in the backing graph
35: */
36: public boolean getBoolean(Tuple tpl) {
37: Node s = m_g.getNodeFromKey(tpl
38: .getInt(m_g.getEdgeSourceField()));
39: Node t = m_g.getNodeFromKey(tpl
40: .getInt(m_g.getEdgeTargetField()));
41: return (s != null && t != null);
42: }
43:
44: } // end of class ValidEdgePredicate
|