Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / LeafrefTypeDefinition.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.Objects;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.YangConstants;
15 import org.opendaylight.yangtools.yang.model.api.PathExpression;
16
17 public interface LeafrefTypeDefinition extends RequireInstanceRestrictedTypeDefinition<LeafrefTypeDefinition> {
18     /**
19      * Well-known QName of the {@code leafref} built-in type.
20      */
21     QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "leafref").intern();
22
23     PathExpression getPathStatement();
24
25     /**
26      * {@inheritDoc}
27      *
28      * <p>
29      * For YANG version 1 (RFC6020), this should always return true.
30      */
31     @Override
32     boolean requireInstance();
33
34     static int hashCode(final @NonNull LeafrefTypeDefinition type) {
35         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
36             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getPathStatement());
37     }
38
39     static boolean equals(final @NonNull LeafrefTypeDefinition type, final @Nullable Object obj) {
40         if (type == obj) {
41             return true;
42         }
43
44         final LeafrefTypeDefinition other = TypeDefinitions.castIfEquals(LeafrefTypeDefinition.class, type, obj);
45         return other != null && type.getPathStatement().equals(other.getPathStatement());
46     }
47
48     static String toString(final @NonNull LeafrefTypeDefinition type) {
49         return TypeDefinitions.toStringHelper(type).add("pathStatement", type.getPathStatement()).toString();
50     }
51 }