pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util.time
Class Duration

java.lang.Object
  extended by org.torweg.pulse.util.time.Duration
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<TimeSpan>, IHasDuration

@Embeddable
public final class Duration
extends java.lang.Object
implements java.lang.Comparable<TimeSpan>, IHasDuration, java.io.Serializable

represents a duration in time.

Version:
$Revision: 1625 $
Author:
Thomas Weber
See Also:
Serialized Form

Constructor Summary
Duration()
          creates a Duration starting now and lasting zero milliseconds.
Duration(java.util.Calendar a, java.util.Calendar b)
          creates a new Duration with a positive TimeSpan , making the less recent Calendar the reference date.
Duration(java.util.Date a, java.util.Date b)
          creates a new Duration with a positive TimeSpan , making the less recent Date the reference date.
Duration(java.util.Date d, java.lang.String ts)
          creates a new Duration lasting for the given time span and the given reference date.
Duration(java.util.Date d, TimeSpan ts)
          creates a new Duration lasting for the given time span and the given reference date.
Duration(Duration duration)
          Creates a new Duration from the given Duration.
Duration(long a, long b)
          creates a new Duration with a positive TimeSpan , making the less recent time-stamp the reference date.
Duration(java.lang.String ts)
          creates a new Duration lasting for the given time span string and now as the reference date.
Duration(TimeSpan ts)
          creates a new Duration lasting for the given time span.
 
Method Summary
 TimeSpan add(TimeSpan s)
          adds a given time span to this time span.
 java.util.Date addTo(java.util.Date d)
          returns a new Date with the time span added to the Date.
 Duration applyOffset(java.lang.Long offset)
          Applies the given offset to the start/end time stamp of Duration if the offset is not null.
 int compareTo(TimeSpan o)
          compare the time spans of the duration with the given time span.
 boolean contains(java.util.Date date)
          returns whether a given date is contained in the duration.
 boolean contains(Duration duration)
          Checks if the given duration is within or equal the duration.
 boolean contains(long time)
          returns whether a given time stamp is contained in the duration.
 boolean equals(java.lang.Object obj)
          checks whether the given object is equal to the duration.
 Duration getDuration()
          Returns a new Duration with the values of the Duration.
 java.util.Date getEndDate()
          returns the end date.
 java.lang.String getEndDateUTCString()
          returns the UTC end date.
 long getEndMillis()
          Returns the milliseconds-value of the end of the Duration.
 long getMilliseconds()
          returns the milliseconds.
 java.util.Date getReferenceDate()
          returns the reference date.
 java.lang.String getSpan()
          returns the string value.
 java.util.Date getStartDate()
          returns the start date.
 java.lang.String getStartDateUTCString()
          returns the UTC start date.
 long getStartMillis()
          Returns the milliseconds-value of the start of the Duration.
 TimeSpan getTimeSpan()
          returns the TimeSpan of the Duration.
 int hashCode()
           
 Duration levelBoundaries(Period period)
          Modifies the start/end time stamp of the Duration to match the start/end of the given Period.
 void setEndDateMillis(long millis)
          Sets the given value as endDate.
 void setMilliseconds(long ms)
          sets the milliseconds for the time span.
 void setSpan(java.lang.String s)
          sets the time span.
 TimeSpan subtract(TimeSpan s)
          subtracts a given time span from this time span.
 java.util.Date subtractFrom(java.util.Date d)
          returns a new Date with the time span subtracted from the Date.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Duration

public Duration()
creates a Duration starting now and lasting zero milliseconds.


Duration

public Duration(java.lang.String ts)
creates a new Duration lasting for the given time span string and now as the reference date.

Parameters:
ts - the time span as a string

Duration

public Duration(TimeSpan ts)
creates a new Duration lasting for the given time span.

If the time span is negative, the duration's start date is now - time span. Otherwise the start date is now.

Parameters:
ts - the time span

Duration

public Duration(java.util.Date d,
                java.lang.String ts)
creates a new Duration lasting for the given time span and the given reference date.

Parameters:
d - the reference date
ts - the time span

Duration

public Duration(java.util.Date d, TimeSpan ts)
creates a new Duration lasting for the given time span and the given reference date.

Parameters:
d - the reference date
ts - the time span

Duration

public Duration(java.util.Date a,
                java.util.Date b)
creates a new Duration with a positive TimeSpan , making the less recent Date the reference date.

Parameters:
a - boundary date a
b - boundary date b

Duration

public Duration(java.util.Calendar a,
                java.util.Calendar b)
creates a new Duration with a positive TimeSpan , making the less recent Calendar the reference date.

Parameters:
a - boundary Calendar a
b - boundary Calendar b

Duration

public Duration(long a,
                long b)
creates a new Duration with a positive TimeSpan , making the less recent time-stamp the reference date.

Parameters:
a - boundary time-stamp a
b - boundary time-stamp b

Duration

public Duration(Duration duration)
Creates a new Duration from the given Duration.

Parameters:
duration - the Duration
Method Detail

getStartDate

public java.util.Date getStartDate()
returns the start date.

Returns:
the start date

getStartDateUTCString

public java.lang.String getStartDateUTCString()
returns the UTC start date.

Returns:
the UTC start date

getStartMillis

public long getStartMillis()
Returns the milliseconds-value of the start of the Duration.

Returns:
startDate

getEndDate

public java.util.Date getEndDate()
returns the end date.

Returns:
the end date

getEndDateUTCString

public java.lang.String getEndDateUTCString()
returns the UTC end date.

Returns:
the UTC end date

getEndMillis

public long getEndMillis()
Returns the milliseconds-value of the end of the Duration.

Returns:
endDate

setEndDateMillis

public void setEndDateMillis(long millis)
Sets the given value as endDate.

Parameters:
millis - the value to set.
Throws:
java.lang.IllegalArgumentException - if the record is null

getReferenceDate

public java.util.Date getReferenceDate()
returns the reference date.

Returns:
the reference date

getMilliseconds

public long getMilliseconds()
returns the milliseconds.

Returns:
the milliseconds

getTimeSpan

public TimeSpan getTimeSpan()
returns the TimeSpan of the Duration.

Returns:
the time span

setMilliseconds

public void setMilliseconds(long ms)
sets the milliseconds for the time span.

Parameters:
ms - the time span

getSpan

public java.lang.String getSpan()
returns the string value.

Returns:
the string value

setSpan

public void setSpan(java.lang.String s)
sets the time span.

Parameters:
s - the time span string

add

public TimeSpan add(TimeSpan s)
adds a given time span to this time span.

Parameters:
s - the time span to add
Returns:
this time span plus the given time span

subtract

public TimeSpan subtract(TimeSpan s)
subtracts a given time span from this time span.

Parameters:
s - the time span to add
Returns:
this time span minus the given time span

addTo

public java.util.Date addTo(java.util.Date d)
returns a new Date with the time span added to the Date.

Parameters:
d - the date
Returns:
the computed date

subtractFrom

public java.util.Date subtractFrom(java.util.Date d)
returns a new Date with the time span subtracted from the Date.

Parameters:
d - the date
Returns:
the computed date

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

equals

public boolean equals(java.lang.Object obj)
checks whether the given object is equal to the duration.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to check against
Returns:
true, if and only if both start and end dates are equal

compareTo

public int compareTo(TimeSpan o)
compare the time spans of the duration with the given time span.

Specified by:
compareTo in interface java.lang.Comparable<TimeSpan>
Parameters:
o - the time span to compare with
Returns:
a negative integer, zero, or a positive integer as this time span is less than, equal to, or greater than the specified time span.
See Also:
Comparable.compareTo(java.lang.Object)

contains

public boolean contains(java.util.Date date)
returns whether a given date is contained in the duration.

Parameters:
date - the date
Returns:
true, if and only if the given date is within the duration. Otherwise false.

contains

public boolean contains(long time)
returns whether a given time stamp is contained in the duration.

Parameters:
time - the time stamp
Returns:
true, if and only if the given time stamp is within the duration. Otherwise false.

contains

public boolean contains(Duration duration)
Checks if the given duration is within or equal the duration.

Parameters:
duration - the Duration
Returns:
true, if and only if the given Duration is within or equal the duration, false otherwise

getDuration

public Duration getDuration()
Returns a new Duration with the values of the Duration.

Specified by:
getDuration in interface IHasDuration
Returns:
a new Duration with the values of the Duration
See Also:
IHasDuration.getDuration()

applyOffset

public Duration applyOffset(java.lang.Long offset)
Applies the given offset to the start/end time stamp of Duration if the offset is not null.

Parameters:
offset - the offset to scroll by
Returns:
the modified Duration

levelBoundaries

public Duration levelBoundaries(Period period)
Modifies the start/end time stamp of the Duration to match the start/end of the given Period.

Parameters:
period - Period
Returns:
the modified Duration

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string-representation of the Duration