01: package org.drools.base.evaluators;
02:
03: import java.io.Serializable;
04:
05: import org.drools.RuntimeDroolsException;
06:
07: public class Operator implements Serializable {
08:
09: private static final long serialVersionUID = 400L;
10:
11: public static final Operator EQUAL = new Operator("==");
12: public static final Operator NOT_EQUAL = new Operator("!=");
13: public static final Operator LESS = new Operator("<");
14: public static final Operator LESS_OR_EQUAL = new Operator("<=");
15: public static final Operator GREATER = new Operator(">");
16: public static final Operator GREATER_OR_EQUAL = new Operator(">=");
17: public static final Operator CONTAINS = new Operator("contains");
18: public static final Operator EXCLUDES = new Operator("excludes");
19: public static final Operator NOT_CONTAINS = new Operator(
20: "not contains");
21: public static final Operator MATCHES = new Operator("matches");
22: public static final Operator NOT_MATCHES = new Operator(
23: "not matches");
24: public static final Operator MEMBEROF = new Operator("memberOf");
25: public static final Operator NOTMEMBEROF = new Operator(
26: "not memberOf");
27:
28: private String operator;
29:
30: private Operator(final String operator) {
31: this .operator = operator;
32: }
33:
34: private Object readResolve() throws java.io.ObjectStreamException {
35: return determineOperator(this .operator);
36: }
37:
38: public static Operator determineOperator(final String string) {
39: if (string.equals("==")) {
40: return Operator.EQUAL;
41: } else if (string.equals("!=")) {
42: return Operator.NOT_EQUAL;
43: } else if (string.equals("<")) {
44: return Operator.LESS;
45: } else if (string.equals("<=")) {
46: return Operator.LESS_OR_EQUAL;
47: } else if (string.equals(">")) {
48: return Operator.GREATER;
49: } else if (string.equals(">=")) {
50: return Operator.GREATER_OR_EQUAL;
51: } else if (string.equals("contains")) {
52: return Operator.CONTAINS;
53: } else if (string.equals("not contains")) {
54: return Operator.NOT_CONTAINS;
55: } else if (string.equals("matches")) {
56: return Operator.MATCHES;
57: } else if (string.equals("not matches")) {
58: return Operator.NOT_MATCHES;
59: } else if (string.equals("excludes")) {
60: return Operator.EXCLUDES;
61: } else if (string.equals("memberOf")) {
62: return Operator.MEMBEROF;
63: } else if (string.equals("not memberOf")) {
64: return Operator.NOTMEMBEROF;
65: }
66: throw new RuntimeDroolsException(
67: "unable to determine operator for String [" + string
68: + "]");
69: }
70:
71: public String toString() {
72: return "Operator = '" + this .operator + "'";
73: }
74:
75: public String getOperatorString() {
76: return this .operator;
77: }
78:
79: public int hashCode() {
80: return this .operator.hashCode();
81: }
82:
83: public boolean equals(final Object object) {
84: if (object == this ) {
85: return true;
86: }
87:
88: return false;
89: }
90: }
|