All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.yangtools.binding.lib.AbstractAugmentable Maven / Gradle / Ivy

/*
 * 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.binding.lib;

import static java.util.Objects.requireNonNull;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.binding.Augmentable;
import org.opendaylight.yangtools.binding.Augmentation;

/**
 * Abstract base class for implementing immutable {@link Augmentable} classes. This class is provided as a convenience.
 *
 * @param  Augmentable type
 */
public abstract class AbstractAugmentable> implements Augmentable {
    private final @NonNull ImmutableMap>, Augmentation> augmentations;

    protected AbstractAugmentable() {
        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;
    }

    @Override
    public abstract int hashCode();

    @Override
    public abstract boolean equals(Object obj);

    @Override
    public abstract String toString();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy