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;
16 * An XPath literal expression.
19 * Note that a literal may be required to hold a value of {@code instance-identifier} or {@code identityref} type,
20 * when the corresponding {@link YangXPathExpression} was parsed from reference String specification defined in RFC7950.
21 * When such conversion is required, it should be performed through
22 * {@link YangXPathExpression#interpretAsQName(YangLiteralExpr)} or
23 * {@link YangXPathExpression#interpretAsInstanceIdentifier(YangLiteralExpr)}.
26 * A more type-safe alternative is {@link YangQNameExpr}, which should be preferred and used whenever possible.
28 * @author Robert Varga
31 public class YangLiteralExpr implements YangExpr {
32 private static final class Empty extends YangLiteralExpr {
33 private static final long serialVersionUID = 1L;
39 @SuppressWarnings("static-method")
40 Object readResolve() {
45 private static final long serialVersionUID = 1L;
46 private static final YangLiteralExpr EMPTY = new Empty();
48 private final String literal;
50 protected YangLiteralExpr(final String literal) {
51 this.literal = requireNonNull(literal);
54 public static final YangLiteralExpr empty() {
58 public static final YangLiteralExpr of(final String literal) {
59 return literal.isEmpty() ? EMPTY : new YangLiteralExpr(literal);
62 public final String getLiteral() {
67 public final int hashCode() {
68 return literal.hashCode();
72 public final boolean equals(final @Nullable Object obj) {
73 return this == obj || obj instanceof YangLiteralExpr && literal.equals(((YangLiteralExpr) obj).literal);
77 public final String toString() {