View Javadoc

1   /*
2    * Copyright (c) 2010.  The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.expreval.expr;
22  
23  import org.apache.hadoop.hbase.filter.CompareFilter;
24  import org.apache.hadoop.hbase.hbql.client.HBqlException;
25  
26  public enum Operator {
27  
28      PLUS("+", null, null),
29      MINUS("-", null, null),
30      MULT("*", null, null),
31      DIV("/", null, null),
32      MOD("%", null, null),
33      NEGATIVE("-", null, null),
34  
35      EQ("==",
36         CompareFilter.CompareOp.EQUAL,
37         CompareFilter.CompareOp.EQUAL),
38      GT("<",
39         CompareFilter.CompareOp.GREATER,
40         CompareFilter.CompareOp.LESS_OR_EQUAL),
41      GTEQ(">=",
42           CompareFilter.CompareOp.GREATER_OR_EQUAL,
43           CompareFilter.CompareOp.LESS),
44      LT("<",
45         CompareFilter.CompareOp.LESS,
46         CompareFilter.CompareOp.GREATER_OR_EQUAL),
47      LTEQ("<=",
48           CompareFilter.CompareOp.LESS_OR_EQUAL,
49           CompareFilter.CompareOp.GREATER),
50      NOTEQ("!=",
51            CompareFilter.CompareOp.NOT_EQUAL,
52            CompareFilter.CompareOp.NOT_EQUAL),
53  
54      AND("AND", null, null),
55      OR("OR", null, null);
56  
57      final String opStr;
58      final CompareFilter.CompareOp compareOpLeft;
59      final CompareFilter.CompareOp compareOpRight;
60  
61      Operator(final String opStr,
62               final CompareFilter.CompareOp compareOpLeft,
63               final CompareFilter.CompareOp compareOpRight) {
64          this.opStr = opStr;
65          this.compareOpLeft = compareOpLeft;
66          this.compareOpRight = compareOpRight;
67      }
68  
69      public String toString() {
70          return this.opStr;
71      }
72  
73      public CompareFilter.CompareOp getCompareOpLeft() throws HBqlException {
74          if (this.compareOpRight == null)
75              throw new HBqlException("Invalid operator: " + this);
76          return this.compareOpLeft;
77      }
78  
79      public CompareFilter.CompareOp getCompareOpRight() throws HBqlException {
80          if (this.compareOpRight == null)
81              throw new HBqlException("Invalid operator: " + this);
82          return this.compareOpRight;
83      }
84  }