Populate data/ hierarchy
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / UnionTypeDefinition.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.opendaylight.yangtools.yang.model.api.TypeDefinition;
13
14 /**
15  * Contains the method which access union item in the union type.
16  */
17 public interface UnionTypeDefinition extends TypeDefinition<UnionTypeDefinition> {
18     /**
19      * Returns type definitions which represent the values of the arguments for all YANG {@code type} substatement in
20      * the main {@code union} statement.
21      *
22      * @return list of the type definition which contains the union items.
23      */
24     List<TypeDefinition<?>> getTypes();
25
26     static int hashCode(final UnionTypeDefinition type) {
27         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
28             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getTypes());
29     }
30
31     static boolean equals(final UnionTypeDefinition type, final Object obj) {
32         if (type == obj) {
33             return true;
34         }
35
36         final UnionTypeDefinition other = TypeDefinitions.castIfEquals(UnionTypeDefinition.class, type, obj);
37         return other != null && type.getTypes().equals(other.getTypes());
38     }
39
40     static String toString(final UnionTypeDefinition type) {
41         return TypeDefinitions.toStringHelper(type).add("types", type.getTypes()).toString();
42     }
43 }