| Line | Hits | Source |
|---|---|---|
| 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; | |
| 38 | 3 | private static String message = "KPartiteEdgePredicate"; |
| 39 | ||
| 40 | public KPartiteEdgePredicate(Collection vertex_partitions) | |
| 41 | 18 | { |
| 42 | // used to make sure that each vertex satisfies only one predicate | |
| 43 | 18 | mutex = OnePredicate.getInstance(vertex_partitions); |
| 44 | 18 | this.vertex_partitions = vertex_partitions; |
| 45 | 18 | } |
| 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 | { | |
| 52 | 51 | Edge e = (Edge)edge; |
| 53 | 51 | Pair endpoints = e.getEndpoints(); |
| 54 | 51 | Vertex v1 = (Vertex)endpoints.getFirst(); |
| 55 | 51 | Vertex v2 = (Vertex)endpoints.getSecond(); |
| 56 | 51 | Predicate p1 = getSatisfyingPredicate(v1); |
| 57 | 51 | Predicate p2 = getSatisfyingPredicate(v2); |
| 58 | ||
| 59 | 51 | return (mutex.evaluate(v1) && mutex.evaluate(v2) && |
| 60 | p1 != null && p2 != null && (p1 != p2)); | |
| 61 | } | |
| 62 | ||
| 63 | public String toString() | |
| 64 | { | |
| 65 | 4 | return message; |
| 66 | } | |
| 67 | ||
| 68 | public boolean equals(Object o) | |
| 69 | { | |
| 70 | 21 | if (! (o instanceof KPartiteEdgePredicate)) |
| 71 | 21 | return false; |
| 72 | 0 | return ((KPartiteEdgePredicate)o).vertex_partitions.equals(vertex_partitions); |
| 73 | } | |
| 74 | ||
| 75 | public int hashCode() | |
| 76 | { | |
| 77 | 0 | return vertex_partitions.hashCode(); |
| 78 | } | |
| 79 | ||
| 80 | private Predicate getSatisfyingPredicate(Vertex v) | |
| 81 | { | |
| 82 | 102 | for (Iterator p_iter = vertex_partitions.iterator(); p_iter.hasNext(); ) |
| 83 | { | |
| 84 | 153 | Predicate p = (Predicate)p_iter.next(); |
| 85 | 153 | if (p.evaluate(v)) |
| 86 | 102 | return p; |
| 87 | } | |
| 88 | 0 | return null; |
| 89 | } | |
| 90 | ||
| 91 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |