Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | /* | |
11 | * (c) 2002 Danyel Fisher, Paul Dourish, | |
12 | * and the Regents of the University of California | |
13 | * | |
14 | * Created on Jul 2, 2003 | |
15 | * | |
16 | */ | |
17 | package edu.uci.ics.jung.graph.filters.impl; | |
18 | ||
19 | import edu.uci.ics.jung.graph.Vertex; | |
20 | import edu.uci.ics.jung.graph.decorators.StringLabeller; | |
21 | import edu.uci.ics.jung.graph.filters.EfficientFilter; | |
22 | import edu.uci.ics.jung.graph.filters.GeneralVertexAcceptFilter; | |
23 | ||
24 | /** | |
25 | * A small example filter that accepts vertices that are alphabetically | |
26 | * past the input value. | |
27 | * | |
28 | * @author danyelf | |
29 | */ | |
30 | public class AlphabeticVertexFilter extends GeneralVertexAcceptFilter implements EfficientFilter { | |
31 | ||
32 | public AlphabeticVertexFilter( | |
33 | String threshhold, | |
34 | StringLabeller sl, | |
35 | 9 | boolean acceptAboveThreshold) { |
36 | ||
37 | 9 | this.stringLabeller = sl; |
38 | 9 | this.threshhold = threshhold; |
39 | 9 | this.acceptThoseAboveThreshhold = acceptAboveThreshold; |
40 | ||
41 | 9 | } |
42 | ||
43 | private StringLabeller stringLabeller; | |
44 | private String threshhold; | |
45 | private boolean acceptThoseAboveThreshhold; | |
46 | ||
47 | /** | |
48 | * Passes the vertex if its StringLabeller value compares over | |
49 | * (or under) the threshold. | |
50 | */ | |
51 | public boolean acceptVertex(Vertex vert) { | |
52 | // String comp = GraphUtils.getLabel( stringLabeller, vert); | |
53 | 307 | String comp = stringLabeller.getLabel(vert); |
54 | 307 | if ((comp.compareTo(threshhold) > 0) && acceptThoseAboveThreshhold) |
55 | 142 | return true; |
56 | 165 | return false; |
57 | } | |
58 | ||
59 | /** | |
60 | * Returns a name for this: | |
61 | * <tt>AlphabeticFilter(>"TestString")</tt> | |
62 | */ | |
63 | public String getName() { | |
64 | 25 | String label = acceptThoseAboveThreshhold ? ">" : "<="; |
65 | 25 | return "Alphabetic filter(" + label + "\"" + threshhold + "\")"; |
66 | } | |
67 | ||
68 | /** | |
69 | * Returns the current direction of the comparison: | |
70 | * True if this accepts only strings above the | |
71 | * threshhold, otherwise, accepts only strings at or | |
72 | * below the threshhold. | |
73 | * | |
74 | * @return boolean | |
75 | */ | |
76 | public boolean isAcceptThoseAboveThreshhold() { | |
77 | 0 | return acceptThoseAboveThreshhold; |
78 | } | |
79 | ||
80 | /** | |
81 | * @return String the current comparison value | |
82 | */ | |
83 | public String getThreshhold() { | |
84 | 9 | return threshhold; |
85 | } | |
86 | ||
87 | /** | |
88 | * Sets the acceptThoseAboveThreshhold: if true, this accepts values over | |
89 | * the threshhold; if false, this accepts values up to and including the | |
90 | * threshhold, but not above it. | |
91 | * @param acceptThoseAboveThreshhold | |
92 | */ | |
93 | public void setAcceptThoseAboveThreshhold(boolean acceptThoseAboveThreshhold) { | |
94 | 0 | this.acceptThoseAboveThreshhold = acceptThoseAboveThreshhold; |
95 | 0 | } |
96 | ||
97 | /** | |
98 | * Sets the threshhold. | |
99 | * @param threshhold The threshhold to set | |
100 | */ | |
101 | public void setThreshhold(String threshhold) { | |
102 | 18 | this.threshhold = threshhold; |
103 | 18 | } |
104 | ||
105 | /** | |
106 | * Returns the String Labeller being used by this filter to check vertices with. | |
107 | * @return StringLabeller | |
108 | */ | |
109 | public StringLabeller getStringLabeller() { | |
110 | 0 | return stringLabeller; |
111 | } | |
112 | ||
113 | /** | |
114 | * Sets the stringLabeller. | |
115 | * @param stringLabeller The stringLabeller to set | |
116 | */ | |
117 | public void setStringLabeller(StringLabeller stringLabeller) { | |
118 | 0 | this.stringLabeller = stringLabeller; |
119 | 0 | } |
120 | ||
121 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |