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 org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.UnresolvedQName;
18 * An XPath QName expression. This is an exact QName, which cannot be converted to a string literal compatible with
19 * XPath string representation, because it does not define a prefix/namespace mapping. It represents a strong binding
20 * to a particular namespace at a particular revision.
23 * Parsers and users of this package are encouraged to use this class in place of {@link YangLiteralExpr} where
24 * appropriate, as it retains type safety and more semantic context.
26 * @author Robert Varga
29 public abstract sealed class YangQNameExpr implements YangExpr, QNameReferent {
30 public static final class Resolved extends YangQNameExpr implements ResolvedQNameReferent {
31 private static final long serialVersionUID = 1L;
33 private final QName qname;
35 Resolved(final QName qname) {
36 this.qname = requireNonNull(qname);
40 public QName getQName() {
45 public int hashCode() {
46 return qname.hashCode();
50 public boolean equals(final @Nullable Object obj) {
51 return this == obj || obj instanceof Resolved && qname.equals(((Resolved) obj).qname);
55 public String toString() {
56 return qname.toString();
60 public static final class Unresolved extends YangQNameExpr implements UnresolvedQNameReferent {
61 private static final long serialVersionUID = 1L;
63 private final UnresolvedQName qname;
65 Unresolved(final UnresolvedQName qname) {
66 this.qname = requireNonNull(qname);
70 public UnresolvedQName getQName() {
75 public int hashCode() {
76 return qname.hashCode();
80 public boolean equals(final @Nullable Object obj) {
81 return this == obj || obj instanceof Unresolved && qname.equals(((Unresolved) obj).qname);
85 public String toString() {
86 return qname.toString();
90 private static final long serialVersionUID = 1L;
92 public static Unresolved of(final UnresolvedQName qname) {
93 return new Unresolved(qname);
96 public static Resolved of(final QName qname) {
97 return new Resolved(qname);