Update TypeDefinition design
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / RangeConstraintEffectiveImpl.java
index 4308ecb07b80cca83b9ac4f6762f04f65c31c1d4..a5fedd5b9af6beab918232f7ec99b92b83999b65 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Objects;
+import java.util.Optional;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 
 public class RangeConstraintEffectiveImpl implements RangeConstraint {
@@ -26,36 +27,39 @@ public class RangeConstraintEffectiveImpl implements RangeConstraint {
 
     public RangeConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
             final Optional<String> reference) {
+        this(min, max, description.orElse(null), reference.orElse(null), "range-out-of-specified-bounds",
+                "The argument is out of bounds <" + min + ", " + max + ">");
+    }
 
-        super();
-
-        this.min = Preconditions.checkNotNull(min, "min must not be null.");
-        this.max = Preconditions.checkNotNull(max, "max must not be null.");
-        this.description = description.orNull();
-        this.reference = reference.orNull();
-
-        this.errorAppTag = "range-out-of-specified-bounds";
-        this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
+    public RangeConstraintEffectiveImpl(final Number min, final Number max, final String description,
+            final String reference, final String errorAppTag, final String errorMessage) {
+        this.min = requireNonNull(min, "min must not be null");
+        this.max = requireNonNull(max, "max must not be null");
+        this.description = description;
+        this.reference = reference;
+        this.errorAppTag = errorAppTag != null ? errorAppTag : "range-out-of-specified-bounds";
+        this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
+                + ">";
     }
 
     @Override
-    public String getDescription() {
-        return description;
+    public Optional<String> getDescription() {
+        return Optional.ofNullable(description);
     }
 
     @Override
-    public String getErrorAppTag() {
-        return errorAppTag;
+    public Optional<String> getErrorAppTag() {
+        return Optional.ofNullable(errorAppTag);
     }
 
     @Override
-    public String getErrorMessage() {
-        return errorMessage;
+    public Optional<String> getErrorMessage() {
+        return Optional.ofNullable(errorMessage);
     }
 
     @Override
-    public String getReference() {
-        return reference;
+    public Optional<String> getReference() {
+        return Optional.ofNullable(reference);
     }
 
     @Override
@@ -110,21 +114,8 @@ public class RangeConstraintEffectiveImpl implements RangeConstraint {
 
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append(RangeConstraintEffectiveImpl.class.getSimpleName());
-        builder.append(" [min=");
-        builder.append(min);
-        builder.append(", max=");
-        builder.append(max);
-        builder.append(", description=");
-        builder.append(description);
-        builder.append(", reference=");
-        builder.append(reference);
-        builder.append(", errorAppTag=");
-        builder.append(errorAppTag);
-        builder.append(", errorMessage=");
-        builder.append(errorMessage);
-        builder.append("]");
-        return builder.toString();
+        return RangeConstraintEffectiveImpl.class.getSimpleName() + " [min=" + min + ", max=" + max + ", description="
+                + description + ", reference=" + reference + ", errorAppTag=" + errorAppTag + ", errorMessage="
+                + errorMessage + "]";
     }
 }