2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. 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.yangtools.yang.binding;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableMap;
15 import org.eclipse.jdt.annotation.NonNull;
18 * Abstract base class for implementing immutable {@link Augmentable} classes. This class is provided as a convenience,
19 * combining {@link AugmentationHolder} and providing {@link Augmentable#augmentation(Class)} implementation on top of
22 * @param <T> Augmentable type
25 public abstract class AbstractAugmentable<T extends Augmentable<T>> implements Augmentable<T>, AugmentationHolder<T> {
26 private final @NonNull ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations;
28 protected AbstractAugmentable() {
29 this.augmentations = ImmutableMap.of();
32 protected AbstractAugmentable(final Map<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations) {
33 this.augmentations = ImmutableMap.copyOf(augmentations);
36 protected AbstractAugmentable(
37 final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations) {
38 this.augmentations = requireNonNull(augmentations);
41 protected AbstractAugmentable(final AbstractAugmentable<T> other) {
42 this(other.augmentations);
45 @SuppressWarnings("unchecked")
47 public final <A extends Augmentation<T>> A augmentation(final Class<A> augmentationType) {
48 return (A) augmentations.get(requireNonNull(augmentationType));
52 public final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations() {