Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 17 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 19 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Base abstraction of an annotated entity. |
| 23 | */ |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 24 | public abstract class AbstractAnnotated implements Annotated { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 25 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 26 | private final Annotations annotations; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 27 | |
| 28 | // For serialization |
| 29 | protected AbstractAnnotated() { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 30 | this.annotations = null; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Creates a new entity, annotated with the specified annotations. |
| 35 | * |
| 36 | * @param annotations optional key/value annotations map |
| 37 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 38 | protected AbstractAnnotated(Annotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 39 | checkArgument(annotations.length <= 1, "Only one set of annotations is expected"); |
| 40 | this.annotations = annotations.length == 1 ? annotations[0] : EMPTY; |
| 41 | } |
| 42 | |
| 43 | @Override |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 44 | public Annotations annotations() { |
| 45 | return annotations; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | } |