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();
+ }
}