01: package org.geotools.filter.function;
02:
03: import java.util.Set;
04:
05: public final class ExplicitClassifier extends Classifier {
06:
07: Set[] values = null; //the contents of each bin (set of objects)
08:
09: public ExplicitClassifier(Set[] values) {
10: this .values = values;
11: //initialize titles
12: this .titles = new String[values.length];
13: for (int i = 0; i < titles.length; i++) {
14: Object[] set = values[i].toArray();
15: if (set.length > 0) {
16: StringBuffer title = new StringBuffer(
17: set[0] == null ? "null" : set[0].toString());
18: for (int j = 1; j < set.length; j++) {
19: title.append(", ");
20: title.append(set[j] == null ? "null" : set[j]
21: .toString());
22: }
23: titles[i] = title.toString();
24: } else {
25: titles[i] = "";
26: }
27: }
28: }
29:
30: public int getSize() {
31: return values.length;
32: }
33:
34: /**
35: * Returns all the unique values for a particular slot.
36: *
37: * @param index
38: * @return all applicable values for a slot
39: */
40: public Set getValues(int index) {
41: return values[index];
42: }
43:
44: public int classify(Object value) {
45: for (int i = 0; i < values.length; i++) {
46: if (values[i].contains(value)) {
47: return i;
48: }
49: }
50: return -1;
51: }
52:
53: }
|