01: package org.swingml.tablebrowser.ext;
02:
03: import java.util.*;
04:
05: /**
06: * @author dpitt
07: */
08: public class Pattern {
09:
10: private String key = null;
11: List list = new ArrayList();
12:
13: public void add(String value) {
14: if (list.indexOf(value) < 0) {
15: list.add(value);
16: }
17: }
18:
19: public boolean equals(String value) {
20: for (int i = 0; i < list.size(); i++) {
21: String ele = (String) list.get(i);
22: if (ele.equalsIgnoreCase(value)) {
23: return true;
24: }
25: }
26:
27: return false;
28: }
29:
30: /**
31: * Returns the key.
32: * @return String
33: */
34: public String getKey() {
35: return key;
36: }
37:
38: public boolean isEmpty() {
39: return list.isEmpty();
40: }
41:
42: public boolean matches(String value) {
43: Iterator itr = list.iterator();
44: while (itr.hasNext()) {
45: String pattern = (String) itr.next();
46: if (value.toLowerCase().indexOf(pattern.toLowerCase()) == 0) {
47: return true;
48: }
49:
50: }
51:
52: return false;
53: }
54:
55: public void remove(String value) {
56: list.remove(value);
57: }
58:
59: /**
60: * Sets the key.
61: * @param key The key to set
62: */
63: public void setKey(String key) {
64: this.key = key;
65: }
66:
67: }
|