2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.xpath.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.Objects;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.Nullable;
18 public class YangPathExpr implements YangExpr {
19 private static final class WithLocation extends YangPathExpr {
20 private static final long serialVersionUID = 1L;
22 private final YangLocationPath locationPath;
24 WithLocation(final YangExpr filterExpr, final YangLocationPath locationPath) {
26 this.locationPath = requireNonNull(locationPath);
30 public Optional<YangLocationPath> getLocationPath() {
31 return Optional.of(locationPath);
35 private static final long serialVersionUID = 1L;
37 private final YangExpr filterExpr;
39 YangPathExpr(final YangExpr filterExpr) {
40 this.filterExpr = requireNonNull(filterExpr);
43 public static YangPathExpr of(final YangExpr filterExpr) {
44 return new YangPathExpr(filterExpr);
47 public static YangPathExpr of(final YangExpr expr, final YangLocationPath locationPath) {
48 return new WithLocation(expr, locationPath);
51 public final YangExpr getFilterExpr() {
55 public Optional<YangLocationPath> getLocationPath() {
56 return Optional.empty();
60 public final int hashCode() {
61 return Objects.hash(filterExpr, getLocationPath());
65 public final boolean equals(final @Nullable Object obj) {
69 if (!(obj instanceof YangPathExpr)) {
72 final YangPathExpr other = (YangPathExpr) obj;
73 return filterExpr.equals(((YangPathExpr) obj).filterExpr) && getLocationPath().equals(other.getLocationPath());
77 public final String toString() {
78 // FIXME: this is not right
79 return "-(" + filterExpr + ")";