Fix checkstyle issues reported by odlparent-3.0.0's checkstyle
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / StringTypeBuilder.java
index e2f2959de0885f374ed00056df04125c01d81534..deafa424e7ef7ba12cd5c46c98b43f4b072f60cf 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.yangtools.yang.model.util.type;
 import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.List;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 
@@ -21,14 +23,29 @@ public final class StringTypeBuilder extends LengthRestrictedTypeBuilder<StringT
         super(baseType, path);
     }
 
-    public void addPatternConstraint(final PatternConstraint constraint) {
+    public StringTypeBuilder addPatternConstraint(final PatternConstraint constraint) {
         patternConstraints.add(Preconditions.checkNotNull(constraint));
         touch();
+        return this;
     }
 
     @Override
-    public RestrictedStringType buildType() {
-        return new RestrictedStringType(getBaseType(), getPath(), getUnknownSchemaNodes(),
-            calculateLenghtConstraints(getBaseType().getLengthConstraints()), patternConstraints);
+    LengthConstraint typeLengthConstraints() {
+        /**
+         * Length constraint imposed on YANG string type by our implementation. {@link String#length()} is an integer,
+         * capping our ability to support strings up to 18446744073709551615 as defined in
+         * http://tools.ietf.org/html/rfc6020#section-9.4.4.
+         *
+         * FIXME: We could bump this number up to allow such models, but that could lead to unexpected run-time errors.
+         *        In order to do that, the parser would need another pass on the effective statements, which would cap
+         *        the constraints to the run-time environment.
+         */
+        return JavaLengthConstraints.INTEGER_SIZE_CONSTRAINTS;
+    }
+
+    @Override
+    StringTypeDefinition buildType(final @Nullable LengthConstraint constraint) {
+        return new RestrictedStringType(getBaseType(), getPath(), getUnknownSchemaNodes(), constraint,
+            patternConstraints);
     }
 }