tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 3 | import static com.google.common.base.Preconditions.checkArgument; |
| 4 | |
| 5 | /** |
| 6 | * Base abstraction of an annotated entity. |
| 7 | */ |
| 8 | public class AbstractAnnotated implements Annotated { |
| 9 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame^] | 10 | private static final Annotations EMPTY = DefaultAnnotations.builder().build(); |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 11 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame^] | 12 | private final Annotations annotations; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 13 | |
| 14 | // For serialization |
| 15 | protected AbstractAnnotated() { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame^] | 16 | this.annotations = null; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Creates a new entity, annotated with the specified annotations. |
| 21 | * |
| 22 | * @param annotations optional key/value annotations map |
| 23 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame^] | 24 | protected AbstractAnnotated(Annotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 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 |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame^] | 30 | public Annotations annotations() { |
| 31 | return annotations; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | } |