Use String concatenation instead of StringBuffer/Builder
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / DeviationBuilder.java
index 7d9805761391cfb4158a0ba642c08548a347873e..2aa509e08a7c24d65769918127e15dcd6d96d8cd 100644 (file)
@@ -7,47 +7,42 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
+import com.google.common.collect.ImmutableList;
 import java.util.List;
-
+import java.util.Objects;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.parser.builder.api.AbstractBuilder;
-import org.opendaylight.yangtools.yang.parser.util.ParserUtils;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractBuilder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
-import com.google.common.collect.ImmutableList;
-
+/**
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
+ */
+@Deprecated
 public final class DeviationBuilder extends AbstractBuilder {
     private DeviationImpl instance;
-    private final String targetPathStr;
-    private SchemaPath targetPath;
+    private final SchemaPath targetPath;
     private Deviate deviate;
     private String reference;
 
-    DeviationBuilder(final String moduleName, final int line, final String targetPathStr) {
+    DeviationBuilder(final String moduleName, final int line, final SchemaPath targetPath) {
         super(moduleName, line);
-        if (!targetPathStr.startsWith("/")) {
-            throw new YangParseException(moduleName, line,
-                    "Deviation argument string must be an absolute schema node identifier.");
-        }
-        this.targetPathStr = targetPathStr;
-        this.targetPath = ParserUtils.parseXPathString(targetPathStr);
+        this.targetPath = targetPath;
     }
 
     @Override
     public Deviation build() {
-        if (targetPath == null) {
-            throw new YangParseException(getModuleName(), getLine(), "Unresolved deviation target");
-        }
-
         if (instance != null) {
             return instance;
         }
+        if (targetPath == null) {
+            throw new YangParseException(getModuleName(), getLine(), "Unresolved deviation target");
+        }
 
-        instance = new DeviationImpl();
-        instance.targetPath = targetPath;
+        instance = new DeviationImpl(targetPath);
         instance.deviate = deviate;
         instance.reference = reference;
 
@@ -64,10 +59,6 @@ public final class DeviationBuilder extends AbstractBuilder {
         return targetPath;
     }
 
-    public void setTargetPath(final SchemaPath targetPath) {
-        this.targetPath = targetPath;
-    }
-
     public void setDeviate(final String deviate) {
         if ("not-supported".equals(deviate)) {
             this.deviate = Deviate.NOT_SUPPORTED;
@@ -88,16 +79,17 @@ public final class DeviationBuilder extends AbstractBuilder {
 
     @Override
     public String toString() {
-        return "deviation " + targetPathStr;
+        return "deviation " + targetPath;
     }
 
     private static final class DeviationImpl implements Deviation {
-        private SchemaPath targetPath;
+        private final SchemaPath targetPath;
         private Deviate deviate;
         private String reference;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
 
-        private DeviationImpl() {
+        private DeviationImpl(final SchemaPath targetPath) {
+            this.targetPath = targetPath;
         }
 
         @Override
@@ -124,14 +116,14 @@ public final class DeviationBuilder extends AbstractBuilder {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
-            result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
-            result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+            result = prime * result + Objects.hashCode(targetPath);
+            result = prime * result + Objects.hashCode(deviate);
+            result = prime * result + Objects.hashCode(reference);
             return result;
         }
 
         @Override
-        public boolean equals(Object obj) {
+        public boolean equals(final Object obj) {
             if (this == obj) {
                 return true;
             }
@@ -168,13 +160,11 @@ public final class DeviationBuilder extends AbstractBuilder {
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(DeviationImpl.class.getSimpleName());
-            sb.append("[");
-            sb.append("targetPath=" + targetPath);
-            sb.append(", deviate=" + deviate);
-            sb.append(", reference=" + reference);
-            sb.append("]");
-            return sb.toString();
+            return DeviationImpl.class.getSimpleName() + "[" +
+                    "targetPath=" + targetPath +
+                    ", deviate=" + deviate +
+                    ", reference=" + reference +
+                    "]";
         }
     }