Merge "Move adsal into its own subdirectory."
[controller.git] / opendaylight / adsal / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / query / CompareExpression.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.northbound.commons.query;
9
10 /*package*/ class CompareExpression implements Expression {
11
12     public static enum OP { RE, EQ, NE, GT, GE, LT, LE };
13
14     private final OP _operation;
15     private final String _selector;
16     private final String _arg;
17
18     public CompareExpression(OP op, String selector, String arg) {
19         _operation = op;
20         _selector = selector;
21         _arg = unQuote(arg);
22     }
23
24
25     public OP getOperator() {
26         return _operation;
27     }
28
29     public String getSelector() {
30         return _selector;
31     }
32
33     public String getArgument() {
34         return _arg;
35     }
36
37     @Override
38     public boolean accept(Visitor visitor) throws QueryException {
39         return visitor.visit(this);
40     }
41
42     @Override
43     public String toString() {
44         return "[" + _selector + " " + _operation + " " + _arg + "]";
45     }
46
47     private static String unQuote(String s) {
48         if (s.startsWith("\"") && s.endsWith("\"")) {
49             s = s.substring(1, s.length()-1);
50         } else if (s.startsWith("\'") && s.endsWith("\'")) {
51             s = s.substring(1, s.length()-1);
52         }
53         return s;
54     }
55
56 }