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

LineHitsSource
1 /*
2  * Created on Mar 17, 2004
3  *
4 * Copyright (c) 2003, 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 edu.uci.ics.jung.graph.ArchetypeVertex;
15  
16  
17 /**
18  * A predicate that checks to see whether a vertex's user
19  * data repository contains
20  * the constructor-specified (key,datum) pair. This predicate
21  * may be used as a constraint.
22  */
23 public class UserDatumVertexPredicate extends VertexPredicate
24 {
25     public static final String message = "UserDatumVertexPredicate: ";
26     private Object datum;
27     private Object key;
28     
29     public UserDatumVertexPredicate(Object key, Object datum)
3024    {
3124        if (key == null)
320            throw new IllegalArgumentException("UserDatumVertexPredicate " +
33                     "key must be non-null");
3424        this.datum = datum;
3524        this.key = key;
3624    }
37         
38     /**
39      * Returns <code>true</code> if the datum stored by <code>v</code> with
40      * key value <code>key</code> (in the user data repository) is
41      * <code>datum</code>.
42      *
43      * @see edu.uci.ics.jung.utils.UserData
44      */
45     public boolean evaluateVertex(ArchetypeVertex v)
46     {
47652        Object value = v.getUserDatum(key);
48652        return ((datum == null && value == null) || datum.equals(value));
49     }
50  
51     public String toString()
52     {
531        return message + "(" + key + ", " + datum + ")";
54     }
55     
56     /**
57      * Tests equality based on underlying objects
58      */
59     public boolean equals( Object o ) {
6016        if (! (o instanceof UserDatumVertexPredicate))
6113            return false;
623        UserDatumVertexPredicate udvp = (UserDatumVertexPredicate) o;
633        return ( udvp.datum.equals( datum ) && udvp.key.equals(key));
64     }
65     
66     public int hashCode() {
67201        return datum.hashCode() + key.hashCode();
68     }
69     
70     /**
71      * Returns the user data key which partially defines this predicate.
72      */
73     public Object getKey()
74     {
7522        return key;
76     }
77     
78     /**
79      * Returns the user datum which partially defines this predicate.
80      */
81     public Object getDatum()
82     {
8322        return datum;
84     }
85 }

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.