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
Enum Period

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

public enum Period
extends java.lang.Enum<Period>

Defines constant values representing periods for working with Durations.

Version:
$Revision: 1685 $
Author:
Daniel Dietz

Nested Class Summary
static class Period.Level
          The known levels.
static class Period.Scroll
          The known values for scrolling Durations.
 
Enum Constant Summary
DAY
          A full day [00:00:00.000 - 23:59:59.999].
HOUR
          A full hour [??
MINUTE
          A full minute [??
MONTH
          A month - all full days of a month.
SECOND
          A full second [??
UNDEFINED
          Defines an "undefined" Period.
WEEK
          A week - a sequence of seven full days [Sunday - Saturday].
YEAR
          A year - all full days of a year [01.01.????
 
Method Summary
 long approximateSplitSize(Duration duration)
          Calculates the approximate split size for the given Duration if split by the Period.
static long approximateSplitSize(Duration duration, Period period)
          Calculates the approximate split size for the given Duration if split by the given Period.
static Duration getDuration(Period period, long millis)
          Calculates a Duration representing the given period and containing the given reference date.
 java.lang.Integer getOrder()
          Returns the order.
 java.lang.String getValue()
          Returns the string value.
 boolean isLonger(Period period)
          Checks whether the given Period is contained by the Period.
static Duration scrollDuration(Duration duration, Period period, Period.Scroll scroll)
          Scrolls the given Duration by the given Period to the given Scroll direction.
static Duration scrollDurationLevelled(Duration duration, Period period, Period.Scroll scroll)
          Scrolls the given Duration by the given Period to the given Scroll direction and returns a levelled Duration.
static Period valueof(Duration duration)
          Returns a Period for a given Duration.
static Period valueof(java.lang.String stringValue)
          Returns a Period by its string value.
static Period valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static Period[] values()
          Returns an array containing the constants of this enum type, in the order they're declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

UNDEFINED

public static final Period UNDEFINED
Defines an "undefined" Period.


SECOND

public static final Period SECOND
A full second [??:??:??.000 - ??:??:??.999].


MINUTE

public static final Period MINUTE
A full minute [??:??:00.000 - ??:??:59.999].


HOUR

public static final Period HOUR
A full hour [??:00:00.000 - ??:59:59.999].


DAY

public static final Period DAY
A full day [00:00:00.000 - 23:59:59.999].


WEEK

public static final Period WEEK
A week - a sequence of seven full days [Sunday - Saturday].


MONTH

public static final Period MONTH
A month - all full days of a month.


YEAR

public static final Period YEAR
A year - all full days of a year [01.01.???? - 31.12.????].

Method Detail

values

public static final Period[] values()
Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants as follows:
for(Period c : Period.values())
        System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they're declared

valueOf

public static Period valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name

getValue

public java.lang.String getValue()
Returns the string value.

Returns:
value

getOrder

public java.lang.Integer getOrder()
Returns the order.

Returns:
order

isLonger

public boolean isLonger(Period period)
Checks whether the given Period is contained by the Period.

Parameters:
period - the Period to be checked
Returns:
  • true
    • if the Period contains the given Period
  • false
    • if the Period matches the given Period
    • if the Period is Period.UNDEFINED
    • if the given Period is Period.UNDEFINED
    • any other case

getDuration

public static Duration getDuration(Period period,
                                   long millis)
Calculates a Duration representing the given period and containing the given reference date.

Parameters:
period - the Period
millis - the reference date in milliseconds
Returns:
a Duration

scrollDuration

public static Duration scrollDuration(Duration duration, Period period, Period.Scroll scroll)
Scrolls the given Duration by the given Period to the given Scroll direction.

Parameters:
duration - the Duration
period - the Period to scroll by
scroll - the scroll direction
Returns:
  • the scrolled milliseconds
  • if the given period is Period.UNDEFINED the given Duration will be left unchanged

scrollDurationLevelled

public static Duration scrollDurationLevelled(Duration duration, Period period, Period.Scroll scroll)
Scrolls the given Duration by the given Period to the given Scroll direction and returns a levelled Duration.

Levelled here means the returned Duration will be the PREVIOUS/NEXT

Parameters:
duration - the Duration
period - the Period to scroll by
scroll - the scroll direction
Returns:
  • the scrolled milliseconds
  • if the given period is Period.UNDEFINED the given Duration will be left unchanged
Throws:
TimeUtilityException

valueof

public static Period valueof(java.lang.String stringValue)
Returns a Period by its string value.

Parameters:
stringValue - the string value
Returns:
Period

valueof

public static Period valueof(Duration duration)
Returns a Period for a given Duration.

Parameters:
duration - the Duration
Returns:
Period

approximateSplitSize

public long approximateSplitSize(Duration duration)
Calculates the approximate split size for the given Duration if split by the Period.

Parameters:
duration - the Duration
Returns:
returns the approximate split size

approximateSplitSize

public static final long approximateSplitSize(Duration duration, Period period)
Calculates the approximate split size for the given Duration if split by the given Period.

Parameters:
duration - the Duration
period - the Period
Returns:
returns the approximate split size
Throws:
TimeUtilityException - if the given Period is Period.UNDEFINED