Media Authoring
with Java API

tv.amwa.maj.embeddable
Class TimeStruct

java.lang.Object
  extended by tv.amwa.maj.embeddable.TimeStruct
All Implemented Interfaces:
Serializable, Cloneable, MAJCommon, TimeStruct

public final class TimeStruct
extends Object
implements TimeStruct, Serializable, Cloneable, MAJCommon

Implementation of the time component of date and time values specified according to Coordinated Universal Time (UTC), including hour, minute, second and 1/100th of a second. The time structure is itself a component of a timestamp.

This implementation is backed by a Calendar.

Author:
Richard Cartwright
See Also:
DateStruct, TimeStamp, TypeDefinitionRecord.TimeStruct, Serialized Form

Constructor Summary
TimeStruct()
          Create a new time structure set to the current time.
TimeStruct(byte hour, byte minute, byte second)
          Create a time value from its hour, minute and second component parts.
TimeStruct(byte hour, byte minute, byte second, byte fraction)
          Create a time value from all of its component parts.
TimeStruct(Calendar timeItem)
          Create a new time structure from the given calendar value.
 
Method Summary
static TimeStruct castFromInterface(TimeStruct alien)
          Cast a value the implements the TimeStruct interface to concrete value of this implementation.
 TimeStruct clone()
          Creates a cloned deep copy of this embeddable value.
 boolean equals(Object o)
          Tests to see if the value of two time structures are equal.
 byte getFraction()
          Returns the fractions of a second component of the time value.
 byte getHour()
          Returns the hours component of the time value.
 byte getMinute()
          Returns the minutes component of the time value.
 byte getSecond()
          Returns the seconds component of the time value.
 Calendar getTimeValue()
          Returns a copy of the calendar value used to represent the time value.
 int hashCode()
          Returns a hash code value for this embeddable object.
static TimeStruct parseTimeStruct(String time)
          Creates a new time value from a UTC-style string.
 void setFraction(byte fraction)
          Sets the fractions of a second component of the time value, in the range 0 to 99.
 void setHour(byte hour)
          Sets the hours component of the time value, in the range 0 to 23.
 void setMinute(byte minute)
          Sets the minutes component of the time value, in the range 0 to 59.
 void setPropertiesFromInterface(TimeStruct castFrom)
          Set the properties of this value from those available in the given value, which is specified by the time structure interface.
 void setSecond(byte second)
          Sets the second component of the time value, normally in the range 0 to 59.
 void setTime(byte hour, byte minute, byte second)
          Set the values of the time structure using an hour, minute and second values provided.
 void setTime(byte hour, byte minute, byte second, byte fraction)
          Sets all the values of the time structure using the hour, minute, second and fraction of a second values provided.
 void setTimeValue(Calendar timeItem)
          Sets the value of the time structure from the given calendar value.
 String toString()
          Creates a UTC-style string representation of the time structure's value, including the timezone offset.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeStruct

public TimeStruct(byte hour,
                  byte minute,
                  byte second,
                  byte fraction)
           throws IllegalArgumentException

Create a time value from all of its component parts.

Parameters:
hour - Hour component of the time value, in the inclusive range 0 to 23.
minute - Minute component of the time value, in the inclusive range 0 to 59.
second - Second component of the time value, normally in the inclusive range 0 to 59.
fraction - 1/100th of a second component of the time value, in the inclusive range 0 to 99.
Throws:
IllegalArgumentException - One or more of the parameters is out of range.

TimeStruct

public TimeStruct(byte hour,
                  byte minute,
                  byte second)
           throws IllegalArgumentException

Create a time value from its hour, minute and second component parts. The fraction of a second is set to 0.

Parameters:
hour - Hour component of the time value, in the inclusive range 0 to 23.
minute - Minute component of the time value, in the inclusive range 0 to 59.
second - Second component of the time value, normally in the inclusive range 0 to 59.
Throws:
IllegalArgumentException - One or more of the parameters is out of range.

TimeStruct

public TimeStruct(Calendar timeItem)
           throws NullPointerException,
                  IllegalArgumentException

Create a new time structure from the given calendar value.

Parameters:
timeItem - Calendar item to use to create a new time structure.
Throws:
NullPointerException - Argument is null.
IllegalArgumentException - The given calendar value contains out-of-range values.

TimeStruct

public TimeStruct()

Create a new time structure set to the current time.

Method Detail

castFromInterface

public static final TimeStruct castFromInterface(TimeStruct alien)
                                          throws NullPointerException

Cast a value the implements the TimeStruct 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 alien value argument is null.
See Also:
setPropertiesFromInterface(tv.amwa.maj.record.TimeStruct)

setPropertiesFromInterface

public final void setPropertiesFromInterface(TimeStruct castFrom)
                                      throws NullPointerException

Set the properties of this value from those available in the given value, which is specified by the time structure interface.

Parameters:
castFrom - Value to extract properties from.
Throws:
NullPointerException - The given value to use to set this value is null.
See Also:
castFromInterface(tv.amwa.maj.record.TimeStruct)

getFraction

public final byte getFraction()
Description copied from interface: TimeStruct

Returns the fractions of a second component of the time value.

Specified by:
getFraction in interface TimeStruct
Returns:
Fractions of a second component of the time value.

setFraction

public final void setFraction(byte fraction)
                       throws IllegalArgumentException
Description copied from interface: TimeStruct

Sets the fractions of a second component of the time value, in the range 0 to 99.

Specified by:
setFraction in interface TimeStruct
Parameters:
fraction - Fractions of a second component of the time value.
Throws:
IllegalArgumentException - The fractions of a second value is outside the acceptable range.

getHour

public final byte getHour()
Description copied from interface: TimeStruct

Returns the hours component of the time value.

Specified by:
getHour in interface TimeStruct
Returns:
Hours component of the time value.

setHour

public final void setHour(byte hour)
                   throws IllegalArgumentException
Description copied from interface: TimeStruct

Sets the hours component of the time value, in the range 0 to 23.

Specified by:
setHour in interface TimeStruct
Parameters:
hour - Hours component of the time value.
Throws:
IllegalArgumentException - The hours value is outside the acceptable range.

getMinute

public final byte getMinute()
Description copied from interface: TimeStruct

Returns the minutes component of the time value.

Specified by:
getMinute in interface TimeStruct
Returns:
Minutes component of the time value.

setMinute

public final void setMinute(byte minute)
                     throws IllegalArgumentException
Description copied from interface: TimeStruct

Sets the minutes component of the time value, in the range 0 to 59.

Specified by:
setMinute in interface TimeStruct
Parameters:
minute - Minutes component of the time value.
Throws:
IllegalArgumentException - The minute value is outside the acceptable range.

getSecond

public final byte getSecond()
Description copied from interface: TimeStruct

Returns the seconds component of the time value. Note that advanced implementations may allow for very occasional leap second values of 60 or 61.

Specified by:
getSecond in interface TimeStruct
Returns:
Seconds component of the time value.

setSecond

public final void setSecond(byte second)
                     throws IllegalArgumentException
Description copied from interface: TimeStruct

Sets the second component of the time value, normally in the range 0 to 59. Note that advanced implementations may allow for very occasional leap second values of 60 or 61.

Specified by:
setSecond in interface TimeStruct
Parameters:
second - Seconds component of the time value.
Throws:
IllegalArgumentException - The second value is outside the acceptable range.

setTime

public final void setTime(byte hour,
                          byte minute,
                          byte second)
                   throws IllegalArgumentException
Description copied from interface: TimeStruct

Set the values of the time structure using an hour, minute and second values provided. The fraction of the second represented is set to be 0.

Specified by:
setTime in interface TimeStruct
Parameters:
hour - Hours component of the time value, represented in 24-hour clock format.
minute - Minutes component of the time value.
second - Seconds component of the time value.
Throws:
IllegalArgumentException - One or more of the values is outside the acceptable range for a time value.

setTime

public final void setTime(byte hour,
                          byte minute,
                          byte second,
                          byte fraction)
                   throws IllegalArgumentException
Description copied from interface: TimeStruct

Sets all the values of the time structure using the hour, minute, second and fraction of a second values provided.

Specified by:
setTime in interface TimeStruct
Parameters:
hour - Hours component of the time value, represented in 24-hour clock format.
minute - Minutes component of the time value.
second - Seconds component of the time value.
fraction - Fractions of a second component of the time value.
Throws:
IllegalArgumentException - One or more of the values is outside the acceptable range for a time value.

setTimeValue

public final void setTimeValue(Calendar timeItem)
                        throws NullPointerException,
                               IllegalArgumentException

Sets the value of the time structure from the given calendar value.

Parameters:
timeItem - Calendar value to set for this time structure.
Throws:
NullPointerException - Argument is null.
IllegalArgumentException - The given calendar value contains one or more fields that are out of range.

getTimeValue

public final Calendar getTimeValue()

Returns a copy of the calendar value used to represent the time value.

Returns:
Copy of the calendar value used to represent this time structure.

toString

public final String toString()

Creates a UTC-style string representation of the time structure's value, including the timezone offset. The format used is "HH:mm:ss.SSSZ", where:

Specified by:
toString in interface MAJCommon
Overrides:
toString in class Object
Returns:
String representation of the time value according to the local time zone.
See Also:
Object.toString(), SimpleDateFormat

equals

public final boolean equals(Object o)

Tests to see if the value of two time structures are equal. Two time values are equal if and only each of their hour, minute, second and fraction of a second values are equal respectively.

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(java.lang.Object)

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()

clone

public final TimeStruct 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()

parseTimeStruct

public static final TimeStruct parseTimeStruct(String time)
                                        throws ParseException,
                                               NullPointerException

Creates a new time value from a UTC-style string. The expected format of the string is "HH:mm:ss.SSSZ", where:

Note that if a timezone value different from UTC ("+0000"), the time value will be converted to its UTC equivalent.

Parameters:
time - UTC-style string time value.
Returns:
Time structure representing the given string time value.
Throws:
ParseException - The given value could not be converted into a time structure value.
NullPointerException - Argument 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.