blob: d90c9da2cefa3fd012705e01a32025ee29602b57 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
tom27ae0e62014-10-01 20:35:01 -070017
tom27ae0e62014-10-01 20:35:01 -070018import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * Base abstraction of an annotated entity.
22 */
tom5a9383a2014-10-02 07:33:52 -070023public abstract class AbstractAnnotated implements Annotated {
tom27ae0e62014-10-01 20:35:01 -070024
tomf5d85d42014-10-02 05:27:56 -070025 private static final Annotations EMPTY = DefaultAnnotations.builder().build();
tom27ae0e62014-10-01 20:35:01 -070026
tomf5d85d42014-10-02 05:27:56 -070027 private final Annotations annotations;
tom27ae0e62014-10-01 20:35:01 -070028
29 // For serialization
30 protected AbstractAnnotated() {
tomf5d85d42014-10-02 05:27:56 -070031 this.annotations = null;
tom27ae0e62014-10-01 20:35:01 -070032 }
33
34 /**
35 * Creates a new entity, annotated with the specified annotations.
36 *
37 * @param annotations optional key/value annotations map
38 */
tomf5d85d42014-10-02 05:27:56 -070039 protected AbstractAnnotated(Annotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070040 checkArgument(annotations.length <= 1, "Only one set of annotations is expected");
41 this.annotations = annotations.length == 1 ? annotations[0] : EMPTY;
42 }
43
44 @Override
tomf5d85d42014-10-02 05:27:56 -070045 public Annotations annotations() {
46 return annotations;
tom27ae0e62014-10-01 20:35:01 -070047 }
48
49}