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;
16 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Relative;
19 public sealed class YangPathExpr implements YangExpr {
20 private static final class WithLocation extends YangPathExpr {
21 private static final long serialVersionUID = 1L;
23 private final Relative locationPath;
25 WithLocation(final YangExpr filterExpr, final Relative locationPath) {
27 this.locationPath = requireNonNull(locationPath);
31 public Optional<Relative> getLocationPath() {
32 return Optional.of(locationPath);
36 private static final long serialVersionUID = 1L;
38 private final YangExpr filterExpr;
40 private YangPathExpr(final YangExpr filterExpr) {
41 this.filterExpr = requireNonNull(filterExpr);
44 public static YangPathExpr of(final YangExpr filterExpr) {
45 return new YangPathExpr(filterExpr);
48 public static YangPathExpr of(final YangExpr expr, final Relative locationPath) {
49 return new WithLocation(expr, locationPath);
52 public final YangExpr getFilterExpr() {
56 public Optional<Relative> getLocationPath() {
57 return Optional.empty();
61 public final int hashCode() {
62 return Objects.hash(filterExpr, getLocationPath());
66 public final boolean equals(final @Nullable Object obj) {
67 return this == obj || obj instanceof YangPathExpr other && filterExpr.equals(other.filterExpr)
68 && getLocationPath().equals(other.getLocationPath());
72 public final String toString() {
73 // FIXME: this is not right
74 return "-(" + filterExpr + ")";