Eliminate AugmentationHolder
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / Augmentable.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.binding;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Map;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * Augmentable (extensible) object which could carry additional data defined by a third-party extension, without
18  * introducing conflict between various extension.
19  *
20  * <p>
21  * This interface uses extended version of ExtensibleInterface pattern which also adds marker interface for
22  * augmentations (extensions) - {@link Augmentable}.
23  *
24  * @param <T> Base class which should implements this interface and is target for augmentation.
25  * @author Tony Tkacik
26  */
27 public interface Augmentable<T> {
28     /**
29      * Returns instance of augmentation.
30      *
31      * @param augmentationType Type of augmentation to be returned.
32      * @param <A> Type capture for augmentation type
33      * @return instance of augmentation, or null if the augmentationType is not present.
34      * @throws NullPointerException if augmentationType is null
35      */
36     @SuppressWarnings("unchecked")
37     default <A extends Augmentation<T>> @Nullable A augmentation(final Class<A> augmentationType) {
38         return (A) augmentations().get(requireNonNull(augmentationType));
39     }
40
41     /**
42      * Returns map of all augmentations.
43      *
44      * @return map of all augmentations.
45      */
46     @NonNull Map<Class<? extends Augmentation<T>>, Augmentation<T>> augmentations();
47 }