Media Authoring
with Java API

tv.amwa.maj.embeddable
Class TimeStamp

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

public final class TimeStamp
extends Object
implements TimeStamp, Serializable, XMLSerializable, Cloneable, MAJCommon

Implementation of a date and time in UTC (Coordinated Universal Time). The value is made up of a date and time structure.

The internal representation of this value is a Calendar value.

A time stamp structure is represented in the database by a column of type date:

     `Date` date
 

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

Constructor Summary
TimeStamp()
          Create a new time stamp value to represent the time now.
TimeStamp(Calendar calendarItem)
          Create a new time stamp from the given calendar value.
TimeStamp(DateStruct date, TimeStruct time)
          Create a new time stamp from the given date and time structures.
 
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 TimeStamp castFromInterface(TimeStamp alien)
          Cast a value the implements the TimeStamp interface to concrete value of this implementation.
 TimeStamp clone()
          Creates a cloned deep copy of this embeddable value.
 boolean equals(Object o)
          Checks for the equality of UTC values only and not the exact equality of the underlying calendar value representation.
 DateStruct getDate()
          Returns the date component of the time stamp.
 TimeStruct getTime()
          Returns the time component of the time stamp.
 Calendar getTimeStamp()
          Returns a calendar value representing this time stamp.
 int hashCode()
          Returns a hash code value for this embeddable object.
static TimeStamp parseTimeStamp(String stamp)
          Create a time stamp from a string that is formatted according to the UTC standards.
 void setDate(DateStruct date)
          Sets the date component of the time stamp.
 void setPropertiesFromInterface(TimeStamp castFrom)
          Set the properties of this value from another value that implements that implements the TimeStamp interface.
 void setStamp(DateStruct date, TimeStruct time)
          Simultaneously sets the date and time components of the time stamp.
 void setTime(TimeStruct time)
          Sets the time component of the time stamp.
 void setTimeStamp(Calendar timestampItem)
          Set the value of this time stamp using a Calendar value.
 String toString()
          Formats the string according ISO 8601 and as a UTC value.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeStamp

public TimeStamp()

Create a new time stamp value to represent the time now.


TimeStamp

public TimeStamp(Calendar calendarItem)
          throws IllegalArgumentException,
                 NullPointerException

Create a new time stamp from the given calendar value.

Parameters:
calendarItem - Calendar value to use to create a new time stamp.
Throws:
IllegalArgumentException - The resulting time stamp value would not be valid.
NullPointerException - Argument is null.

TimeStamp

public TimeStamp(DateStruct date,
                 TimeStruct time)
          throws NullPointerException,
                 IllegalArgumentException

Create a new time stamp from the given date and time structures.

Parameters:
date - Date to set for the new time stamp.
time - Time to set for the new time stamp.
Throws:
NullPointerException - One or more of the arguments is null.
IllegalArgumentException - The resulting time stamp value would not be valid.
Method Detail

castFromInterface

public static final TimeStamp castFromInterface(TimeStamp alien)
                                         throws NullPointerException

Cast a value the implements the TimeStamp 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 - Argument is null.

setPropertiesFromInterface

public final void setPropertiesFromInterface(TimeStamp castFrom)
                                      throws NullPointerException

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

Parameters:
castFrom - Value to use to set this timecode value.
Throws:
NullPointerException - The given time stamp value is null.

getDate

public final DateStruct getDate()
Description copied from interface: TimeStamp

Returns the date component of the time stamp.

Specified by:
getDate in interface TimeStamp
Returns:
Date component of the time stamp.

setDate

public final void setDate(DateStruct date)
                   throws NullPointerException,
                          IllegalArgumentException
Description copied from interface: TimeStamp

Sets the date component of the time stamp.

Specified by:
setDate in interface TimeStamp
Parameters:
date - Date component of the time stamp.
Throws:
NullPointerException - The given data structure is null.
IllegalArgumentException - The given date is not valid.

getTime

public final TimeStruct getTime()
Description copied from interface: TimeStamp

Returns the time component of the time stamp.

Specified by:
getTime in interface TimeStamp
Returns:
Time component of the time stamp.

setTime

public final void setTime(TimeStruct time)
                   throws NullPointerException,
                          IllegalArgumentException
Description copied from interface: TimeStamp

Sets the time component of the time stamp.

Specified by:
setTime in interface TimeStamp
Parameters:
time - Time component of the time stamp.
Throws:
NullPointerException - The given time structure is null.
IllegalArgumentException - The given time is not valid.

setStamp

public final void setStamp(DateStruct date,
                           TimeStruct time)
                    throws NullPointerException,
                           IllegalArgumentException
Description copied from interface: TimeStamp

Simultaneously sets the date and time components of the time stamp.

Specified by:
setStamp in interface TimeStamp
Parameters:
date - Date component of the time stamp.
time - Time component of the time stamp.
Throws:
NullPointerException - One or both of the given data or time structures are null.
IllegalArgumentException - One or both of the given date or time values are not valid.

getTimeStamp

public final Calendar getTimeStamp()

Returns a calendar value representing this time stamp. The method returns a copy of internal calendar value to preserve the internal state of this value.

Returns:
Calendar value representing this time stamp.

setTimeStamp

public final void setTimeStamp(Calendar timestampItem)
                        throws NullPointerException,
                               IllegalArgumentException

Set the value of this time stamp using a Calendar value. This method is strict in its interpretation of date and time values.

Note that all fields of the value will be preserved within the time stamp value and available on a call to getTimeStamp().

Parameters:
timestampItem - Calendar value to use to set the value of this time stamp.
Throws:
NullPointerException - Argument is null.
IllegalArgumentException - The given calendar value is not a valid date or time.

toString

public final String toString()

Formats the string according ISO 8601 and as a UTC value.

The format of the string is "yyyy-MM-dd'T'HH:mm:ss.SSZ", where:

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

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

parseTimeStamp

public static final TimeStamp parseTimeStamp(String stamp)
                                      throws ParseException,
                                             NullPointerException

Create a time stamp from a string that is formatted according to the UTC standards. If the value is given with a timezone part, the internal representation will be converted to UTC "+0000", otherwise kwown as "Z".

One acceptable format of the string is "yyyy-MM-dd'T'HH:mm:ss.SSSZ", where:

Alternatively, a "Z" may be used in place of "+0000". The number of milliseconds can be expressed by 100ths of a second.

Parameters:
stamp - String representation of a time stamp value.
Returns:
Newly created MAJ time stamp value from given string value.
Throws:
ParseException - A problem with the given string prevents it from being converted to a time stamp value, or the resulting value in unacceptable.
NullPointerException - Argument is null.

equals

public final boolean equals(Object o)

Checks for the equality of UTC values only and not the exact equality of the underlying calendar value representation.

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)

clone

public final TimeStamp 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.

Media Authoring
with Java API

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