Make getIfFeaturePredicate() a default method
[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.model.api.RevisionAwareXPath;
14
15 public interface LeafrefTypeDefinition extends RequireInstanceRestrictedTypeDefinition<LeafrefTypeDefinition> {
16
17     // FIXME: this is not the same syntax as when statement. See https://tools.ietf.org/html/rfc7950#section-9.9.2
18     RevisionAwareXPath getPathStatement();
19
20     /**
21      * {@inheritDoc}
22      *
23      * <p>
24      * For YANG version 1 (RFC6020), this should always return true.
25      */
26     @Override
27     boolean requireInstance();
28
29     static int hashCode(final @NonNull LeafrefTypeDefinition type) {
30         return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(),
31             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getPathStatement());
32     }
33
34     static boolean equals(final @NonNull LeafrefTypeDefinition type, final @Nullable Object obj) {
35         if (type == obj) {
36             return true;
37         }
38
39         final LeafrefTypeDefinition other = TypeDefinitions.castIfEquals(LeafrefTypeDefinition.class, type, obj);
40         return other != null && type.getPathStatement().equals(other.getPathStatement());
41     }
42
43     static String toString(final @NonNull LeafrefTypeDefinition type) {
44         return TypeDefinitions.toStringHelper(type).add("pathStatement", type.getPathStatement()).toString();
45     }
46 }