BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / query / ExpressionBuilder.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 import java.util.Stack;
11
12 /*package*/ class ExpressionBuilder {
13     private final Stack<Expression> _stack = new Stack<Expression>();
14     private LogicalExpression.OP _lastOp = null;
15
16     public ExpressionBuilder() {}
17
18     public ExpressionBuilder withAnd() {
19         _lastOp = LogicalExpression.OP.AND;
20         return this;
21     }
22
23     public ExpressionBuilder withOr() {
24         _lastOp = LogicalExpression.OP.OR;
25         return this;
26     }
27
28     public ExpressionBuilder withTerm(Expression exp) {
29         if (_lastOp != null) {
30             exp = new LogicalExpression(_lastOp, _stack.pop(), exp);
31             _lastOp = null;
32         }
33         _stack.push(exp);
34         return this;
35     }
36
37     public Expression build() {
38         return _stack.pop();
39     }
40
41 }