Populate data/ hierarchy
[yangtools.git] / model / 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.model.api.PathExpression;
14
15 public interface LeafrefTypeDefinition extends RequireInstanceRestrictedTypeDefinition<LeafrefTypeDefinition> {
16     /**
17      * Return the {@link PathExpression} of this {@code leafref}.
18      *
19      * @return A path expression
20      */
21     @NonNull PathExpression getPathStatement();
22
23     /**
24      * {@inheritDoc}
25      *
26      * <p>
27      * For YANG version 1 (RFC6020), this should always return true.
28      */
29     @Override
30     boolean requireInstance();
31
32     static int hashCode(final @NonNull LeafrefTypeDefinition type) {
33         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
34             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getPathStatement());
35     }
36
37     static boolean equals(final @NonNull LeafrefTypeDefinition type, final @Nullable Object obj) {
38         if (type == obj) {
39             return true;
40         }
41
42         final LeafrefTypeDefinition other = TypeDefinitions.castIfEquals(LeafrefTypeDefinition.class, type, obj);
43         return other != null && type.getPathStatement().equals(other.getPathStatement());
44     }
45
46     static String toString(final @NonNull LeafrefTypeDefinition type) {
47         return TypeDefinitions.toStringHelper(type).add("pathStatement", type.getPathStatement()).toString();
48     }
49 }