import org.opendaylight.yangtools.yang.common.QNameModule;
@Beta
-public class YangLocationPath implements YangExpr {
+public abstract class YangLocationPath implements YangExpr {
public abstract static class Step implements Serializable, YangPredicateAware {
private static final long serialVersionUID = 1L;
}
}
+ public static final class Relative extends YangLocationPath {
+ private static final long serialVersionUID = 1L;
+
+ Relative(final ImmutableList<Step> steps) {
+ super(steps);
+ }
+
+ @Override
+ public boolean isAbsolute() {
+ return false;
+ }
+ }
+
private static final long serialVersionUID = 1L;
- private static final YangLocationPath ROOT = new Absolute(ImmutableList.of());
- private static final YangLocationPath SELF = new YangLocationPath(ImmutableList.of());
+ private static final Absolute ROOT = new Absolute(ImmutableList.of());
+ private static final Relative SELF = new Relative(ImmutableList.of());
private final ImmutableList<Step> steps;
this.steps = requireNonNull(steps);
}
- public static final YangLocationPath of(final boolean absolute) {
- return absolute ? ROOT : SELF;
+ public static final Absolute absolute(final Step... steps) {
+ return absolute(Arrays.asList(steps));
}
- public static final YangLocationPath of(final boolean absolute, final Step... steps) {
- return of(absolute, Arrays.asList(steps));
+ public static final Absolute absolute(final Collection<Step> steps) {
+ return steps.isEmpty() ? ROOT : new Absolute(ImmutableList.copyOf(steps));
}
- public static final YangLocationPath of(final boolean absolute, final Collection<Step> steps) {
- if (steps.isEmpty()) {
- return of(absolute);
- }
+ public static final Relative relative(final Step... steps) {
+ return relative(Arrays.asList(steps));
+ }
- final ImmutableList<Step> copy = ImmutableList.copyOf(steps);
- return absolute ? new Absolute(copy) : new YangLocationPath(copy);
+ public static final Relative relative(final Collection<Step> steps) {
+ return steps.isEmpty() ? SELF : new Relative(ImmutableList.copyOf(steps));
}
/**
*
* @return Empty absolute {@link YangLocationPath}
*/
- public static final YangLocationPath root() {
+ public static final Absolute root() {
return ROOT;
}
*
* @return Empty relative {@link YangLocationPath}
*/
- public static YangLocationPath self() {
+ public static final Relative self() {
return SELF;
}
- public boolean isAbsolute() {
- return false;
- }
-
public final ImmutableList<Step> getSteps() {
return steps;
}
+ public abstract boolean isAbsolute();
+
@Override
public final int hashCode() {
return Boolean.hashCode(isAbsolute()) * 31 + steps.hashCode();
}
final Object readSolve() {
- return steps.isEmpty() ? of(isAbsolute()) : this;
+ return steps.isEmpty() ? isAbsolute() ? ROOT : SELF : this;
}
}
import java.util.Objects;
import java.util.Optional;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Relative;
@Beta
public class YangPathExpr implements YangExpr {
private static final class WithLocation extends YangPathExpr {
private static final long serialVersionUID = 1L;
- private final YangLocationPath locationPath;
+ private final Relative locationPath;
- WithLocation(final YangExpr filterExpr, final YangLocationPath locationPath) {
+ WithLocation(final YangExpr filterExpr, final Relative locationPath) {
super(filterExpr);
this.locationPath = requireNonNull(locationPath);
}
@Override
- public Optional<YangLocationPath> getLocationPath() {
+ public Optional<Relative> getLocationPath() {
return Optional.of(locationPath);
}
}
return new YangPathExpr(filterExpr);
}
- public static YangPathExpr of(final YangExpr expr, final YangLocationPath locationPath) {
+ public static YangPathExpr of(final YangExpr expr, final Relative locationPath) {
return new WithLocation(expr, locationPath);
}
return filterExpr;
}
- public Optional<YangLocationPath> getLocationPath() {
+ public Optional<Relative> getLocationPath() {
return Optional.empty();
}
verifyChildCount(expr, 1);
final ParseTree first = expr.getChild(0);
if (first instanceof RelativeLocationPathContext) {
- return parseRelativeLocationPath((RelativeLocationPathContext) first);
+ return YangLocationPath.relative(parseLocationPathSteps((RelativeLocationPathContext) first));
}
final AbsoluteLocationPathNorootContext abs = verifyTree(AbsoluteLocationPathNorootContext.class, first);
final Deque<Step> steps = parseLocationPathSteps(getChild(abs, RelativeLocationPathContext.class, 1));
parseStepShorthand(abs.getChild(0)).ifPresent(steps::addFirst);
- return YangLocationPath.of(true, steps);
+ return YangLocationPath.absolute(steps);
}
private YangExpr parseMultiplicative(final MultiplicativeExprContext expr) {
verifyChildCount(expr, 3);
final Deque<Step> steps = parseLocationPathSteps(getChild(expr, RelativeLocationPathContext.class, 2));
parseStepShorthand(expr.getChild(1)).ifPresent(steps::addFirst);
- return YangPathExpr.of(filter, YangLocationPath.of(false, steps));
+ return YangPathExpr.of(filter, YangLocationPath.relative(steps));
}
private YangExpr parsePredicate(final PredicateContext expr) {
return steps;
}
- private YangLocationPath parseRelativeLocationPath(final RelativeLocationPathContext expr) {
- return YangLocationPath.of(false, parseLocationPathSteps(expr));
- }
-
private YangExpr parseTerminal(final TerminalNode term) {
final String text = term.getText();
switch (term.getSymbol().getType()) {
import org.opendaylight.yangtools.yang.xpath.api.YangExpr;
import org.opendaylight.yangtools.yang.xpath.api.YangLiteralExpr;
import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
+import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Absolute;
import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step;
import org.opendaylight.yangtools.yang.xpath.api.YangQNameExpr;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
this.mathSupport = mathMode.getSupport();
}
- YangLocationPath interpretAsInstanceIdentifier(final YangLiteralExpr expr) throws XPathExpressionException {
+ Absolute interpretAsInstanceIdentifier(final YangLiteralExpr expr) throws XPathExpressionException {
final xpathLexer lexer = new xpathLexer(CharStreams.fromString(expr.getLiteral()));
final instanceIdentifierParser parser = new instanceIdentifierParser(new CommonTokenStream(lexer));
final CapturingErrorListener listener = new CapturingErrorListener();
steps.add(parsePathArgument(getChild(id, PathArgumentContext.class, i)));
}
- return YangLocationPath.of(true, steps);
+ return YangLocationPath.absolute(steps);
}
private Step parsePathArgument(final PathArgumentContext expr) {