Media Authoring
with Java API

tv.amwa.maj.embeddable
Class VersionType

java.lang.Object
  extended by tv.amwa.maj.embeddable.VersionType
All Implemented Interfaces:
Serializable, Cloneable, Comparable<VersionType>, MAJCommon, XMLSerializable, VersionType

public final class VersionType
extends Object
implements VersionType, Serializable, XMLSerializable, Comparable<VersionType>, Cloneable, MAJCommon

Implements a 2-byte unsigned version number, consisting of a major and minor component.

A persistent representation of a product version may be represented by the following columns in a database:

     'VersionType_major' tinyint(4) NOT NULL, 
     'VersionType_minor' tinyint(4) NOT NULL
 

Author:
Richard Cartwright
See Also:
ProductVersion, Header.getFileRevision(), PluginDefinition, Serialized Form

Constructor Summary
VersionType()
          Create a new version number, set to "0.0".
VersionType(byte major, byte minor)
          Create a version number from its major and minor component.
 
Method Summary
 void appendXMLChildren(Node parent)
          Append child elements to the given parent node to serialize the value of an object to an XML fragment.
static VersionType castFromInterface(VersionType alien)
          Cast a value the implements the VersionType interface to concrete value of this implementation.
 VersionType clone()
          Creates a cloned deep copy of this embeddable value.
 int compareTo(VersionType o)
          Compare this version number to the given version number.
 boolean equals(Object o)
          Tests to see if the given object is equal to this embeddable value.
static String format(VersionType version)
          Format a version number as a string.
 byte getMajor()
          Returns the major component of the version number.
 byte getMinor()
          Returns the minor component of the version number.
 int hashCode()
          Returns a hash code value for this embeddable object.
static VersionType parseVersion(String versionAsString)
          Parse a string representation of a version number and create a value of this class.
 void setMajor(byte major)
          Sets the major component of the version number.
 void setMinor(byte minor)
          Sets the minor component of the version number.
 void setPropertiesFromInterface(VersionType castFrom)
          Set the properties of this value from another value that implements that implements the VersionType interface.
 String toString()
          Formats the version number as a string representation using an XML element.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VersionType

public VersionType(@UInt8
                   byte major,
                   @UInt8
                   byte minor)

Create a version number from its major and minor component.

Parameters:
major - Major component of version number.
minor - Minor component of version number.

VersionType

public VersionType()

Create a new version number, set to "0.0".

Method Detail

castFromInterface

public static final VersionType castFromInterface(VersionType alien)
                                           throws NullPointerException

Cast a value the implements the VersionType interface to concrete value of this implementation.

Parameters:
alien - Value to cast to a concrete instance.
Returns:
Concrete version of the given interface.
Throws:
NullPointerException - The given version number value is null.

setPropertiesFromInterface

public final void setPropertiesFromInterface(VersionType castFrom)
                                      throws NullPointerException

Set the properties of this value from another value that implements that implements the VersionType interface.

Parameters:
castFrom - Value to use to set the version number.
Throws:
NullPointerException - The given version number is null.

getMajor

public final byte getMajor()
Description copied from interface: VersionType

Returns the major component of the version number.

Specified by:
getMajor in interface VersionType
Returns:
Major component of the version number.

setMajor

public final void setMajor(byte major)
Description copied from interface: VersionType

Sets the major component of the version number.

Specified by:
setMajor in interface VersionType
Parameters:
major - Major component of the version number.


getMinor

public final byte getMinor()
Description copied from interface: VersionType

Returns the minor component of the version number.

Specified by:
getMinor in interface VersionType
Returns:
Minor component of the version number.

setMinor

public void setMinor(byte minor)
Description copied from interface: VersionType

Sets the minor component of the version number.

Specified by:
setMinor in interface VersionType
Parameters:
minor - Minor component of the version number.

toString

public final String toString()

Formats the version number as a string representation using an XML element. For example:

<Version>1.1</Version>

Note that "2.10" is a later version than "2.9".

Specified by:
toString in interface MAJCommon
Overrides:
toString in class Object
Returns:
String representation of this embeddable value.
See Also:
Object.toString()

parseVersion

public static final VersionType parseVersion(String versionAsString)
                                      throws NullPointerException,
                                             NumberFormatException

Parse a string representation of a version number and create a value of this class. The value must contain a '.' to be valid. The major and minor parts of the version numbers, before and after the dot respectively, must range between 0 and 255.

Parameters:
versionAsString - String representation of a version number.
Returns:
Version number value.
Throws:
NullPointerException - The given version number string is null.
NumberFormatException - The given version number string causes parse or number range errors that prevent it from being converted into a version number value.

hashCode

public final int hashCode()
Description copied from interface: MAJCommon

Returns a hash code value for this embeddable object.

Specified by:
hashCode in interface MAJCommon
Overrides:
hashCode in class Object
Returns:
Hash code value for this embeddable object.
See Also:
Object.hashCode()

compareTo

public final int compareTo(VersionType o)
                    throws NullPointerException

Compare this version number to the given version number.

Specified by:
compareTo in interface Comparable<VersionType>
Parameters:
o - Version number to compare with this one.
Returns:
A value of -1 if this version number is less than the given one, 1 if this version is greater and 0 if the two version numbers and equal.
Throws:
NullPointerException - The given value is null.
See Also:
Comparable.compareTo(Object)

equals

public final boolean equals(Object o)
Description copied from interface: MAJCommon

Tests to see if the given object is equal to this embeddable value. To be equal, the given value must be not null, share the same interface to its value and each of the properties of the value must each be equal.

Specified by:
equals in interface MAJCommon
Overrides:
equals in class Object
Parameters:
o - Object to test for equality with.
Returns:
Is the given object equals to this value?
See Also:
Object.equals(Object)

clone

public final VersionType clone()
Description copied from interface: MAJCommon

Creates a cloned deep copy of this embeddable value. The clone will be initialized to have the same value as this value but exists independently from then on. Changes to this value will not effect the clone and changes to the clone will not effect this. MAJ API clones are true deep clones with no shared references to areas of memory within the original.

This method does not throw a CloneNotSupportedException as all embeddable values must implement the Cloneable interface.

Specified by:
clone in interface MAJCommon
Overrides:
clone in class Object
Returns:
Independent clone of this value, which is a deep copy.
See Also:
Object.clone()

appendXMLChildren

public final void appendXMLChildren(Node parent)
Description copied from interface: XMLSerializable

Append child elements to the given parent node to serialize the value of an object to an XML fragment. Methods of the XMLBuilder class are provided to help with this process.

Specified by:
appendXMLChildren in interface XMLSerializable
Parameters:
parent - XML parent element to append child nodes to.

format

public static final String format(VersionType version)
                           throws NullPointerException

Format a version number as a string.

Parameters:
version - Version number value to format as a string.
Returns:
Version number formatted as a string.
Throws:
NullPointerException - Version value is null.

Media Authoring
with Java API

(c) 2007-2008 Richard Cartwright, all rights reserved. Subject to the terms of the AAF SDK Public Source License.