Seal YangExpr hierarchy
[yangtools.git] / xpath / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / YangBinaryExpr.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o.  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.yangtools.yang.xpath.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.Objects;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * A binary expression formed of a {@link #getLeftExpr()}, an {@link #getOperator()} and a {@link #getRightExpr()}.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 public abstract sealed class YangBinaryExpr implements YangExpr permits YangBinaryOperator.Expr {
23     private static final long serialVersionUID = 1L;
24
25     private final YangExpr leftExpr;
26     private final YangExpr rightExpr;
27
28     YangBinaryExpr(final YangExpr leftExpr, final YangExpr rightExpr) {
29         this.leftExpr = requireNonNull(leftExpr);
30         this.rightExpr = requireNonNull(rightExpr);
31     }
32
33     public final YangExpr getLeftExpr() {
34         return leftExpr;
35     }
36
37     public final YangExpr getRightExpr() {
38         return rightExpr;
39     }
40
41     public abstract YangBinaryOperator getOperator();
42
43     @Override
44     public final int hashCode() {
45         return Objects.hash(leftExpr, rightExpr, getOperator());
46     }
47
48     @Override
49     public final boolean equals(final @Nullable Object obj) {
50         if (this == obj) {
51             return true;
52         }
53         if (!(obj instanceof YangBinaryExpr)) {
54             return false;
55         }
56         final YangBinaryExpr other = (YangBinaryExpr) obj;
57         return getOperator().equals(other.getOperator()) && leftExpr.equals(other.leftExpr)
58                 && rightExpr.equals(other.rightExpr);
59     }
60
61     @Override
62     public final String toString() {
63         return leftExpr.toString() + " " + getOperator() + " " + rightExpr;
64     }
65 }