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.mdsal.binding.generator.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.BiMap;
12 import com.google.common.collect.ImmutableBiMap;
13 import com.google.common.collect.ImmutableMap;
14 import com.google.common.collect.ImmutableMultimap;
15 import com.google.common.collect.Multimap;
16 import java.util.Collection;
18 import java.util.Optional;
19 import javax.annotation.concurrent.ThreadSafe;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.yangtools.concepts.Immutable;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
27 * The result of BindingGenerator run. Contains mapping between Types and SchemaNodes.
31 public final class BindingRuntimeTypes implements Immutable {
32 private final Map<Type, AugmentationSchemaNode> typeToAugmentation;
33 private final BiMap<Type, WithStatus> typeToSchema;
34 private final Multimap<Type, Type> choiceToCases;
35 private final Map<QName, Type> identities;
37 public BindingRuntimeTypes(final Map<Type, AugmentationSchemaNode> typeToAugmentation,
38 final BiMap<Type, WithStatus> typeToDefiningSchema, final Multimap<Type, Type> choiceToCases,
39 final Map<QName, Type> identities) {
40 this.typeToAugmentation = ImmutableMap.copyOf(typeToAugmentation);
41 this.typeToSchema = ImmutableBiMap.copyOf(typeToDefiningSchema);
42 this.choiceToCases = ImmutableMultimap.copyOf(choiceToCases);
43 this.identities = ImmutableMap.copyOf(identities);
46 public Optional<AugmentationSchemaNode> findAugmentation(final Type type) {
47 return Optional.ofNullable(typeToAugmentation.get(type));
50 public Optional<Type> findIdentity(final QName qname) {
51 return Optional.ofNullable(identities.get(qname));
54 public Optional<WithStatus> findSchema(final Type type) {
55 return Optional.ofNullable(typeToSchema.get(type));
58 public Optional<Type> findType(final WithStatus schema) {
59 return Optional.ofNullable(typeToSchema.inverse().get(schema));
62 public Multimap<Type, Type> getChoiceToCases() {
66 public Collection<Type> findCases(final Type choiceType) {
67 return choiceToCases.get(choiceType);