things.data.impl
Class AttributesReaderWrapper

java.lang.Object
  extended by things.data.impl.AttributesReaderWrapper
All Implemented Interfaces:
AttributeReader

public class AttributesReaderWrapper
extends java.lang.Object
implements AttributeReader

A set of readable attributes from a simple hashmap.

Version:
1.0

Version History

EPG - Initial - 23 AUG 05
 
Author:
Erich P. Gatejen

Field Summary
protected  java.util.HashMap<java.lang.String,java.lang.String> mYAttributes
          Attributes, if needed.
 
Constructor Summary
AttributesReaderWrapper(java.util.HashMap<java.lang.String,java.lang.String> attributes)
          Constructor.
 
Method Summary
 NVImmutable getAttribute(java.lang.String n)
          Get an attribute.
 NVImmutable getAttribute(java.lang.String n, int index)
          Get an attribute from a multi-attribute by index.
 int getAttributeCount()
          Get attribute count.
 int getAttributeCount(java.lang.String n)
          Get the total attribute count for a specific name.
 java.util.Collection<java.lang.String> getAttributeNames()
          Get a collection of attribute names.
 java.util.Collection<NVImmutable> getAttributes()
          Get a collection of the attributes.
 java.util.Collection<NVImmutable> getAttributes(java.lang.String n)
          Get a collection of the attributes for the name.
 java.lang.String getAttributeValueToString(java.lang.String n)
          Get an attribute value rendered as a string.
 java.lang.String getAttributeValueToString(java.lang.String n, java.lang.String defaultValue)
          Get an attribute value rendered as a string.
 Attributes getPrivateSet()
          Get a private set that can be manipulated.
 boolean hasAttribute(java.lang.String n)
          Check if it has an attribute.
 boolean isMultivalueAllowed()
          Ask if multi-value is allowed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mYAttributes

protected java.util.HashMap<java.lang.String,java.lang.String> mYAttributes
Attributes, if needed.

Constructor Detail

AttributesReaderWrapper

public AttributesReaderWrapper(java.util.HashMap<java.lang.String,java.lang.String> attributes)
Constructor.

Method Detail

isMultivalueAllowed

public boolean isMultivalueAllowed()
Ask if multi-value is allowed.

Specified by:
isMultivalueAllowed in interface AttributeReader
Returns:
true if it is allowed.

getAttribute

public NVImmutable getAttribute(java.lang.String n)
Get an attribute. If the name of the attribute is null or the attribute does not exist, it should return null. If it is a multi, it will return the first.

Specified by:
getAttribute in interface AttributeReader
Parameters:
n - name of the attribute
Returns:
the value or null if not set.

getAttributeValueToString

public java.lang.String getAttributeValueToString(java.lang.String n)
Get an attribute value rendered as a string. If the name of the attribute is null or the attribute does not exist, it should return null. If it is a multi, it will return the first.

Specified by:
getAttributeValueToString in interface AttributeReader
Parameters:
n - name of the attribute
Returns:
the value or null if not set.

getAttributeValueToString

public java.lang.String getAttributeValueToString(java.lang.String n,
                                                  java.lang.String defaultValue)
Get an attribute value rendered as a string. If the name of the attribute is null or the attribute does not exist, it should return null. If it is a multi, it will return the first.

Specified by:
getAttributeValueToString in interface AttributeReader
Parameters:
n - name of the attribute
defaultValue - the value it will return if the name maps to a null.
Returns:
the value or null if not set.

hasAttribute

public boolean hasAttribute(java.lang.String n)
Check if it has an attribute. It will return false if the name is null.

Specified by:
hasAttribute in interface AttributeReader
Parameters:
n - name of the attribute
Returns:
true if it has the attribute, otherwise false.

getAttributes

public java.util.Collection<NVImmutable> getAttributes(java.lang.String n)
Get a collection of the attributes for the name.

Specified by:
getAttributes in interface AttributeReader
Parameters:
n - name of the attribute
Returns:
The collection.

getAttribute

public NVImmutable getAttribute(java.lang.String n,
                                int index)
Get an attribute from a multi-attribute by index. This will work with single value items, as long as the index is zero. This is not a fast operation, so don't use it in time critical areas. It will always return null rather than throw an exception.

Specified by:
getAttribute in interface AttributeReader
Parameters:
n - name of the attribute
index - the index of the attribute from 0.
Returns:
The NV or a null if it doesn't exist.

getAttributeNames

public java.util.Collection<java.lang.String> getAttributeNames()
Get a collection of attribute names.

Specified by:
getAttributeNames in interface AttributeReader
Returns:
The collection.

getAttributes

public java.util.Collection<NVImmutable> getAttributes()
Get a collection of the attributes.

This version is heavy.

Specified by:
getAttributes in interface AttributeReader
Returns:
The collection

getAttributeCount

public int getAttributeCount()
Get attribute count.

Specified by:
getAttributeCount in interface AttributeReader
Returns:
count, zero or greater

getAttributeCount

public int getAttributeCount(java.lang.String n)
Get the total attribute count for a specific name. It will return 0 if the name is not found.

Specified by:
getAttributeCount in interface AttributeReader
Parameters:
n - The name of the attribute.
Returns:
count, zero or greater

getPrivateSet

public Attributes getPrivateSet()
Get a private set that can be manipulated. This will make a copy and will not affect the original. This is a slow, heavy operation.

Specified by:
getPrivateSet in interface AttributeReader
Returns:
the HashSet of attributes.


Things.