1 21 22 27 28 package net.walend.somnifugi.sql92; 29 30 36 class SelectorToken 37 { 38 39 static final SelectorToken trueToken = 42 new SelectorToken(Selector.TRUE, "true"); 43 static final SelectorToken falseToken = 44 new SelectorToken(Selector.FALSE, "false"); 45 static final SelectorToken unknownToken = 46 new SelectorToken(Selector.UNKNOWN, "unknown"); 47 48 static final SelectorToken equalsToken = 52 new SelectorToken(Selector.EQUALS, "="); 53 static final SelectorToken notEqualsToken = 54 new SelectorToken(Selector.NOT_EQUALS, "<>"); 55 static final SelectorToken gtToken = 56 new SelectorToken(Selector.GT, ">"); 57 static final SelectorToken gteToken = 58 new SelectorToken(Selector.GTE, ">="); 59 static final SelectorToken ltToken = 60 new SelectorToken(Selector.LT, "<"); 61 static final SelectorToken lteToken = 62 new SelectorToken(Selector.LTE, "<="); 63 64 static final SelectorToken andMarker = 66 new SelectorToken(Selector.AND_MARKER, "&"); 67 static final SelectorToken orMarker = 68 new SelectorToken(Selector.OR_MARKER, "|"); 69 70 int token = Selector.UNKNOWN; 72 73 Object value = null; 79 80 public static synchronized SelectorToken getInstance(int token, Object value) 81 { 82 83 switch (token) 84 { 85 86 case Selector.TRUE: 87 return trueToken; 88 case Selector.FALSE: 89 return falseToken; 90 case Selector.UNKNOWN: 91 return unknownToken; 92 case Selector.EQUALS: 93 return equalsToken; 94 case Selector.GTE: 95 return gteToken; 96 case Selector.LTE: 97 return lteToken; 98 case Selector.GT: 99 return gtToken; 100 case Selector.LT: 101 return ltToken; 102 case Selector.NOT_EQUALS: 103 return notEqualsToken; 104 case Selector.AND_MARKER: 105 return andMarker; 106 case Selector.OR_MARKER: 107 return orMarker; 108 default: 109 return new SelectorToken(token, value); 110 } 111 } 112 113 public static SelectorToken getInstance(int token) 114 { 115 return getInstance(token, null); 116 } 117 118 private SelectorToken(int token) 119 { 120 this.token = token; 121 } 122 123 private SelectorToken(int token, Object value) 124 { 125 this.token = token; 126 this.value = value; 127 } 128 129 public int getToken() 130 { 131 return token; 132 } 133 134 public Object getValue() 135 { 136 return value; 137 } 138 139 public boolean equals(Object o) 140 { 141 142 if (this == o) return true; 143 144 if (!(o instanceof SelectorToken)) 145 { 146 return false; 147 } 148 149 SelectorToken obj = (SelectorToken)o; 150 151 if (obj.token != token) 152 { 153 return false; 154 } 155 156 return (value == null ? obj.value == null : value.equals(obj.value)); 157 } 158 159 public int hashCode() 160 { 161 162 if (value == null) 163 { 164 return token; 165 } 166 else 167 { 168 return value.hashCode() * token; 169 } 170 } 171 172 public String toString() 173 { 174 return ("[" + token + "," + 175 (value == null ? "null" : value.toString()) + "]"); 176 } 177 } 178 | Popular Tags |