/* * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.binding; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; /** * Abstract base class for implementing immutable {@link Augmentable} classes. This class is provided as a convenience. * * @param Augmentable type */ @Beta public abstract class AbstractAugmentable> implements Augmentable { private final @NonNull ImmutableMap>, Augmentation> augmentations; protected AbstractAugmentable() { this.augmentations = ImmutableMap.of(); } protected AbstractAugmentable(final Map>, Augmentation> augmentations) { this.augmentations = ImmutableMap.copyOf(augmentations); } protected AbstractAugmentable( final ImmutableMap>, Augmentation> augmentations) { this.augmentations = requireNonNull(augmentations); } protected AbstractAugmentable(final AbstractAugmentable other) { this(other.augmentations); } @Override @SuppressWarnings("unchecked") public final > A augmentation(final Class augmentationType) { return (A) augmentations.get(requireNonNull(augmentationType)); } @Override public final ImmutableMap>, Augmentation> augmentations() { return augmentations; } }