Line | Hits | Source |
---|---|---|
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) | |
30 | 24 | { |
31 | 24 | if (key == null) |
32 | 0 | throw new IllegalArgumentException("UserDatumVertexPredicate " + |
33 | "key must be non-null"); | |
34 | 24 | this.datum = datum; |
35 | 24 | this.key = key; |
36 | 24 | } |
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 | { | |
47 | 652 | Object value = v.getUserDatum(key); |
48 | 652 | return ((datum == null && value == null) || datum.equals(value)); |
49 | } | |
50 | ||
51 | public String toString() | |
52 | { | |
53 | 1 | return message + "(" + key + ", " + datum + ")"; |
54 | } | |
55 | ||
56 | /** | |
57 | * Tests equality based on underlying objects | |
58 | */ | |
59 | public boolean equals( Object o ) { | |
60 | 16 | if (! (o instanceof UserDatumVertexPredicate)) |
61 | 13 | return false; |
62 | 3 | UserDatumVertexPredicate udvp = (UserDatumVertexPredicate) o; |
63 | 3 | return ( udvp.datum.equals( datum ) && udvp.key.equals(key)); |
64 | } | |
65 | ||
66 | public int hashCode() { | |
67 | 201 | 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 | { | |
75 | 22 | return key; |
76 | } | |
77 | ||
78 | /** | |
79 | * Returns the user datum which partially defines this predicate. | |
80 | */ | |
81 | public Object getDatum() | |
82 | { | |
83 | 22 | return datum; |
84 | } | |
85 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |