KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > util > ValidEdgePredicate


1 package prefuse.data.util;
2
3 import prefuse.data.Graph;
4 import prefuse.data.Node;
5 import prefuse.data.Tuple;
6 import prefuse.data.expression.AbstractPredicate;
7
8 /**
9  * 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.getInt(m_g.getEdgeSourceField()));
38         Node t = m_g.getNodeFromKey(tpl.getInt(m_g.getEdgeTargetField()));
39         return ( s != null && t != null );
40     }
41     
42 } // end of class ValidEdgePredicate
43
Popular Tags