1 /*
2 * Copyright 2006-2010 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sourceforge.domian.specification;
17
18
19 import static java.lang.Boolean.TRUE;
20
21
22 /**
23 * Operator defining a comparison relation between two objects.
24 * It is a binary operator, always having two operands.
25 * When applied, it always represents a {@code boolean} expression.
26 *
27 * @author Eirik Torske
28 * @since 0.5
29 */
30 enum RelationalOperator {
31
32 EQUAL("="),
33 NOT_EQUAL("<>"),
34 LESS_THAN("<"),
35 LESS_THAN_OR_EQUAL("=<"),
36 GREATER_THAN(">"),
37 GREATER_THAN_OR_EQUAL(">="),
38 MUCH_LESS_THAN("<<"),
39 MUCH_GREATER_THAN(">>");
40
41
42 final static Boolean DO_INVERT = TRUE;
43 final static Boolean DO_NOT_INVERT = !DO_INVERT;
44
45
46 private String sqlCompliantSymbolRepresentation;
47
48 private RelationalOperator(final String sqlCompliantSymbolRepresentation) {
49 this.sqlCompliantSymbolRepresentation = sqlCompliantSymbolRepresentation;
50 }
51
52
53 /** @return the inverted binary relation of this enum */
54 RelationalOperator getInvertedBinaryRelation() {
55 switch (this) {
56 case EQUAL:
57 return NOT_EQUAL;
58
59 case NOT_EQUAL:
60 return EQUAL;
61
62 case LESS_THAN:
63 return GREATER_THAN_OR_EQUAL;
64
65 case LESS_THAN_OR_EQUAL:
66 return GREATER_THAN;
67
68 case GREATER_THAN:
69 return LESS_THAN_OR_EQUAL;
70
71 case GREATER_THAN_OR_EQUAL:
72 return LESS_THAN;
73
74 default:
75 throw new UnsupportedOperationException("Inverted binary relation " + this.name() + " is not defined");
76 }
77 }
78
79 @Override
80 public String toString() {
81 return this.sqlCompliantSymbolRepresentation;
82 }
83 }