blob: 8d1185a6505be1595c65bef84cea4bf80bcd56d0 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080019import static org.onosproject.net.DefaultAnnotations.EMPTY;
tom27ae0e62014-10-01 20:35:01 -070020
21/**
22 * Base abstraction of an annotated entity.
23 */
tom5a9383a2014-10-02 07:33:52 -070024public abstract class AbstractAnnotated implements Annotated {
tom27ae0e62014-10-01 20:35:01 -070025
tomf5d85d42014-10-02 05:27:56 -070026 private final Annotations annotations;
tom27ae0e62014-10-01 20:35:01 -070027
28 // For serialization
29 protected AbstractAnnotated() {
tomf5d85d42014-10-02 05:27:56 -070030 this.annotations = null;
tom27ae0e62014-10-01 20:35:01 -070031 }
32
33 /**
34 * Creates a new entity, annotated with the specified annotations.
35 *
36 * @param annotations optional key/value annotations map
37 */
tomf5d85d42014-10-02 05:27:56 -070038 protected AbstractAnnotated(Annotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070039 checkArgument(annotations.length <= 1, "Only one set of annotations is expected");
40 this.annotations = annotations.length == 1 ? annotations[0] : EMPTY;
41 }
42
43 @Override
tomf5d85d42014-10-02 05:27:56 -070044 public Annotations annotations() {
45 return annotations;
tom27ae0e62014-10-01 20:35:01 -070046 }
47
48}