org.jmythapi.impl
Class AData<E extends Enum<E>>

java.lang.Object
  extended by org.jmythapi.impl.AData<E>
Type Parameters:
E - the enumeration class describing the object properties.
All Implemented Interfaces:
Cloneable, IPropertyAware<E>, IVersionable
Direct Known Subclasses:
ADatabaseRow, AMythResponse

public abstract class AData<E extends Enum<E>>
extends Object
implements Cloneable, IPropertyAware<E>, IVersionable

A generic data object.

This object represents is a generic data object containing the following mandatory fields:

  1. Protocol Version:
    An constant describing the protocol-version the object was created for.
  2. Property Class:
    An enumeration class describing all properties of the data object.
  3. Property Values:
    A list of values for all properties.

This object is property-aware. getProperties() can be used to determine the properties, which are accessible by this object.


Field Summary
protected  Logger logger
          For logging.
protected  Class<E> propsClass
          An enumeration class defining all data properties.
protected  ProtocolVersion protoVersion
          The MythTV-protocol-version of this data object.
protected  List<String> respArgs
          The values of all data properties.
 
Constructor Summary
AData()
           
 
Method Summary
 Object clone()
          Creates a copy of this object.
protected abstract
<T> T
decodeProperty(Class<T> dataType, String dataValue)
           
protected abstract
<S,T> String
encodeProperty(Class<S> propObjectType, S propValue, Class<T> propStringType, String propDefaultValue)
           
 boolean equals(Object obj)
          Tests objects for equality.
abstract  EnumSet<E> getProperties()
          Returns all supported properties.
abstract  E getProperty(int idx)
          Gets the property for the given index.
 Class<E> getPropertyClass()
          Gets the enumeration class defining all available properties.
 int getPropertyCount()
          Gets the amount of available properties stored in this object.
abstract  int getPropertyIndex(E prop)
          Gets the index for the given property.
 EnumMap<E,String> getPropertyMap()
          Gets a map with all available properties and their values.
 String getPropertyValue(E prop)
          Gets the value for the given property.
 String getPropertyValue(int propIdx)
          Gets the value for the given property index.
<T> T
getPropertyValueObject(Class<T> dataType, E prop)
           
<T> T
getPropertyValueObject(E prop)
          Gets the property value for a given property and converts it into the property data-type.
 List<String> getPropertyValues()
          Returns all property values as strings.
 ProtocolVersion getVersionNr()
          Gets the protocol-version of an object.
 int hashCode()
          Generates a hashCode for this object.
protected  void init(ProtocolVersion protoVersion, Class<E> propsClass, List<String> data)
          Initializes this object with all mandatory values.
protected  void postProcessArguments()
           
 String setPropertyValue(E prop, String value)
          Sets the property value for the given property.
 String setPropertyValue(int propIdx, String value)
          Sets the property value for the given property.
<S,T> void
setPropertyValueObject(E prop, S propValue)
          Sets the property value for the given property.
 String toString()
          Returns the content of this data object as a formatted string.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected Logger logger
For logging.


protoVersion

protected ProtocolVersion protoVersion
The MythTV-protocol-version of this data object.


propsClass

protected Class<E extends Enum<E>> propsClass
An enumeration class defining all data properties.


respArgs

protected List<String> respArgs
The values of all data properties.

This list has a fixed size.

Constructor Detail

AData

public AData()
Method Detail

init

protected void init(ProtocolVersion protoVersion,
                    Class<E> propsClass,
                    List<String> data)
Initializes this object with all mandatory values.

Parameters:
protoVersion - the protocol version of this object
propsClass - the enumeration class, containing all properties of this object
data - the property values of this object

postProcessArguments

protected void postProcessArguments()

getVersionNr

public ProtocolVersion getVersionNr()
Gets the protocol-version of an object.

Specified by:
getVersionNr in interface IVersionable
Returns:
the version a given object was created for.

getPropertyClass

public Class<E> getPropertyClass()
Description copied from interface: IPropertyAware
Gets the enumeration class defining all available properties.

Specified by:
getPropertyClass in interface IPropertyAware<E extends Enum<E>>
Returns:
the enumeration class

getPropertyCount

public int getPropertyCount()
Description copied from interface: IPropertyAware
Gets the amount of available properties stored in this object.

Protocol Version Hint:

Depending on the used protocol version the amount of available properties may be different.

Specified by:
getPropertyCount in interface IPropertyAware<E extends Enum<E>>
Returns:
the amount of properties

getPropertyValues

public List<String> getPropertyValues()
Description copied from interface: IPropertyAware
Returns all property values as strings.

Specified by:
getPropertyValues in interface IPropertyAware<E extends Enum<E>>
Returns:
all properties as strings

getPropertyValue

public String getPropertyValue(int propIdx)
Description copied from interface: IPropertyAware
Gets the value for the given property index.

Protocol Version Hint:

Depending on the current protocol version, a different property may be located on the same index.

Usage example:


    // reads the recorder-info property "hostport" and 
    String port = recorderInfo.getPropertyValue(IRecorderInfo.Props.HOSTPORT);
 

Specified by:
getPropertyValue in interface IPropertyAware<E extends Enum<E>>
Parameters:
propIdx - the index of the property for which the value should be returned
Returns:
the property value

getPropertyValue

public String getPropertyValue(E prop)
Description copied from interface: IPropertyAware
Gets the value for the given property.

Internally this method uses IPropertyAware.getPropertyIndex(Enum), to determine the position of the value in the value list.

Specified by:
getPropertyValue in interface IPropertyAware<E extends Enum<E>>
Parameters:
prop - the desired property
Returns:
the property value or null if no value is available or the given property is not supported in the given protocol-version.

getPropertyValueObject

public <T> T getPropertyValueObject(E prop)
Description copied from interface: IPropertyAware
Gets the property value for a given property and converts it into the property data-type.

The data type conversion is done using methods of the utility class EncodingUtils.

Protocol Version Hint:

If the requested property is not supported in the current protocol version, null is returned as value.

Usage example:


    // reads the recorder-info property "hostport" and 
    // converts it into an object of type Integer.
    Integer port = recorderInfo.getPropertyValueObject(IRecorderInfo.Props.HOSTPORT);
 

Specified by:
getPropertyValueObject in interface IPropertyAware<E extends Enum<E>>
Type Parameters:
T - the property data type
Parameters:
prop - the desired property
Returns:
the converted property value or null if no value is available or the given property is not supported in the given protocol-version.
See Also:
EncodingUtils.decodeString(java.lang.Class, org.jmythapi.protocol.ProtocolVersion, java.lang.String)

getPropertyValueObject

public <T> T getPropertyValueObject(Class<T> dataType,
                                    E prop)

decodeProperty

protected abstract <T> T decodeProperty(Class<T> dataType,
                                        String dataValue)

setPropertyValue

public String setPropertyValue(int propIdx,
                               String value)
Description copied from interface: IPropertyAware
Sets the property value for the given property.

Protocol Version Hint:

Depending on the current protocol version, a different property may be located on the same index.

Specified by:
setPropertyValue in interface IPropertyAware<E extends Enum<E>>
Parameters:
propIdx - the index of the argument, whose value should be set.
Depending on the current protocol version the same index may address different properties.
value - the new value
Returns:
the old value

setPropertyValue

public String setPropertyValue(E prop,
                               String value)
Description copied from interface: IPropertyAware
Sets the property value for the given property.

Protocol Version Hint:

If the given property is not supported for the current protocol version, than calling this method has no effect.

Specified by:
setPropertyValue in interface IPropertyAware<E extends Enum<E>>
Parameters:
prop - the argument, whose value should be set
value - the new value of the argument
Returns:
the previous value of the argument

setPropertyValueObject

public <S,T> void setPropertyValueObject(E prop,
                                         S propValue)
Description copied from interface: IPropertyAware
Sets the property value for the given property.

Protocol Version Hint:

If the given property is not supported for the current protocol version, than calling this method has no effect.

Specified by:
setPropertyValueObject in interface IPropertyAware<E extends Enum<E>>
Type Parameters:
S - the type of the property value
T - the to-string type of the property value
Parameters:
prop - the property
propValue - the property value as object

encodeProperty

protected abstract <S,T> String encodeProperty(Class<S> propObjectType,
                                               S propValue,
                                               Class<T> propStringType,
                                               String propDefaultValue)

getPropertyMap

public EnumMap<E,String> getPropertyMap()
Description copied from interface: IPropertyAware
Gets a map with all available properties and their values.

Protocol Version Hint:

Depending on the protocol version a different set of properties may be returned.

Specified by:
getPropertyMap in interface IPropertyAware<E extends Enum<E>>
Returns:
a map containing all properties and their values.
See Also:
EnumUtils.getEnums(java.lang.Class, org.jmythapi.protocol.ProtocolVersion)

getProperty

public abstract E getProperty(int idx)
Description copied from interface: IPropertyAware
Gets the property for the given index.

This is the reverse operation of IPropertyAware.getPropertyIndex(Enum).

Protocol Version Hint:

Depending on the used protocol version a specific property may be located at a different position.

Usage example:


    for(int i=0; i < object.getPropertyCount(); i++) {
       System.out.println(String.format(
          "Property %02d: %s",
          i, object.getProperty(i)
       ));
    }
 

Specified by:
getProperty in interface IPropertyAware<E extends Enum<E>>
Parameters:
idx - the position within the property array
Returns:
the enumeration constant

getPropertyIndex

public abstract int getPropertyIndex(E prop)
Description copied from interface: IPropertyAware
Gets the index for the given property.

This is the reverse operation of IPropertyAware.getProperty(int)

Protocol Version Hint:

If the given property is not supported in the current protocol version, -1 is returned.

Usage example:


    EnumSet<IProgramInfo.Props> props = program.getProperties();
    for(IProgramInfo.Props prop : props) {
       System.out.println(String.format(
          "Property %s is stored at position %d.",
          prop.name(), program.getPropertyIndex(prop)
       ));
    }
 

Specified by:
getPropertyIndex in interface IPropertyAware<E extends Enum<E>>
Parameters:
prop - the property for which the index should be returned
Returns:
the index of the property or -1, if a property is not supported in the currently used protocol version.

getProperties

public abstract EnumSet<E> getProperties()
Description copied from interface: IPropertyAware
Returns all supported properties.

Protocol Version Hint:

Depending on the protocol version, a different set of properties my be returned.

Specified by:
getProperties in interface IPropertyAware<E extends Enum<E>>
Returns:
all properties supported in the current protocol version

clone

public Object clone()
             throws CloneNotSupportedException
Creates a copy of this object.

Overrides:
clone in class Object
Returns:
a copy of this object
Throws:
CloneNotSupportedException

equals

public boolean equals(Object obj)
Tests objects for equality.

Data objects are seen to be equal if the response to the following function calls are equal:

  1. Object.getClass()
  2. getVersionNr()
  3. getPropertyClass()
  4. getPropertyValues()

Overrides:
equals in class Object

hashCode

public int hashCode()
Generates a hashCode for this object.

This is required when using this object as a key in a map.

Overrides:
hashCode in class Object
Returns:
the hash code

toString

public String toString()

Returns the content of this data object as a formatted string.

E.g.
 <0>TOTAL_RAM_MB: 1002 | <1>FREE_RAM_MB: 474 | <2>TOTAL_VM_MB: 853 | <3>FREE_VM_MB: 853
 

Overrides:
toString in class Object


Copyright © 2008-2013. All Rights Reserved.