Merge "Remove unused declarations"
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / Leafref.java
index 2a52b0f453adb70e6a852a63f4b3ca8155619bbf..5a14d3097b7c2eb8fdf9c780e18fc3fb0582bf2e 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -24,124 +24,74 @@ import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
  * @see LeafrefTypeDefinition
  */
 public final class Leafref implements LeafrefTypeDefinition {
-    private static final QName name = BaseTypes.constructQName("leafref");
-    private static final String description = "The leafref type is used to reference a "
-            + "particular leaf instance in the data tree.";
-    private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.9";
-    private final SchemaPath path;
+    private static final QName NAME = BaseTypes.constructQName("leafref");
+    private static final SchemaPath PATH = SchemaPath.create(true, NAME);
+    private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
+    private static final String REF = "https://tools.ietf.org/html/rfc6020#section-9.9";
+
     private final RevisionAwareXPath xpath;
-    private final String units = "";
-    private final LeafrefTypeDefinition baseType;
+    private final SchemaPath path;
+
+    @Deprecated
+    public Leafref(final RevisionAwareXPath xpath) {
+        this(PATH,xpath);
+
+    }
+
+    private Leafref(final SchemaPath path, final RevisionAwareXPath target) {
+        this.path = Preconditions.checkNotNull(path,"path must be specified");
+        this.xpath = Preconditions.checkNotNull(target,"target must not be null.");
+    }
 
-    public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
-        this.path = path;
-        this.xpath = xpath;
-        baseType = this;
+    public static Leafref create(final SchemaPath path,final RevisionAwareXPath target) {
+        return new Leafref(path,target);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
-     */
     @Override
     public LeafrefTypeDefinition getBaseType() {
-        return baseType;
+        return null;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
-     */
     @Override
     public String getUnits() {
-        return units;
+        return "";
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
-     * ()
-     */
     @Override
     public Object getDefaultValue() {
         return this;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
-     */
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
-     */
     @Override
     public SchemaPath getPath() {
         return path;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
-     */
     @Override
     public String getDescription() {
-        return description;
+        return DESCRIPTION;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
-     */
     @Override
     public String getReference() {
-        return reference;
+        return REF;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
-     */
     @Override
     public Status getStatus() {
         return Status.CURRENT;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
-     * ()
-     */
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return Collections.emptyList();
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition
-     * #getPathStatement()
-     */
     @Override
     public RevisionAwareXPath getPathStatement() {
         return xpath;
@@ -151,14 +101,12 @@ public final class Leafref implements LeafrefTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
-        result = prime * result + ((units == null) ? 0 : units.hashCode());
         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -169,20 +117,6 @@ public final class Leafref implements LeafrefTypeDefinition {
             return false;
         }
         Leafref other = (Leafref) obj;
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
-            return false;
-        }
         if (xpath == null) {
             if (other.xpath != null) {
                 return false;
@@ -196,12 +130,10 @@ public final class Leafref implements LeafrefTypeDefinition {
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        builder.append("Leafref [path=");
-        builder.append(path);
-        builder.append("xpath=");
+        builder.append("type ");
+        builder.append(NAME);
+        builder.append(" [xpath=");
         builder.append(xpath);
-        builder.append(", units=");
-        builder.append(units);
         builder.append("]");
         return builder.toString();
     }