Enum Class QuarterOfYear
- All Implemented Interfaces:
Serializable
,Comparable<QuarterOfYear>
,Constable
,Calendrical
QuarterOfYear
is an enum representing the 4 quarters of the year -
Q1, Q2, Q3 and Q4. These are defined as January to March, April to June,
July to September and October to December.
The calendrical framework requires date-time fields to have an int
value.
The int
value follows the quarter, from 1 (Q1) to 4 (Q4).
It is recommended that applications use the enum rather than the int
value
to ensure code clarity.
Do not use ordinal()
to obtain the numeric representation of QuarterOfYear
.
Use getValue()
instead.
This enum represents a common concept that is found in many calendar systems.
As such, this enum may be used by any calendar system that has the quarter-of-year
concept with a 4 quarter year where the names are equivalent to those defined.
Note that the implementation of DateTimeFieldRule
for quarter-of-year may
vary by calendar system.
QuarterOfYear is an immutable and thread-safe enum.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe singleton instance for the first quarter-of-year, from January to March.The singleton instance for the second quarter-of-year, from April to June.The singleton instance for the third quarter-of-year, from July to September.The singleton instance for the fourth quarter-of-year, from October to December. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
get
(CalendricalRule<T> rule) Gets the value of the specified calendrical rule.Gets the first of the three months that this quarter refers to.int
getValue()
Gets the quarter-of-yearint
value.boolean
isQ1()
Is this instance representing Q1, from January to March inclusive.boolean
isQ2()
Is this instance representing Q2, from April to June inclusive.boolean
isQ3()
Is this instance representing Q3, from July to September inclusive.boolean
isQ4()
Is this instance representing Q4, from October to December inclusive.next()
Gets the next quarter-of-year.static QuarterOfYear
of
(int quarterOfYear) Obtains an instance ofQuarterOfYear
from anint
value.previous()
Gets the previous quarter-of-year.roll
(int quarters) Rolls the quarter-of-year, adding the specified number of quarters.static QuarterOfYear
Returns the enum constant of this class with the specified name.static QuarterOfYear[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
Q1
The singleton instance for the first quarter-of-year, from January to March. This has the numeric value of1
. -
Q2
The singleton instance for the second quarter-of-year, from April to June. This has the numeric value of2
. -
Q3
The singleton instance for the third quarter-of-year, from July to September. This has the numeric value of3
. -
Q4
The singleton instance for the fourth quarter-of-year, from October to December. This has the numeric value of4
.
-
-
Constructor Details
-
QuarterOfYear
private QuarterOfYear()
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
of
Obtains an instance ofQuarterOfYear
from anint
value.QuarterOfYear
is an enum representing the 4 quarters of the year. This factory allows the enum to be obtained from theint
value. Theint
value follows the quarter, from 1 (Q1) to 4 (Q4).An exception is thrown if the value is invalid. The exception uses the
ISOChronology
quarter-of-year rule to indicate the failed rule.- Parameters:
quarterOfYear
- the quarter-of-year to represent, from 1 (Q1) to 4 (Q4)- Returns:
- the QuarterOfYear singleton, never null
- Throws:
IllegalCalendarFieldValueException
- if the quarter-of-year is invalid
-
getValue
public int getValue()Gets the quarter-of-yearint
value.The values are numbered following the ISO-8601 standard, from 1 (Q1) to 4 (Q4).
- Returns:
- the quarter-of-year, from 1 (Q1) to 4 (Q4)
-
get
Gets the value of the specified calendrical rule.This returns the one of the quarter values if the type of the rule is
QuarterOfYear
. Other rules will returnnull
.- Specified by:
get
in interfaceCalendrical
- Parameters:
rule
- the rule to use, not null- Returns:
- the value for the rule, null if the value cannot be returned
-
isQ1
public boolean isQ1()Is this instance representing Q1, from January to March inclusive.- Returns:
- true if this instance represents Q1
-
isQ2
public boolean isQ2()Is this instance representing Q2, from April to June inclusive.- Returns:
- true if this instance represents Q2
-
isQ3
public boolean isQ3()Is this instance representing Q3, from July to September inclusive.- Returns:
- true if this instance represents Q3
-
isQ4
public boolean isQ4()Is this instance representing Q4, from October to December inclusive.- Returns:
- true if this instance represents Q4
-
next
Gets the next quarter-of-year.This calculates based on the time-line, thus it rolls around the end of the week. The next quarter after Q4 is Q1.
- Returns:
- the next quarter-of-year, never null
-
previous
Gets the previous quarter-of-year.This calculates based on the time-line, thus it rolls around the end of the year. The previous quarter before Q1 is Q4.
- Returns:
- the previous quarter-of-year, never null
-
roll
Rolls the quarter-of-year, adding the specified number of quarters.This calculates based on the time-line, thus it rolls around the end of the year from Q4 to Q1. The quarters to roll by may be negative.
This instance is immutable and unaffected by this method call.
- Parameters:
quarters
- the quarters to roll by, positive or negative- Returns:
- the resulting quarter-of-year, never null
-
getFirstMonthOfQuarter
Gets the first of the three months that this quarter refers to.Q1 will return January.
Q2 will return April.
Q3 will return July.
Q4 will return October.To obtain the other two months of the quarter, simply use
MonthOfYear.next()
on the returned month.- Returns:
- the first month in the quarter, never null
-