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.
20 * @param <T> Augmentable type
23 public abstract class AbstractAugmentable<T extends Augmentable<T>> implements Augmentable<T> {
24 private final @NonNull ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations;
26 protected AbstractAugmentable() {
27 this.augmentations = ImmutableMap.of();
30 protected AbstractAugmentable(final Map<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations) {
31 this.augmentations = ImmutableMap.copyOf(augmentations);
34 protected AbstractAugmentable(
35 final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations) {
36 this.augmentations = requireNonNull(augmentations);
39 protected AbstractAugmentable(final AbstractAugmentable<T> other) {
40 this(other.augmentations);
44 @SuppressWarnings("unchecked")
45 public final <A extends Augmentation<T>> A augmentation(final Class<A> augmentationType) {
46 return (A) augmentations.get(requireNonNull(augmentationType));
50 public final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations() {