+ /**
+ * Abstract base class for expressing steps of a PathExpression.
+ */
+ abstract class Steps {
+ Steps() {
+ // Prevent external subclassing
+ }
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(@Nullable Object obj);
+
+ @Override
+ public final String toString() {
+ return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
+ }
+
+ abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
+ }
+
+ /**
+ * Steps of a PathExpression which is a LocationPath, corresponding to RFC7950 base specification.
+ */
+ final class LocationPathSteps extends Steps {
+ private final YangLocationPath locationPath;
+
+ public LocationPathSteps(final YangLocationPath locationPath) {
+ this.locationPath = requireNonNull(locationPath);
+ }
+
+ public YangLocationPath getLocationPath() {
+ return locationPath;
+ }
+
+ @Override
+ public int hashCode() {
+ return locationPath.hashCode();
+ }
+
+ @Override
+ public boolean equals(final @Nullable Object obj) {
+ return this == obj
+ || obj instanceof LocationPathSteps && locationPath.equals(((LocationPathSteps) obj).locationPath);
+ }
+
+ @Override
+ ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return helper.add("locationPath", locationPath);
+ }
+ }
+
+ /**
+ * Steps of a PathExpression which is a combination of {@code deref()} function call and a relative path,
+ * corresponding to Errata 5617.
+ */
+ final class DerefSteps extends Steps {
+ private final Relative derefArgument;
+ private final Relative relativePath;
+
+ public DerefSteps(final Relative derefArgument, final Relative relativePath) {
+ this.derefArgument = requireNonNull(derefArgument);
+ this.relativePath = requireNonNull(relativePath);
+ }
+
+ public Relative getDerefArgument() {
+ return derefArgument;
+ }
+
+ public Relative getRelativePath() {
+ return relativePath;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * derefArgument.hashCode() + relativePath.hashCode();
+ }
+
+ @Override
+ public boolean equals(@Nullable final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof DerefSteps)) {
+ return false;
+ }
+ final DerefSteps other = (DerefSteps) obj;
+ return derefArgument.equals(other.derefArgument) && relativePath.equals(other.relativePath);
+ }
+
+ @Override
+ ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return helper.add("derefArgument", derefArgument).add("relativePath", relativePath);
+ }
+ }
+