Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / PathExpressionImpl.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
15
16 /**
17  * A simple XPathExpression implementation.
18  *
19  * @deprecated This is a transitional class to transition from {@link RevisionAwareXPathImpl}. Users are advised to
20  *             supply their own implementation of PathExpression.
21  */
22 @Deprecated
23 @NonNullByDefault
24 public final class PathExpressionImpl extends AbstractPathExpression {
25     private final @Nullable YangLocationPath location;
26     private final boolean absolute;
27
28     @SuppressFBWarnings(value = "NP_STORE_INTO_NONNULL_FIELD", justification = "Non-grok on SpotBugs part")
29     public PathExpressionImpl(final String xpath, final boolean absolute) {
30         super(xpath);
31         this.absolute = absolute;
32         this.location = null;
33     }
34
35     public PathExpressionImpl(final String xpath, final YangLocationPath location) {
36         super(xpath);
37         this.absolute = location.isAbsolute();
38         this.location = location;
39     }
40
41     @Override
42     public boolean isAbsolute() {
43         return absolute;
44     }
45
46     @Override
47     public YangLocationPath getLocation() {
48         final YangLocationPath loc = location;
49         if (loc == null) {
50             throw new UnsupportedOperationException("Location has not been provided");
51         }
52         return loc;
53     }
54
55     @Override
56     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
57         return super.addToStringAttributes(helper.add("absolute", absolute).add("location", location));
58     }
59 }