Package net.time4j

Enum Class Quarter

All Implemented Interfaces:
Serializable, Comparable<Quarter>, java.lang.constant.Constable, Function<PlainDate,​PlainDate>, Predicate<GregorianDate>, UnaryOperator<PlainDate>, ChronoCondition<GregorianDate>, ChronoOperator<PlainDate>

public enum Quarter extends Enum<Quarter> implements ChronoCondition<GregorianDate>, ChronoOperator<PlainDate>

Represents a quarter (in most cases of a year).

Author:
Meno Hochschild
  • Enum Constant Details

    • Q1

      public static final Quarter Q1

      First quarter with the numerical value 1.

    • Q2

      public static final Quarter Q2

      Second quarter with the numerical value 2.

    • Q3

      public static final Quarter Q3

      Third quarter with the numerical value 3.

    • Q4

      public static final Quarter Q4

      Last quarter with the numerical value 4.

  • Method Details

    • values

      public static Quarter[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Quarter valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • valueOf

      public static Quarter valueOf(int quarter)

      Gets the enum-constant which corresponds to the given numerical value.

      Parameters:
      quarter - value in the range [1-4]
      Returns:
      enum
      Throws:
      IllegalArgumentException - if given argument is out of range
    • getValue

      public int getValue()

      Gets the corresponding numerical value.

      Returns:
      int (Q1 = 1, Q2 = 2, Q3 = 3, Q4 = 4)
    • next

      public Quarter next()

      Rolls to the next quarter.

      The result is Q1 if this method is applied on Q4.

      Returns:
      next quarter rolling at last quarter
    • previous

      public Quarter previous()

      Rolls to the previous quarter.

      The result is Q4 if this method is applied on Q1.

      Returns:
      previous quarter rolling at first quarter
    • roll

      public Quarter roll(int quarters)

      Rolls by given amount of quarters.

      Parameters:
      quarters - count of quarters (maybe negative)
      Returns:
      result of rolling operation
    • getDisplayName

      public String getDisplayName(Locale locale)

      Equivalent to the expression getDisplayName(locale, TextWidth.WIDE, OutputContext.FORMAT).

      Parameters:
      locale - language setting
      Returns:
      descriptive text (long form, never null)
      See Also:
      getDisplayName(Locale, TextWidth, OutputContext)
    • getDisplayName

      public String getDisplayName(Locale locale, TextWidth width, OutputContext context)

      Gets the description text dependent on the locale and style parameters.

      The second argument controls the width of description while the third argument is only relevant for languages which make a difference between stand-alone forms and embedded text forms (does not matter in English).

      Parameters:
      locale - language setting
      width - text width
      context - output context
      Returns:
      descriptive text for given locale and style (never null)
    • parse

      public static Quarter parse(CharSequence text, Locale locale, TextWidth width, OutputContext context) throws ParseException

      Tries to interprete given text as quarter of year.

      Parameters:
      text - the text to be parsed
      locale - language setting
      width - expected text width
      context - expected output context
      Returns:
      the parsed quarter of year if successful
      Throws:
      ParseException - if parsing fails
      Since:
      3.33/4.28
      See Also:
      getDisplayName(Locale, TextWidth, OutputContext)
    • test

      public boolean test(GregorianDate context)
      Description copied from interface: ChronoCondition

      Decides if given context matches this condition.

      Due to better readability it is recommended to use following equivalent approach instead of this method::

        import static net.time4j.Weekday.SATURDAY;
        import static net.time4j.Month.JANUARY;
      
        PlainDate date = PlainDate.of(2014, JANUARY, 25);
        System.out.println(SATURDAY.test(date)); // direct use
        System.out.println(date.matches(SATURDAY)); // recommended callback
       
      Specified by:
      test in interface ChronoCondition<GregorianDate>
      Specified by:
      test in interface Predicate<GregorianDate>
      Parameters:
      context - context as base of testing this condition
      Returns:
      true if given time context matches this condition else false
    • apply

      public PlainDate apply(PlainDate date)
      Description copied from interface: ChronoOperator

      Adjusts given entity and yields a changed copy of argument.

      Will be called by ChronoEntity.with(ChronoOperator).

      Specified by:
      apply in interface ChronoOperator<PlainDate>
      Specified by:
      apply in interface Function<PlainDate,​PlainDate>
      Parameters:
      date - chronological entity to be adjusted
      Returns:
      adjusted copy of argument which itself remains unaffected