blob: c32959826abe1b13f0c8caf3c6600d819b0ec84c [file] [log] [blame]
tom27ae0e62014-10-01 20:35:01 -07001package org.onlab.onos.net;
2
tom27ae0e62014-10-01 20:35:01 -07003import static com.google.common.base.Preconditions.checkArgument;
4
5/**
6 * Base abstraction of an annotated entity.
7 */
tom5a9383a2014-10-02 07:33:52 -07008public abstract class AbstractAnnotated implements Annotated {
tom27ae0e62014-10-01 20:35:01 -07009
tomf5d85d42014-10-02 05:27:56 -070010 private static final Annotations EMPTY = DefaultAnnotations.builder().build();
tom27ae0e62014-10-01 20:35:01 -070011
tomf5d85d42014-10-02 05:27:56 -070012 private final Annotations annotations;
tom27ae0e62014-10-01 20:35:01 -070013
14 // For serialization
15 protected AbstractAnnotated() {
tomf5d85d42014-10-02 05:27:56 -070016 this.annotations = null;
tom27ae0e62014-10-01 20:35:01 -070017 }
18
19 /**
20 * Creates a new entity, annotated with the specified annotations.
21 *
22 * @param annotations optional key/value annotations map
23 */
tomf5d85d42014-10-02 05:27:56 -070024 protected AbstractAnnotated(Annotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070025 checkArgument(annotations.length <= 1, "Only one set of annotations is expected");
26 this.annotations = annotations.length == 1 ? annotations[0] : EMPTY;
27 }
28
29 @Override
tomf5d85d42014-10-02 05:27:56 -070030 public Annotations annotations() {
31 return annotations;
tom27ae0e62014-10-01 20:35:01 -070032 }
33
34}