tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkArgument; |
| 4 | |
| 5 | /** |
| 6 | * Base implementation of an annotated model description. |
| 7 | */ |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 8 | public abstract class AbstractDescription implements Annotated { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 9 | |
| 10 | private static final SparseAnnotations EMPTY = DefaultAnnotations.builder().build(); |
| 11 | |
| 12 | private final SparseAnnotations annotations; |
| 13 | |
| 14 | // For serialization |
| 15 | protected AbstractDescription() { |
| 16 | this.annotations = null; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Creates a new entity, annotated with the specified annotations. |
| 21 | * |
| 22 | * @param annotations optional key/value annotations map |
| 23 | */ |
| 24 | protected AbstractDescription(SparseAnnotations... annotations) { |
| 25 | checkArgument(annotations.length <= 1, "Only one set of annotations is expected"); |
| 26 | this.annotations = annotations.length == 1 ? annotations[0] : EMPTY; |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public SparseAnnotations annotations() { |
| 31 | return annotations; |
| 32 | } |
| 33 | |
| 34 | } |