Coverage details for edu.uci.ics.jung.graph.predicates.KPartiteEdgePredicate

LineHitsSource
1 /*
2  * Created on Mar 29, 2004
3  *
4  * Copyright (c) 2004, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.graph.predicates;
13  
14 import java.util.Collection;
15 import java.util.Iterator;
16  
17 import org.apache.commons.collections.Predicate;
18 import org.apache.commons.collections.functors.OnePredicate;
19  
20 import edu.uci.ics.jung.graph.ArchetypeEdge;
21 import edu.uci.ics.jung.graph.Edge;
22 import edu.uci.ics.jung.graph.Vertex;
23 import edu.uci.ics.jung.utils.Pair;
24  
25  
26 /**
27  * An edge predicate that passes <code>Edge</code>s whose endpoints
28  * satisfy distinct elements of the Predicate collection passed in as
29  * a parameter to the constructor. May be used as an edge constraint.
30  *
31  * @author Joshua O'Madadhain
32  *
33  */
34 public class KPartiteEdgePredicate extends EdgePredicate
35 {
36     private Collection vertex_partitions;
37     private Predicate mutex;
383    private static String message = "KPartiteEdgePredicate";
39     
40     public KPartiteEdgePredicate(Collection vertex_partitions)
4118    {
42         // used to make sure that each vertex satisfies only one predicate
4318            mutex = OnePredicate.getInstance(vertex_partitions);
4418        this.vertex_partitions = vertex_partitions;
4518    }
46     
47     /**
48      * @see edu.uci.ics.jung.graph.predicates.EdgePredicate#evaluateEdge(edu.uci.ics.jung.graph.ArchetypeEdge)
49      */
50     public boolean evaluateEdge(ArchetypeEdge edge)
51     {
5251        Edge e = (Edge)edge;
5351        Pair endpoints = e.getEndpoints();
5451        Vertex v1 = (Vertex)endpoints.getFirst();
5551        Vertex v2 = (Vertex)endpoints.getSecond();
5651        Predicate p1 = getSatisfyingPredicate(v1);
5751        Predicate p2 = getSatisfyingPredicate(v2);
58         
5951        return (mutex.evaluate(v1) && mutex.evaluate(v2) &&
60                 p1 != null && p2 != null && (p1 != p2));
61     }
62     
63     public String toString()
64     {
654        return message;
66     }
67  
68     public boolean equals(Object o)
69     {
7021        if (! (o instanceof KPartiteEdgePredicate))
7121            return false;
720        return ((KPartiteEdgePredicate)o).vertex_partitions.equals(vertex_partitions);
73     }
74     
75     public int hashCode()
76     {
770        return vertex_partitions.hashCode();
78     }
79     
80     private Predicate getSatisfyingPredicate(Vertex v)
81     {
82102        for (Iterator p_iter = vertex_partitions.iterator(); p_iter.hasNext(); )
83         {
84153            Predicate p = (Predicate)p_iter.next();
85153            if (p.evaluate(v))
86102                return p;
87         }
880        return null;
89     }
90     
91 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.