public enum QuarterOfYear extends Enum<QuarterOfYear> implements 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.
Enum Constant and Description |
---|
Q1
The singleton instance for the first quarter-of-year, from January to March.
|
Q2
The singleton instance for the second quarter-of-year, from April to June.
|
Q3
The singleton instance for the third quarter-of-year, from July to September.
|
Q4
The singleton instance for the fourth quarter-of-year, from October to December.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
MonthOfYear |
getFirstMonthOfQuarter()
Gets the first of the three months that this quarter refers to.
|
int |
getValue()
Gets the quarter-of-year
int 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.
|
QuarterOfYear |
next()
Gets the next quarter-of-year.
|
static QuarterOfYear |
of(int quarterOfYear)
Obtains an instance of
QuarterOfYear from an int value. |
QuarterOfYear |
previous()
Gets the previous quarter-of-year.
|
QuarterOfYear |
roll(int quarters)
Rolls the quarter-of-year, adding the specified number of quarters.
|
static QuarterOfYear |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static QuarterOfYear[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final QuarterOfYear Q1
1
.public static final QuarterOfYear Q2
2
.public static final QuarterOfYear Q3
3
.public static final QuarterOfYear Q4
4
.public static QuarterOfYear[] values()
for (QuarterOfYear c : QuarterOfYear.values()) System.out.println(c);
public static QuarterOfYear valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static QuarterOfYear of(int quarterOfYear)
QuarterOfYear
from an int
value.
QuarterOfYear
is an enum representing the 4 quarters of the year.
This factory allows the enum to be obtained from the int
value.
The int
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.
quarterOfYear
- the quarter-of-year to represent, from 1 (Q1) to 4 (Q4)IllegalCalendarFieldValueException
- if the quarter-of-year is invalidpublic int getValue()
int
value.
The values are numbered following the ISO-8601 standard, from 1 (Q1) to 4 (Q4).
public <T> T get(CalendricalRule<T> rule)
This returns the one of the quarter values if the type of the rule
is QuarterOfYear
. Other rules will return null
.
get
in interface Calendrical
rule
- the rule to use, not nullpublic boolean isQ1()
public boolean isQ2()
public boolean isQ3()
public boolean isQ4()
public QuarterOfYear next()
This calculates based on the time-line, thus it rolls around the end of the week. The next quarter after Q4 is Q1.
public QuarterOfYear previous()
This calculates based on the time-line, thus it rolls around the end of the year. The previous quarter before Q1 is Q4.
public QuarterOfYear roll(int 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.
quarters
- the quarters to roll by, positive or negativepublic MonthOfYear getFirstMonthOfQuarter()
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.
Copyright © 2014. All rights reserved.