Enable checkstyle in yang-model-util
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / RangeConstraintImpl.java
index 2bf3b32ddb8a31a2c2fbb9c309e353e8da7771d1..f1e76b14e7ffb438ebd5540b753d98b20cea01ac 100644 (file)
@@ -11,18 +11,17 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 
 /**
- * {@link Immutable} implementation of {@link LengthConstraint}.
- *
- * Range constraint based on supplied parameters with additional behaviour:
+ * {@link Immutable} implementation of {@link RangeConstraint}.
  *
+ * <p>
+ * Range constraint based on supplied parameters with additional behavior:
  * <ul>
  * <li>{@link RangeConstraint#getErrorAppTag()} returns
  * <code>range-out-of-specified-bounds</code>
- * <li>{@link RangeConstraint#getErrorMessage() returns <code>The argument is
+ * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is
  * out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
  * </ul>
  */
@@ -38,14 +37,19 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable {
 
     RangeConstraintImpl(final Number min, final Number max, final Optional<String> description,
             final Optional<String> reference) {
-        super();
+        this(min, max, description, reference, "range-out-of-specified-bounds", "The argument is out of bounds <" + min
+                + ", " + max + ">");
+    }
+
+    RangeConstraintImpl(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference, final String errorAppTag, final String errorMessage) {
         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 + ">";
+        this.errorAppTag = errorAppTag != null ? errorAppTag : "range-out-of-specified-bounds";
+        this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
+                + ">";
     }
 
     @Override
@@ -106,20 +110,7 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable {
 
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("RangeConstraintImpl [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 "RangeConstraintImpl [min=" + min + ", max=" + max + ", description=" + description
+                + ", reference=" + reference + ", errorAppTag=" + errorAppTag + ", errorMessage=" + errorMessage + "]";
     }
-}
\ No newline at end of file
+}