Package ucar.nc2
Class AttributeContainerMutable
- java.lang.Object
-
- ucar.nc2.AttributeContainerMutable
-
- All Implemented Interfaces:
Iterable<Attribute>
,AttributeContainer
public class AttributeContainerMutable extends Object implements AttributeContainer
A mutable collection of Attributes.
-
-
Constructor Summary
Constructors Constructor Description AttributeContainerMutable(String name)
Constructor with container name.AttributeContainerMutable(String name, Iterable<Attribute> from)
Constructor with container name and list of Attributes to copy in.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(Iterable<Attribute> atts)
Add all; replace old if has same name.Attribute
addAttribute(String name, Number value)
Add Attribute; name and value must not be null.Attribute
addAttribute(String name, String value)
Add Attribute; name and value must not be null.Attribute
addAttribute(Attribute att)
Add an attribute to the container.AttributeContainerMutable
clear()
Remove all attributes.static AttributeContainerMutable
copyFrom(AttributeContainer from)
Create mutable from immutable container.Attribute
findAttribute(String name)
Find an Attribute by exact match on name.double
findAttributeDouble(String attName, double defaultValue)
Find a Numeric Attribute by name (ignore case), return the double value of the Attribute.Attribute
findAttributeIgnoreCase(String name)
Find an Attribute by name, first doing an exact match, then ignoring case.int
findAttributeInteger(String attName, int defaultValue)
Find a Numeric Attribute by name (ignore case), return the integer value of the Attribute.String
findAttributeString(String attName, String defaultValue)
Find a String Attribute by name (ignore case), return the String value of the Attribute.String
getName()
Get the (optional) name of the AttributeContainer.boolean
isEmpty()
True if there are no attributes in the container.Iterator<Attribute>
iterator()
An unordered iterator over the contained attributes.boolean
remove(Attribute a)
Remove an Attribute : uses the attribute hashCode to find it.boolean
removeAttribute(String attName)
Remove an Attribute by name.boolean
removeAttributeIgnoreCase(String attName)
Remove an Attribute by name, ignoring caseboolean
replace(Attribute a, String newName)
Replace an Attribute with a different name, same value.AttributeContainerMutable
setName(String name)
Set the AttributeContainer name.AttributeContainer
toImmutable()
Turn into an immutable AttributeContainer-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ucar.nc2.AttributeContainer
hasAttribute, hasAttributeIgnoreCase
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AttributeContainerMutable
public AttributeContainerMutable(@Nullable String name)
Constructor with container name.
-
-
Method Detail
-
copyFrom
public static AttributeContainerMutable copyFrom(@Nullable AttributeContainer from)
Create mutable from immutable container.
-
setName
public AttributeContainerMutable setName(@Nullable String name)
Set the AttributeContainer name.
-
getName
@Nullable public String getName()
Description copied from interface:AttributeContainer
Get the (optional) name of the AttributeContainer.- Specified by:
getName
in interfaceAttributeContainer
-
iterator
public Iterator<Attribute> iterator()
Description copied from interface:AttributeContainer
An unordered iterator over the contained attributes.- Specified by:
iterator
in interfaceAttributeContainer
- Specified by:
iterator
in interfaceIterable<Attribute>
-
addAttribute
public Attribute addAttribute(Attribute att)
Add an attribute to the container. If an attrribute of the same name already exists, replace it with this one.- Returns:
- the added attribute.
-
addAttribute
public Attribute addAttribute(String name, String value)
Add Attribute; name and value must not be null.
-
addAttribute
public Attribute addAttribute(String name, Number value)
Add Attribute; name and value must not be null.
-
findAttributeString
public String findAttributeString(String attName, String defaultValue)
Description copied from interface:AttributeContainer
Find a String Attribute by name (ignore case), return the String value of the Attribute.- Specified by:
findAttributeString
in interfaceAttributeContainer
- Returns:
- the attribute value, or defaultValue if not found
-
findAttribute
public Attribute findAttribute(String name)
Description copied from interface:AttributeContainer
Find an Attribute by exact match on name.- Specified by:
findAttribute
in interfaceAttributeContainer
-
findAttributeIgnoreCase
public Attribute findAttributeIgnoreCase(String name)
Description copied from interface:AttributeContainer
Find an Attribute by name, first doing an exact match, then ignoring case.- Specified by:
findAttributeIgnoreCase
in interfaceAttributeContainer
-
findAttributeDouble
public double findAttributeDouble(String attName, double defaultValue)
Description copied from interface:AttributeContainer
Find a Numeric Attribute by name (ignore case), return the double value of the Attribute. Must be numeric or a string that parses as an Integer.- Specified by:
findAttributeDouble
in interfaceAttributeContainer
- Returns:
- the attribute value, or defaultValue if not found
-
findAttributeInteger
public int findAttributeInteger(String attName, int defaultValue)
Description copied from interface:AttributeContainer
Find a Numeric Attribute by name (ignore case), return the integer value of the Attribute. Must be numeric or a string that parses as an Integer.- Specified by:
findAttributeInteger
in interfaceAttributeContainer
- Returns:
- the attribute value, or defaultValue if not found
-
remove
public boolean remove(Attribute a)
Remove an Attribute : uses the attribute hashCode to find it.- Parameters:
a
- remove this attribute- Returns:
- true if was found and removed
-
replace
public boolean replace(Attribute a, String newName)
Replace an Attribute with a different name, same value.- Parameters:
a
- remove this attribute- Returns:
- true if old attribute exists.
-
clear
public AttributeContainerMutable clear()
Remove all attributes.
-
removeAttribute
public boolean removeAttribute(String attName)
Remove an Attribute by name.- Parameters:
attName
- if exists, remove this attribute- Returns:
- true if was found and removed
-
removeAttributeIgnoreCase
public boolean removeAttributeIgnoreCase(String attName)
Remove an Attribute by name, ignoring case- Parameters:
attName
- if exists, remove this attribute- Returns:
- true if was found and removed
-
toImmutable
public AttributeContainer toImmutable()
Turn into an immutable AttributeContainer
-
isEmpty
public boolean isEmpty()
Description copied from interface:AttributeContainer
True if there are no attributes in the container.- Specified by:
isEmpty
in interfaceAttributeContainer
-
-