FileDocCategorySizeDatePackage
AbstractDataType.javaAPI DocJaudiotagger 2.0.412694Wed Mar 30 16:12:12 BST 2011org.jaudiotagger.tag.datatype

AbstractDataType

public abstract class AbstractDataType extends Object
Represents a field/data type that can be held within a frames body, these map loosely onto Section 4. ID3v2 frame overview at http://www.id3.org/id3v2.4.0-structure.txt

Fields Summary
protected static final String
TYPE_ELEMENT
public static Logger
logger
protected Object
value
Holds the data
protected String
identifier
Holds the key such as "Text" or "PictureType", the naming of keys are fairly arbitary but are intended to make it easier to for the developer, the keys themseleves are not written to the tag.
protected org.jaudiotagger.tag.id3.AbstractTagFrameBody
frameBody
Holds the calling body, allows an datatype to query other objects in the body such as the Text Encoding of the frame
protected int
size
Holds the size of the data in file when read/written
Constructors Summary
protected AbstractDataType(String identifier, org.jaudiotagger.tag.id3.AbstractTagFrameBody frameBody)
Construct an abstract datatype identified by identifier and linked to a framebody without setting an initial value.

param
identifier to allow retrieval of this datatype by name from framebody
param
frameBody that the dataype is associated with


                                               
        
    
        this.identifier = identifier;
        this.frameBody  = frameBody;
    
protected AbstractDataType(String identifier, org.jaudiotagger.tag.id3.AbstractTagFrameBody frameBody, Object value)
Construct an abstract datatype identified by identifier and linked to a framebody initilised with a value

param
identifier to allow retrieval of this datatype by name from framebody
param
frameBody that the dataype is associated with
param
value of this DataType

        this.identifier = identifier;
        this.frameBody  = frameBody;
        setValue(value);
    
public AbstractDataType(AbstractDataType copyObject)
This is used by subclasses, to clone the data within the copyObject

TODO:It seems to be missing some of the more complex value types.

param
copyObject

        // no copy constructor in super class
        this.identifier = copyObject.identifier;
        if (copyObject.value == null)
        {
            this.value = null;
        }
        else if (copyObject.value instanceof String)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Boolean)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Byte)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Character)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Double)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Float)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Integer)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Long)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof Short)
        {
            this.value = copyObject.value;
        }
        else if(copyObject.value instanceof MultipleTextEncodedStringNullTerminated.Values)
        {
            this.value = copyObject.value;
        }
        else if(copyObject.value instanceof PairedTextEncodedStringNullTerminated.ValuePairs)
        {
            this.value = copyObject.value;
        }
        else if(copyObject.value instanceof PartOfSet.PartOfSetValue)
        {
            this.value = copyObject.value;
        }
        else if (copyObject.value instanceof boolean[])
        {
            this.value = ((boolean[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof byte[])
        {
            this.value = ((byte[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof char[])
        {
            this.value = ((char[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof double[])
        {
            this.value = ((double[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof float[])
        {
            this.value = ((float[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof int[])
        {
            this.value = ((int[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof long[])
        {
            this.value = ((long[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof short[])
        {
            this.value = ((short[]) copyObject.value).clone();
        }
        else if (copyObject.value instanceof Object[])
        {
            this.value = ((Object[]) copyObject.value).clone();
        }
        else
        {
            throw new UnsupportedOperationException("Unable to create copy of class " + copyObject.getClass());
        }
    
Methods Summary
public voidcreateStructure()
Return String Representation of Datatype *

        MP3File.getStructureFormatter().addElement(identifier, getValue().toString());
    
public booleanequals(java.lang.Object obj)

param
obj
return
whether this and obj are deemed equivalent

        if(this==obj)
        {
            return true;
        }

        if (!(obj instanceof AbstractDataType))
        {
            return false;
        }
        AbstractDataType object = (AbstractDataType) obj;
        if (!this.identifier.equals(object.identifier))
        {
            return false;
        }
        if ((this.value == null) && (object.value == null))
        {
            return true;
        }
        else if ((this.value == null) || (object.value == null))
        {
            return false;
        }
        // boolean[]
        if (this.value instanceof boolean[] && object.value instanceof boolean[])
        {
            if (!Arrays.equals((boolean[]) this.value, (boolean[]) object.value))
            {
                return false;
            }
            // byte[]
        }
        else if (this.value instanceof byte[] && object.value instanceof byte[])
        {
            if (!Arrays.equals((byte[]) this.value, (byte[]) object.value))
            {
                return false;
            }
            // char[]
        }
        else if (this.value instanceof char[] && object.value instanceof char[])
        {
            if (!Arrays.equals((char[]) this.value, (char[]) object.value))
            {
                return false;
            }
            // double[]
        }
        else if (this.value instanceof double[] && object.value instanceof double[])
        {
            if (!Arrays.equals((double[]) this.value, (double[]) object.value))
            {
                return false;
            }
            // float[]
        }
        else if (this.value instanceof float[] && object.value instanceof float[])
        {
            if (!Arrays.equals((float[]) this.value, (float[]) object.value))
            {
                return false;
            }
            // int[]
        }
        else if (this.value instanceof int[] && object.value instanceof int[])
        {
            if (!Arrays.equals((int[]) this.value, (int[]) object.value))
            {
                return false;
            }
            // long[]
        }
        else if (this.value instanceof long[] && object.value instanceof long[])
        {
            if (!Arrays.equals((long[]) this.value, (long[]) object.value))
            {
                return false;
            }
            // Object[]
        }
        else if (this.value instanceof Object[] && object.value instanceof Object[])
        {
            if (!Arrays.equals((Object[]) this.value, (Object[]) object.value))
            {
                return false;
            }
            // short[]
        }
        else if (this.value instanceof short[] && object.value instanceof short[])
        {
            if (!Arrays.equals((short[]) this.value, (short[]) object.value))
            {
                return false;
            }
        }
        else if (!this.value.equals(object.value))
        {
            return false;
        }
        return true;
    
public org.jaudiotagger.tag.id3.AbstractTagFrameBodygetBody()
Get the framebody associated with this datatype

return
the framebody that this datatype is associated with

        return frameBody;
    
public java.lang.StringgetIdentifier()
Return the key as declared by the frame bodies datatype list

return
the key used to reference this datatype from a framebody

        return identifier;
    
public abstract intgetSize()
This defines the size in bytes of the datatype being held when read/written to file.

return
the size in bytes of the datatype

public java.lang.ObjectgetValue()
Get value held by this Object

return
value held by this Object

        return value;
    
public abstract voidreadByteArray(byte[] arr, int offset)
This is the starting point for reading bytes from the file into the ID3 datatype starting at offset. This class must be overridden

param
arr
param
offset
throws
org.jaudiotagger.tag.InvalidDataTypeException

public final voidreadByteArray(byte[] arr)
Simplified wrapper for reading bytes from file into Object. Used for reading Strings, this class should be overridden for non String Objects

param
arr
throws
org.jaudiotagger.tag.InvalidDataTypeException

        readByteArray(arr, 0);
    
public voidsetBody(org.jaudiotagger.tag.id3.AbstractTagFrameBody frameBody)
Set the framebody that this datatype is associated with

param
frameBody

        this.frameBody = frameBody;
    
public voidsetValue(java.lang.Object value)
Set the value held by this datatype, this is used typically used when the user wants to modify the value in an existing frame.

param
value

        this.value = value;
    
public abstract byte[]writeByteArray()
Starting point write ID3 Datatype back to array of bytes. This class must be overridden.

return
the array of bytes representing this datatype that should be written to file