2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.api.type;
10 import java.util.List;
11 import java.util.Objects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
16 * Contains method for getting data from the <code>string</code> YANG built-in type.
18 public interface StringTypeDefinition extends LengthRestrictedTypeDefinition<StringTypeDefinition> {
20 * Returns patterns specified in the string.
22 * @return list of pattern constraints which are specified in the {@code pattern} substatement of the {@code type}
25 @NonNull List<PatternConstraint> getPatternConstraints();
27 static int hashCode(final @NonNull StringTypeDefinition type) {
28 return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(),
29 type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null),
30 type.getPatternConstraints());
33 static boolean equals(final @NonNull StringTypeDefinition type, final @Nullable Object obj) {
38 final StringTypeDefinition other = TypeDefinitions.castIfEquals(StringTypeDefinition.class, type, obj);
39 return other != null && type.getLengthConstraint().equals(other.getLengthConstraint())
40 && type.getPatternConstraints().equals(other.getPatternConstraints());
43 static String toString(final @NonNull StringTypeDefinition type) {
44 return TypeDefinitions.toStringHelper(type).add("length", type.getLengthConstraint().orElse(null))
45 .add("patterns", type.getPatternConstraints()).toString();