Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / StringTypeDefinition.java
index e1bf21ada41fd25c1571c811b397ed4b0a1462a7..f4bbffa909ec49c5176657135d70778c8d0bcb15 100644 (file)
@@ -8,31 +8,40 @@
 package org.opendaylight.yangtools.yang.model.api.type;
 
 import java.util.List;
-
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import java.util.Objects;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
- * 
- * Contains method for getting data from the <code>string</code> YANG built-in
- * type.
+ * Contains method for getting data from the <code>string</code> YANG built-in type.
  */
-public interface StringTypeDefinition extends TypeDefinition<StringTypeDefinition> {
-
-    /**
-     * Returns length constraint specified in the string.
-     * 
-     * @return list of length constraint which are specified in the
-     *         <code>lenght</code> substatement of the <code>type</code>
-     *         statement
-     */
-    List<LengthConstraint> getLengthStatements();
-
+public interface StringTypeDefinition extends LengthRestrictedTypeDefinition<StringTypeDefinition> {
     /**
      * Returns patterns specified in the string.
-     * 
-     * @return list of pattern constraints which are specified in the
-     *         <code>pattern</code> substatement of the <code>type</code>
+     *
+     * @return list of pattern constraints which are specified in the {@code pattern} substatement of the {@code type}
      *         statement
      */
-    List<PatternConstraint> getPatterns();
+    @NonNull List<PatternConstraint> getPatternConstraints();
+
+    static int hashCode(final @NonNull StringTypeDefinition type) {
+        return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(),
+            type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null),
+            type.getPatternConstraints());
+    }
+
+    static boolean equals(final @NonNull StringTypeDefinition type, final @Nullable Object obj) {
+        if (type == obj) {
+            return true;
+        }
+
+        final StringTypeDefinition other = TypeDefinitions.castIfEquals(StringTypeDefinition.class, type, obj);
+        return other != null && type.getLengthConstraint().equals(other.getLengthConstraint())
+                && type.getPatternConstraints().equals(other.getPatternConstraints());
+    }
+
+    static String toString(final @NonNull StringTypeDefinition type) {
+        return TypeDefinitions.toStringHelper(type).add("length", type.getLengthConstraint().orElse(null))
+                .add("patterns", type.getPatternConstraints()).toString();
+    }
 }