Holger's
Java API

com.antelmann.calendar
Enum TimeInterval

java.lang.Object
  extended by java.lang.Enum<TimeInterval>
      extended by com.antelmann.calendar.TimeInterval
All Implemented Interfaces:
Unit, Localizable, Serializable, Comparable<TimeInterval>

public enum TimeInterval
extends Enum<TimeInterval>
implements Unit

provides different intervals for time ranges

Since:
07/05/08
Author:
Holger Antelmann
See Also:
TimeUnit, Month, WeekDay

Nested Class Summary
static class TimeInterval.Converter
           
 
Nested classes/interfaces inherited from interface com.antelmann.util.Localizable
Localizable.Adapter
 
Enum Constant Summary
DAY
           
HOUR
           
MILLISECOND
           
MINUTE
           
MONTH
          defined as 30 days in regards to its milliseconds
QUARTER
          defined as 3 months (90 days) in regards to its milliseconds
SECOND
           
WEEK
           
YEAR
          defined as 4 quarters (360 days) in regards to its milliseconds
 
Method Summary
 Date addInterval(Date date, int amount)
           
 Date addInterval(Date date, int amount, Calendar cal)
          adds the date interval times the given amount to the given date
 long addInterval(long time, int amount)
           
 long addInterval(long time, int amount, Calendar cal)
           
 Date adjust(Date date, int n)
          returns a date that is adjusted to the given amount by this interval.
 Date adjustToBegin(Date date)
           
 Date adjustToBegin(Date date, Calendar cal)
          adjusts the date in a way that it always represents the begin time of the interval.
 long adjustToBegin(long time)
           
 long adjustToBegin(long time, Calendar cal)
           
 Date adjustToEnd(Date date)
           
 Date adjustToEnd(Date date, Calendar cal)
           
 long adjustToEnd(long time)
           
 long adjustToEnd(long time, Calendar cal)
           
 long count(Date date0, Date date1)
           
 long count(long time0, long time1)
           
static TimeInterval fromSymbol(String symbol)
           
static TimeInterval fromTimeUnit(TimeUnit unit)
          may return null if the given unit has no corresponding interval
static TimeInterval[] getDateIntervals()
          returns all intervals greater or equal to DAY
 ArrayList<Date> getEntriesInRange(Date begin, Date end)
           
 ArrayList<Date> getEntriesInRange(Range<? extends Date> range)
          provides an easy way to obtain a list of interval entries that enclose the given range, where every returned entry is timed at the beginning of the interval.
 DateFormat getFormat()
          returns an appropriate format that maps to this interval
 Range<Date> getIntervalDateRange(Date date)
           
 Locale getLocale()
          allows access to the Locale that this instance currently uses to localize its messages,
 String getUnitName()
          provides the fully spelled name for this unit
 String getUnitName(Locale l)
           
 String getUnitSymbol()
          provides a short symbolic representation of this unit
 boolean isInSameInterval(Date time1, Date time2)
           
 boolean isInSameInterval(long time1, long time2)
           
 long milliseconds()
           
 long round(long time)
           
 int seconds()
          convenience method
 void setLocale(Locale locale, Object context)
          sets the Locale for this object so that all subsequent return values of method calls to this instance can be localized accordingly until a different Locale is set.
 BaseUnit toBaseUnit()
          allows conversions with other custom time units
 double toDecimal(long millis)
           
 String toString()
           
 TimeUnit toTimeUnit()
          may return null for intervals without a corresponding unit
static TimeInterval valueOf(String name)
          Returns the enum constant of this type with the specified name.
static TimeInterval[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

MILLISECOND

public static final TimeInterval MILLISECOND

SECOND

public static final TimeInterval SECOND

MINUTE

public static final TimeInterval MINUTE

HOUR

public static final TimeInterval HOUR

DAY

public static final TimeInterval DAY

WEEK

public static final TimeInterval WEEK

MONTH

public static final TimeInterval MONTH
defined as 30 days in regards to its milliseconds


QUARTER

public static final TimeInterval QUARTER
defined as 3 months (90 days) in regards to its milliseconds


YEAR

public static final TimeInterval YEAR
defined as 4 quarters (360 days) in regards to its milliseconds

Method Detail

values

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

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

valueOf

public static TimeInterval valueOf(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:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

getDateIntervals

public static TimeInterval[] getDateIntervals()
returns all intervals greater or equal to DAY


fromSymbol

public static TimeInterval fromSymbol(String symbol)

getLocale

public Locale getLocale()
Description copied from interface: Localizable
allows access to the Locale that this instance currently uses to localize its messages,

Specified by:
getLocale in interface Localizable
Returns:
the current Locale that this instance uses to determine return values for its methods; if null is returned, this instance is expected to use the default Locale of the system.
See Also:
Localizable.setLocale(Locale, Object)

setLocale

public void setLocale(Locale locale,
                      Object context)
Description copied from interface: Localizable
sets the Locale for this object so that all subsequent return values of method calls to this instance can be localized accordingly until a different Locale is set.

Specified by:
setLocale in interface Localizable
Parameters:
locale - the Locale that is to be used to determine return values for all methods of this instance; if set to null, the default locale is to be used.
context - a context that may be required for this instance to load the resources for the given locale; this context may be null for objects that do not require an external context. Examples of a context may be a database, a resource file, some map or no context at all.
See Also:
Localizable.getLocale()

getFormat

public DateFormat getFormat()
returns an appropriate format that maps to this interval


getIntervalDateRange

public Range<Date> getIntervalDateRange(Date date)

isInSameInterval

public boolean isInSameInterval(Date time1,
                                Date time2)

isInSameInterval

public boolean isInSameInterval(long time1,
                                long time2)

getEntriesInRange

public ArrayList<Date> getEntriesInRange(Date begin,
                                         Date end)
                                  throws IllegalArgumentException
Throws:
IllegalArgumentException
See Also:
getEntriesInRange(Range)

getEntriesInRange

public ArrayList<Date> getEntriesInRange(Range<? extends Date> range)
                                  throws IllegalArgumentException
provides an easy way to obtain a list of interval entries that enclose the given range, where every returned entry is timed at the beginning of the interval. Entries are included as long as the given boundaries fall within that interval (beginning at the entry time).

Parameters:
range - only closed and typed ranges are supported; the time of the dates are ignored
Returns:
an array with the date entries (at their interval begin time) that are in the given range
Throws:
IllegalArgumentException - if the given range is not closed or not typed
See Also:
Range.isTyped(Class), Range.isClosedRange()

count

public long count(long time0,
                  long time1)

count

public long count(Date date0,
                  Date date1)

round

public long round(long time)

adjustToEnd

public long adjustToEnd(long time)

adjustToEnd

public Date adjustToEnd(Date date)

adjustToEnd

public Date adjustToEnd(Date date,
                        Calendar cal)

adjustToEnd

public long adjustToEnd(long time,
                        Calendar cal)

adjustToBegin

public long adjustToBegin(long time)

adjustToBegin

public Date adjustToBegin(Date date)

adjustToBegin

public Date adjustToBegin(Date date,
                          Calendar cal)
adjusts the date in a way that it always represents the begin time of the interval.


adjustToBegin

public long adjustToBegin(long time,
                          Calendar cal)

adjust

public Date adjust(Date date,
                   int n)
returns a date that is adjusted to the given amount by this interval. For example, MINUTE with n = 5 would return values that are guaranteed to be 5 minutes apart for each given date. This is useful when used with a PatternExtractor that is supposed to produce values for 5 minute intervals, for instance


addInterval

public Date addInterval(Date date,
                        int amount)

addInterval

public long addInterval(long time,
                        int amount)

addInterval

public Date addInterval(Date date,
                        int amount,
                        Calendar cal)
adds the date interval times the given amount to the given date


addInterval

public long addInterval(long time,
                        int amount,
                        Calendar cal)

toString

public String toString()
Overrides:
toString in class Enum<TimeInterval>

getUnitName

@Localized
public String getUnitName()
Description copied from interface: Unit
provides the fully spelled name for this unit

Specified by:
getUnitName in interface Unit

getUnitName

public String getUnitName(Locale l)

getUnitSymbol

@Todo(value="localize")
public String getUnitSymbol()
Description copied from interface: Unit
provides a short symbolic representation of this unit

Specified by:
getUnitSymbol in interface Unit

milliseconds

public long milliseconds()

toDecimal

public double toDecimal(long millis)

seconds

public int seconds()
convenience method


toBaseUnit

public BaseUnit toBaseUnit()
allows conversions with other custom time units


toTimeUnit

public TimeUnit toTimeUnit()
may return null for intervals without a corresponding unit


fromTimeUnit

public static TimeInterval fromTimeUnit(TimeUnit unit)
may return null if the given unit has no corresponding interval



(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads