Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / StringTypeDefinition.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api.type;
9
10 import java.util.List;
11 import java.util.Objects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.YangConstants;
16
17 /**
18  * Contains method for getting data from the <code>string</code> YANG built-in type.
19  */
20 public interface StringTypeDefinition extends LengthRestrictedTypeDefinition<StringTypeDefinition> {
21     /**
22      * Well-known QName of the {@code string} built-in type.
23      */
24     QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "string").intern();
25
26     /**
27      * Returns patterns specified in the string.
28      *
29      * @return list of pattern constraints which are specified in the {@code pattern} substatement of the {@code type}
30      *         statement
31      */
32     @NonNull List<PatternConstraint> getPatternConstraints();
33
34     static int hashCode(final @NonNull StringTypeDefinition type) {
35         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
36             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null),
37             type.getPatternConstraints());
38     }
39
40     static boolean equals(final @NonNull StringTypeDefinition type, final @Nullable Object obj) {
41         if (type == obj) {
42             return true;
43         }
44
45         final StringTypeDefinition other = TypeDefinitions.castIfEquals(StringTypeDefinition.class, type, obj);
46         return other != null && type.getLengthConstraint().equals(other.getLengthConstraint())
47                 && type.getPatternConstraints().equals(other.getPatternConstraints());
48     }
49
50     static String toString(final @NonNull StringTypeDefinition type) {
51         return TypeDefinitions.toStringHelper(type).add("length", type.getLengthConstraint().orElse(null))
52                 .add("patterns", type.getPatternConstraints()).toString();
53     }
54 }