com.dlsc.flexgantt.model
Enum TimeGranularity

java.lang.Object
  extended by java.lang.Enum<TimeGranularity>
      extended by com.dlsc.flexgantt.model.TimeGranularity
All Implemented Interfaces:
IGranularity<TimeGranularity>, java.io.Serializable, java.lang.Comparable<TimeGranularity>

public enum TimeGranularity
extends java.lang.Enum<TimeGranularity>
implements IGranularity<TimeGranularity>

An enumeration of possible time granularities. The smallest granularity is MILLISECOND, the largest is MILLENIUM. Time granularities represent an abstract time concept. These abstractions can be used in various places throughout the framework to control the behaviour and appearance of the user interface. One example is the special zoom policy IZoomPolicy, which is used to determine how far the user can zoom into and out of the timeline. For many applications it is sufficient to see anything ranging from days to years, but not from milliseconds to milleniums. Using the data type 'long' to represent (for example) a year would not be sufficient, because a year can vary in duration.

Since:
1.0
Author:
Dirk Lemmermann
See Also:
TimeGranularityGridPolicy, TimeGranularityDatelineModel, TimeGranularityDatelineRenderer

Enum Constant Summary
CENTURY
          A time granularity representing 100 years.
DAY_SHORT
          A time granularity representing 1 day.
DAY_TINY
          A time granularity representing 1 day (tiny representation).
DECADE
          A time granularity representing 10 years.
FIFTEEN_MINUTES
          A time granularity representing 15 minutes.
FIFTEEN_SECONDS
          A time granularity representing 15 seconds.
FIVE_MINUTES
          A time granularity representing 5 minutes.
FIVE_SECONDS
          A time granularity representing 5 seconds.
HALF_YEAR
          A time granularity representing 6 months.
HOUR
          A time granularity representing 1 hour.
HUNDRED_MILLISECONDS
          A time granularity representing 100 milliseconds.
MILLENIUM
          A time granularity representing 1000 years.
MILLISECOND
          The smallest granularity representing a millisecond.
MINUTE
          A time granularity representing 1 minute.
MONTH_SHORT
          A time granularity representing 1 month.
MONTH_TINY
          A time granularity representing 1 month (tiny representation).
QUARTER_YEAR
          A time granularity representing 3 months.
SECOND
          A time granularity representing 1 second.
SIX_HOURS
          A time granularity representing 6 hour.
TEN_MILLISECONDS
          A time granularity representing 10 milliseconds.
TEN_MINUTES
          A time granularity representing 10 minutes.
TEN_SECONDS
          A time granularity representing 10 seconds.
THIRTY_MINUTES
          A time granularity representing 30 minutes.
THIRTY_SECONDS
          A time granularity representing 30 seconds.
THREE_HOURS
          A time granularity representing 3 hour.
WEEK
          A time granularity representing 1 week.
YEAR
          A time granularity representing 1 year.
 
Method Summary
 void adjustCalendar(java.util.Calendar c)
          Adjusts the given calendar by rounding it down based on the time granularity.
 void adjustDate(java.util.Date date)
          Adjusts the given date by rounding it down based on the time granularity.
 void decrement(java.util.Calendar c)
          Decrements a given calendar by removing time from it.
 void decrement(java.util.Date date)
          Decrements a given date by removing time from it.
 double getDelta(java.util.Calendar s, java.util.Calendar e)
          Returns the number of hours or minutes or days between the given start and end time.
 double getDelta(ITimeSpan span, java.util.TimeZone timeZone)
          Returns the number of hours or minutes or days between the start and the end time of the given time span.
 long getMilliseconds()
          Returns the number of milliseconds represented by the time granularity.
 java.lang.String getName()
          Returns a translated and displayable name for the time granularity enumeration value.
static TimeGranularity[] getRange(TimeGranularity smallest, TimeGranularity largest)
          Returns an array of time granularities.
static TimeGranularity getTimeGranularity(java.lang.String name)
          A name-based lookup of time granularities.
 void increment(java.util.Calendar c)
          Increments a given calendar by adding time to it.
 void increment(java.util.Date date)
          Increments a given date by adding time to it.
 boolean isInside(TimeGranularity lower, TimeGranularity upper)
          Checks whether a time granularity is 'inside' two other granularities.
 boolean isLarger(TimeGranularity tg)
          Performs a check to see whether the time granularity is 'larger' than the given granularity.
 boolean isSmaller(TimeGranularity tg)
          Performs a check to see whether the time granularity is 'smaller' than the given granularity.
static TimeGranularity valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static TimeGranularity[] 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

MILLISECOND

public static final TimeGranularity MILLISECOND
The smallest granularity representing a millisecond.

Since:
1.0

TEN_MILLISECONDS

public static final TimeGranularity TEN_MILLISECONDS
A time granularity representing 10 milliseconds.

Since:
1.0

HUNDRED_MILLISECONDS

public static final TimeGranularity HUNDRED_MILLISECONDS
A time granularity representing 100 milliseconds.

Since:
1.0

SECOND

public static final TimeGranularity SECOND
A time granularity representing 1 second.

Since:
1.0

FIVE_SECONDS

public static final TimeGranularity FIVE_SECONDS
A time granularity representing 5 seconds.

Since:
1.0

TEN_SECONDS

public static final TimeGranularity TEN_SECONDS
A time granularity representing 10 seconds.

Since:
1.0

FIFTEEN_SECONDS

public static final TimeGranularity FIFTEEN_SECONDS
A time granularity representing 15 seconds.

Since:
1.0

THIRTY_SECONDS

public static final TimeGranularity THIRTY_SECONDS
A time granularity representing 30 seconds.

Since:
1.0

MINUTE

public static final TimeGranularity MINUTE
A time granularity representing 1 minute.

Since:
1.0

FIVE_MINUTES

public static final TimeGranularity FIVE_MINUTES
A time granularity representing 5 minutes.

Since:
1.0

TEN_MINUTES

public static final TimeGranularity TEN_MINUTES
A time granularity representing 10 minutes.

Since:
1.0

FIFTEEN_MINUTES

public static final TimeGranularity FIFTEEN_MINUTES
A time granularity representing 15 minutes.

Since:
1.0

THIRTY_MINUTES

public static final TimeGranularity THIRTY_MINUTES
A time granularity representing 30 minutes.

Since:
1.0

HOUR

public static final TimeGranularity HOUR
A time granularity representing 1 hour.

Since:
1.0

THREE_HOURS

public static final TimeGranularity THREE_HOURS
A time granularity representing 3 hour.

Since:
1.0

SIX_HOURS

public static final TimeGranularity SIX_HOURS
A time granularity representing 6 hour.

Since:
1.0

DAY_SHORT

public static final TimeGranularity DAY_SHORT
A time granularity representing 1 day.

Since:
1.0

DAY_TINY

public static final TimeGranularity DAY_TINY
A time granularity representing 1 day (tiny representation).

Since:
1.0

WEEK

public static final TimeGranularity WEEK
A time granularity representing 1 week.

Since:
1.0

MONTH_SHORT

public static final TimeGranularity MONTH_SHORT
A time granularity representing 1 month.

Since:
1.0

MONTH_TINY

public static final TimeGranularity MONTH_TINY
A time granularity representing 1 month (tiny representation).

Since:
1.0

QUARTER_YEAR

public static final TimeGranularity QUARTER_YEAR
A time granularity representing 3 months.

Since:
1.0

HALF_YEAR

public static final TimeGranularity HALF_YEAR
A time granularity representing 6 months.

Since:
1.0

YEAR

public static final TimeGranularity YEAR
A time granularity representing 1 year.

Since:
1.0

DECADE

public static final TimeGranularity DECADE
A time granularity representing 10 years.

Since:
1.0

CENTURY

public static final TimeGranularity CENTURY
A time granularity representing 100 years.

Since:
1.0

MILLENIUM

public static final TimeGranularity MILLENIUM
A time granularity representing 1000 years.

Since:
1.0
Method Detail

values

public static final TimeGranularity[] 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(TimeGranularity c : TimeGranularity.values())
        System.out.println(c);

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

valueOf

public static TimeGranularity 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

getMilliseconds

public long getMilliseconds()
Returns the number of milliseconds represented by the time granularity.

Returns:
the granularity's milliseconds
Since:
1.0

getName

public java.lang.String getName()
Returns a translated and displayable name for the time granularity enumeration value.

Specified by:
getName in interface IGranularity<TimeGranularity>
Returns:
a displayable name
Since:
1.0

adjustDate

public void adjustDate(java.util.Date date)
Adjusts the given date by rounding it down based on the time granularity. For example: if the time granularity is YEAR, then a date like March 16th, 2006 14:30:50 (348) will be rounded down to January 1st, 2006, 00:00:00 (000).

Parameters:
date - the date to round down
Since:
1.0

adjustCalendar

public void adjustCalendar(java.util.Calendar c)
Adjusts the given calendar by rounding it down based on the time granularity. For example: if the time granularity is YEAR, then a date like March 16th, 2006 14:30:50 (348) will be rounded down to January 1st, 2006, 00:00:00 (000).

Parameters:
c - the calendar to round down
Since:
1.0

increment

public void increment(java.util.Date date)
Increments a given date by adding time to it. The amount added is based on the time granularity. If for example the granularity is YEAR then one year will be added to the date. If the granularity is DAY_TINY then only one day will be added.

Parameters:
date - the date to increment
Since:
1.0
See Also:
decrement(Date), increment(Calendar)

increment

public void increment(java.util.Calendar c)
Increments a given calendar by adding time to it. The amount added is based on the time granularity. If for example the granularity is YEAR then one year will be added to the calendar. If the granularity is DAY_TINY then only one day will be added.

Parameters:
c - the calendar to increment
Since:
1.0
See Also:
decrement(Calendar), increment(Date)

decrement

public void decrement(java.util.Date date)
Decrements a given date by removing time from it. The amount removed is based on the time granularity. If for example the granularity is YEAR then one year will be removed from the date. If the granularity is DAY_TINY then only one day will be removed.

Parameters:
date - the date to decrement
Since:
1.0
See Also:
increment(Date), decrement(Calendar)

decrement

public void decrement(java.util.Calendar c)
Decrements a given calendar by removing time from it. The amount removed is based on the time granularity. If for example the granularity is YEAR then one year will be removed from the calendar. If the granularity is DAY_TINY then only one day will be removed.

Parameters:
c - the calendar to decrement
Since:
1.0
See Also:
increment(Calendar), decrement(Date)

getRange

public static TimeGranularity[] getRange(TimeGranularity smallest,
                                         TimeGranularity largest)
Returns an array of time granularities. The first element is the smallest and the last element the largest granularity (lower and upper bounds). Example: if the smallest granularity is DAY_TINY and the largest is MONTH_SHORT, then the resulting array will be [DAY_TINY, WEEK, FOURTEEN_DAYS, MONTH_SHORT];

Parameters:
smallest - the lower bounds of the requested range
largest - the upper bounds of the requested range
Returns:
a sorted array of time granularities where the first element is the smallest and the last element is the largest granularity
Since:
1.0

isInside

public boolean isInside(TimeGranularity lower,
                        TimeGranularity upper)
Checks whether a time granularity is 'inside' two other granularities. A granularity G is inside A and B if (A.isSmaller(G) || A.equals(G)) and (B.isLarger(G) || B.equals(G)).

Parameters:
lower - the lower bounds of the range
upper - the upper bounds of the range
Returns:
'true' if the current time granularity is larger or equal to 'lower' and smaller or equal to 'upper'
Throws:
java.lang.IllegalArgumentException - if 'lower' is not smaller than 'upper' or equal to 'upper'
Since:
1.0

isSmaller

public boolean isSmaller(TimeGranularity tg)
Performs a check to see whether the time granularity is 'smaller' than the given granularity. A time granularity is an enumeration value and it is considered smaller if its ordinal value is smaller than the ordinal value of another time granularity value.

Specified by:
isSmaller in interface IGranularity<TimeGranularity>
Parameters:
tg - the time granularity to compare with
Returns:
'true' if ordinal() < tg.ordinal()
Since:
1.0

isLarger

public boolean isLarger(TimeGranularity tg)
Performs a check to see whether the time granularity is 'larger' than the given granularity. A time granularity is an enumeration value and it is considered larger if its ordinal value is larger than the ordinal value of another time granularity value.

Specified by:
isLarger in interface IGranularity<TimeGranularity>
Parameters:
tg - the time granularity to compare with
Returns:
'true' if ordinal() > tg.ordinal()
Since:
1.0

getTimeGranularity

public static TimeGranularity getTimeGranularity(java.lang.String name)
A name-based lookup of time granularities. The method returns the time granularity for the given 'display' name. It is very important to note that the display name depends on the locale, which was active when the time granularity enumerator was first loaded.

Parameters:
name - a time granularity display name (note: depends on the current locale as the name is i18n)
Returns:
the time granularity with the given display name
Throws:
java.lang.IllegalArgumentException - if no time granularity with the given display name exists
Since:
1.0
See Also:
getName()

getDelta

public double getDelta(ITimeSpan span,
                       java.util.TimeZone timeZone)
Returns the number of hours or minutes or days between the start and the end time of the given time span. Example: if the time granularity is YEAR then the delta will be the difference in number of years between the start and the end time.

Parameters:
span - the time span for which to calculate the delta
timeZone - used to create calendar objects for the start and the end time of the given time span
Returns:
the time granularity difference between the start and the end time of the given time span
See Also:
getDelta(Calendar, Calendar)

getDelta

public double getDelta(java.util.Calendar s,
                       java.util.Calendar e)
Returns the number of hours or minutes or days between the given start and end time. Example: if the time granularity is YEAR then the delta will be the difference in number of years between the start and the end time.

Parameters:
s - the start time
e - the end time
Returns:
the time granularity difference between the start and the end time of the given time span
See Also:
getDelta(ITimeSpan, TimeZone)