com.dlsc.flexgantt.model.dateline

## Enum TimeGranularity

- java.lang.Object
- - java.lang.Enum<TimeGranularity>
  - - com.dlsc.flexgantt.model.dateline.TimeGranularity

- All Implemented Interfaces:
    IGranularity<TimeGranularity>, Serializable, Comparable<TimeGranularity>

      public enum TimeGranularity
      extends 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
  Version:
    $Revision: 1.10 $
  Author:
    Dirk Lemmermann
  See Also:
    `TimeGranularityGridPolicy`, `TimeGranularityDatelineModel`, `TimeGranularityDatelineRenderer`

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `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

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `adjustCalendar(Calendar c)` Adjusts the given calendar by rounding it down based on the time granularity.
    `void` | `adjustDate(Date date, TimeZone timeZone)` Adjusts the given date by rounding it down based on the time granularity.
    `long` | `adjustTime(long time, TimeZone timeZone)` Adjusts the given time by rounding it down based on the time granularity.
    `void` | `decrement(Calendar c)` Decrements a given calendar by removing time from it.
    `void` | `decrement(Date date, TimeZone timeZone)` Decrements a given date by removing time from it.
    `long` | `decrement(long time, TimeZone timeZone)` Decrements a given time poin by removing time from it.
    `double` | `getDelta(Calendar s, Calendar e)` Returns the number of hours or minutes or days between the given start and end time.
    `double` | `getDelta(ITimeSpan span, TimeZone timeZone)` Returns the number of hours or minutes or days between the start and the end time of the given time span.
    `static int` | `getFirstDayOfWeek()` Returns the first day of the week (e.g.
    `long` | `getMilliseconds()` Returns the number of milliseconds represented by the time granularity.
    `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.
    `String` | `getSingularName()` Returns the singular name of the granularity (e.g.
    `long` | `getStandardDuration()` Returns the standard duration in milliseconds of the granularity, e.g.
    `static TimeGranularity` | `getTimeGranularity(String name)` A name-based lookup of time granularities.
    `void` | `increment(Calendar c)` Increments a given calendar by adding time to it.
    `void` | `increment(Date date, TimeZone timeZone)` Increments a given date by adding time to it.
    `long` | `increment(long time, TimeZone timeZone)` Increments a given time point by adding time to it.
    `boolean` | `isDisplayingMarkerType(MarkerType type)` Determines whether markers of the given type will be shown in the timeline.
    `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 void` | `setFirstDayOfWeek(int firstDayOfWeek)` Sets the first day of the week (e.g.
    `static TimeGranularity` | `valueOf(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 are declared.

    - ### Methods inherited from class java.lang.Enum

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

    - ### Methods inherited from class java.lang.Object

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

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

    - #### valueOf

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

    - #### getMilliseconds

          public long getMilliseconds()

      Returns the number of milliseconds represented by the time granularity.
      Returns:
        the granularity's milliseconds
      Since:
        1.0

    - #### getStandardDuration

          public long getStandardDuration()

      Description copied from interface: `IGranularity`
      Returns the standard duration in milliseconds of the granularity, e.g. day = 24 hours * 60 minutes * 60 seconds * 1000;
      Specified by:
        `getStandardDuration` in interface `IGranularity<TimeGranularity>`
      Returns:
        the standard duration of one unit of this granularity

    - #### getName

          public 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

    - #### adjustTime

          public long adjustTime(long time,
                                 TimeZone timeZone)

      Adjusts the given time 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:
        `time` - the time to round down
        `timeZone` - the time zone for which to adjust the date
      Returns:
        the adjusted (rounded) time point
      Since:
        1.1.7

    - #### adjustDate

          public void adjustDate(Date date,
                                 TimeZone timeZone)

      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
        `timeZone` - the time zone for which to adjust the date
      Since:
        1.1.7

    - #### adjustCalendar

          public void adjustCalendar(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 long increment(long time,
                                TimeZone timeZone)

      Increments a given time point 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:
        `time` - the time point to which to add
        `timeZone` - the time zone for which to increment
      Returns:
        the incremented time point
      Since:
        1.1.7
      See Also:
        `decrement(long, TimeZone)`, `increment(Date, TimeZone)`, `increment(Calendar)`

    - #### increment

          public void increment(Date date,
                                TimeZone timeZone)

      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
        `timeZone` - the time zone for which to increment
      Since:
        1.1.7
      See Also:
        `decrement(Date, TimeZone)`, `increment(Calendar)`

    - #### increment

          public void increment(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, TimeZone)`

    - #### decrement

          public long decrement(long time,
                                TimeZone timeZone)

      Decrements a given time poin 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:
        `time` - the time point to decrement
        `timeZone` - the time zone for which to decrement
      Returns:
        the decremented time point
      Since:
        1.1.7
      See Also:
        `increment(long, TimeZone)`, `increment(Date, TimeZone)`, `decrement(Calendar)`

    - #### decrement

          public void decrement(Date date,
                                TimeZone timeZone)

      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
        `timeZone` - the time zone for which to decrement
      Since:
        1.1.7
      See Also:
        `increment(Date, TimeZone)`, `decrement(Calendar)`

    - #### decrement

          public void decrement(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, TimeZone)`

    - #### 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:
        `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(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:
        `IllegalArgumentException` - if no time granularity with the given display name exists
      Since:
        1.0
      See Also:
        `getName()`

    - #### getDelta

          public double getDelta(ITimeSpan span,
                                 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(Calendar s,
                                 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)`

    - #### isDisplayingMarkerType

          public boolean isDisplayingMarkerType(MarkerType type)

      Description copied from interface: `IGranularity`
      Determines whether markers of the given type will be shown in the timeline. It often does not make sense to show markers once a certain granularity (e.g. "decades") gets reached because then douzends of markers will clutter the screen.
      Specified by:
        `isDisplayingMarkerType` in interface `IGranularity<TimeGranularity>`
      Parameters:
        `type` - the type of marker to check
      Returns:
        TRUE if markers of the given type shall be displayed in the timeline

    - #### getFirstDayOfWeek

          public static int getFirstDayOfWeek()

      Returns the first day of the week (e.g. Calendar.MONDAY).
      Returns:
        the first day of the week
      Since:
        1.1.6

    - #### setFirstDayOfWeek

          public static void setFirstDayOfWeek(int firstDayOfWeek)

      Sets the first day of the week (e.g. Sunday or Monday). Use the integer values defined by the `Calendar` class (e.g. Calendar.MONDAY).
      Parameters:
        `firstDayOfWeek` -
      Since:
        1.1.6

    - #### getSingularName

          public String getSingularName()

      Description copied from interface: `IGranularity`
      Returns the singular name of the granularity (e.g. "day" instead of "days").
      Specified by:
        `getSingularName` in interface `IGranularity<TimeGranularity>`
      Returns:
        the name of the granularity

Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.