2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. All rights reserved.
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
8 package org.opendaylight.binding.runtime.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.collect.BiMap;
15 import com.google.common.collect.ImmutableBiMap;
16 import com.google.common.collect.ImmutableMap;
17 import com.google.common.collect.ImmutableMultimap;
18 import com.google.common.collect.Multimap;
19 import java.util.Collection;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.concepts.Immutable;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
32 * The result of BindingGenerator run. Contains mapping between Types and SchemaNodes.
35 public final class BindingRuntimeTypes implements SchemaContextProvider, Immutable {
36 private final @NonNull SchemaContext schemaContext;
37 private final ImmutableMap<Type, AugmentationSchemaNode> typeToAugmentation;
38 private final ImmutableBiMap<Type, WithStatus> typeToSchema;
39 private final ImmutableMultimap<Type, Type> choiceToCases;
40 private final ImmutableMap<QName, Type> identities;
42 public BindingRuntimeTypes(final SchemaContext schemaContext,
43 final Map<Type, AugmentationSchemaNode> typeToAugmentation,
44 final BiMap<Type, WithStatus> typeToDefiningSchema, final Multimap<Type, Type> choiceToCases,
45 final Map<QName, Type> identities) {
46 this.schemaContext = requireNonNull(schemaContext);
47 this.typeToAugmentation = ImmutableMap.copyOf(typeToAugmentation);
48 this.typeToSchema = ImmutableBiMap.copyOf(typeToDefiningSchema);
49 this.choiceToCases = ImmutableMultimap.copyOf(choiceToCases);
50 this.identities = ImmutableMap.copyOf(identities);
54 public SchemaContext getSchemaContext() {
58 public Optional<AugmentationSchemaNode> findAugmentation(final Type type) {
59 return Optional.ofNullable(typeToAugmentation.get(type));
62 public Optional<Type> findIdentity(final QName qname) {
63 return Optional.ofNullable(identities.get(qname));
66 public Optional<WithStatus> findSchema(final Type type) {
67 return Optional.ofNullable(typeToSchema.get(type));
70 public Optional<Type> findType(final WithStatus schema) {
71 return Optional.ofNullable(typeToSchema.inverse().get(schema));
74 public Multimap<Type, Type> getChoiceToCases() {
78 public Collection<Type> findCases(final Type choiceType) {
79 return choiceToCases.get(choiceType);
83 public String toString() {
84 return MoreObjects.toStringHelper(this)
85 .add("typeToAugmentation", typeToAugmentation)
86 .add("typeToSchema", typeToSchema)
87 .add("choiceToCases", choiceToCases)
88 .add("identities", identities)