Package org.onosproject.net
Class DefaultAnnotations
- java.lang.Object
-
- org.onosproject.net.DefaultAnnotations
-
- All Implemented Interfaces:
Annotations
,SparseAnnotations
public final class DefaultAnnotations extends Object implements SparseAnnotations
Represents a set of simple annotations that can be used to add arbitrary attributes to various parts of the data model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultAnnotations.Builder
Facility for gradually building model annotations.
-
Field Summary
Fields Modifier and Type Field Description static SparseAnnotations
EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HashMap<String,String>
asMap()
Returns the annotations as a map.static DefaultAnnotations.Builder
builder()
Creates a new annotations builder.boolean
equals(Object o)
int
hashCode()
boolean
isRemoved(String key)
Indicates whether the specified key has been tagged as removed.Set<String>
keys()
Returns the set of keys for available annotations.static DefaultAnnotations
merge(DefaultAnnotations annotations, SparseAnnotations sparseAnnotations)
Merges the specified base set of annotations and additional sparse annotations into new combined annotations.String
toString()
static SparseAnnotations
union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations)
Creates the union of two given SparseAnnotations.String
value(String key)
Returns the value of the specified annotation.
-
-
-
Field Detail
-
EMPTY
public static final SparseAnnotations EMPTY
-
-
Method Detail
-
asMap
public HashMap<String,String> asMap()
Returns the annotations as a map.- Returns:
- a copy of the contents of the annotations as a map.
-
builder
public static DefaultAnnotations.Builder builder()
Creates a new annotations builder.- Returns:
- new annotations builder
-
merge
public static DefaultAnnotations merge(DefaultAnnotations annotations, SparseAnnotations sparseAnnotations)
Merges the specified base set of annotations and additional sparse annotations into new combined annotations. If the supplied sparse annotations are empty, the original base annotations are returned. Any keys tagged for removal in the sparse annotations will be omitted in the resulting merged annotations.- Parameters:
annotations
- base annotationssparseAnnotations
- additional sparse annotations- Returns:
- combined annotations or the original base annotations if there are not additional annotations
-
union
public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations)
Creates the union of two given SparseAnnotations. Unlike themerge(DefaultAnnotations, SparseAnnotations)
method, result will beSparseAnnotations
instead ofAnnotations
. A key tagged for removal will remain in the output SparseAnnotations, if the counterpart of the input does not contain the same key.- Parameters:
annotations
- base annotationssparseAnnotations
- additional sparse annotations- Returns:
- combined annotations or the original base annotations if there are not additional annotations
-
keys
public Set<String> keys()
Description copied from interface:SparseAnnotations
Returns the set of keys for available annotations.Note that this set includes keys for any attributes tagged for removal.
- Specified by:
keys
in interfaceAnnotations
- Specified by:
keys
in interfaceSparseAnnotations
- Returns:
- annotation keys
-
value
public String value(String key)
Description copied from interface:Annotations
Returns the value of the specified annotation.- Specified by:
value
in interfaceAnnotations
- Parameters:
key
- annotation key- Returns:
- annotation value
-
isRemoved
public boolean isRemoved(String key)
Description copied from interface:SparseAnnotations
Indicates whether the specified key has been tagged as removed. This is used for merging sparse annotation sets.- Specified by:
isRemoved
in interfaceSparseAnnotations
- Parameters:
key
- annotation key- Returns:
- true if the previous annotation has been tagged for removal
-
-