javax.time.calendar
Enum DayOfWeek

java.lang.Object
  extended by java.lang.Enum<DayOfWeek>
      extended by javax.time.calendar.DayOfWeek
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<DayOfWeek>, Calendrical, CalendricalMatcher

public enum DayOfWeek
extends java.lang.Enum<DayOfWeek>
implements Calendrical, CalendricalMatcher

A day-of-week, such as 'Tuesday'.

DayOfWeek is an enum representing the 7 days of the week - Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

The calendrical framework requires date-time fields to have an int value. The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday). It is recommended that applications use the enum rather than the int value to ensure code clarity.

This enum provides access to the localized textual form of the day-of-week. However, some countries assign different numeric values to the days, such as Sunday = 1. Applications requiring such a localized numbering scheme should use WeekRules.

Do not use ordinal() to obtain the numeric representation of DayOfWeek. 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 day-of-week concept defined exactly equivalent to the ISO calendar system.

This is an immutable and thread-safe enum.

Author:
Michael Nascimento Santos, Stephen Colebourne

Enum Constant Summary
FRIDAY
          The singleton instance for the day-of-week of Friday.
MONDAY
          The singleton instance for the day-of-week of Monday.
SATURDAY
          The singleton instance for the day-of-week of Saturday.
SUNDAY
          The singleton instance for the day-of-week of Sunday.
THURSDAY
          The singleton instance for the day-of-week of Thursday.
TUESDAY
          The singleton instance for the day-of-week of Tuesday.
WEDNESDAY
          The singleton instance for the day-of-week of Wednesday.
 
Method Summary
static DayOfWeek from(Calendrical... calendricals)
          Obtains an instance of DayOfWeek from a set of calendricals.
<T> T
get(CalendricalRule<T> ruleToDerive)
          Gets the value of the specified calendrical rule.
 java.lang.String getText(TextStyle style, java.util.Locale locale)
          Gets the textual representation, such as 'Mon' or 'Friday'.
 int getValue()
          Gets the day-of-week int value.
 boolean matchesCalendrical(Calendrical calendrical)
          Checks if the day-of-month extracted from the calendrical matches this.
 DayOfWeek next()
          Gets the next day-of-week.
static DayOfWeek of(int dayOfWeek)
          Obtains an instance of DayOfWeek from an int value.
 DayOfWeek previous()
          Gets the previous day-of-week.
 DayOfWeek roll(int days)
          Rolls the day-of-week, adding the specified number of days.
static CalendricalRule<DayOfWeek> rule()
          Gets the rule for DayOfWeek.
 DateTimeField toField()
          Converts this day-of-week to an equivalent field.
static DayOfWeek valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static DayOfWeek[] 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

MONDAY

public static final DayOfWeek MONDAY
The singleton instance for the day-of-week of Monday. This has the numeric value of 1.


TUESDAY

public static final DayOfWeek TUESDAY
The singleton instance for the day-of-week of Tuesday. This has the numeric value of 2.


WEDNESDAY

public static final DayOfWeek WEDNESDAY
The singleton instance for the day-of-week of Wednesday. This has the numeric value of 3.


THURSDAY

public static final DayOfWeek THURSDAY
The singleton instance for the day-of-week of Thursday. This has the numeric value of 4.


FRIDAY

public static final DayOfWeek FRIDAY
The singleton instance for the day-of-week of Friday. This has the numeric value of 5.


SATURDAY

public static final DayOfWeek SATURDAY
The singleton instance for the day-of-week of Saturday. This has the numeric value of 6.


SUNDAY

public static final DayOfWeek SUNDAY
The singleton instance for the day-of-week of Sunday. This has the numeric value of 7.

Method Detail

values

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

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

valueOf

public static DayOfWeek 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
java.lang.NullPointerException - if the argument is null

rule

public static CalendricalRule<DayOfWeek> rule()
Gets the rule for DayOfWeek.

This rule is a calendrical rule based on DayOfWeek. The equivalent date-time rule is ISODateTimeRule.DAY_OF_WEEK.

Returns:
the rule for the day-of-week, not null

of

public static DayOfWeek of(int dayOfWeek)
Obtains an instance of DayOfWeek from an int value.

DayOfWeek is an enum representing the 7 days of the week. This factory allows the enum to be obtained from the int value. The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).

An exception is thrown if the value is invalid.

Parameters:
dayOfWeek - the day-of-week to represent, from 1 (Monday) to 7 (Sunday)
Returns:
the DayOfWeek singleton, not null
Throws:
IllegalCalendarFieldValueException - if the day-of-week is invalid

from

public static DayOfWeek from(Calendrical... calendricals)
Obtains an instance of DayOfWeek from a set of calendricals.

A calendrical represents some form of date and time information. This method combines the input calendricals into a day-of-week.

Parameters:
calendricals - the calendricals to create a day-of-week from, no nulls, not null
Returns:
the day-of-week, not null
Throws:
CalendricalException - if unable to merge to a day-of-week

get

public <T> T get(CalendricalRule<T> ruleToDerive)
Gets the value of the specified calendrical rule.

This will only return a value for the ISODateTimeRule.DAY_OF_WEEK rule, or something derivable from it.

Specified by:
get in interface Calendrical
Parameters:
ruleToDerive - the rule to derive, not null
Returns:
the value for the rule, null if the value cannot be returned

getValue

public int getValue()
Gets the day-of-week int value.

The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).

Returns:
the day-of-week, from 1 (Monday) to 7 (Sunday)

getText

public java.lang.String getText(TextStyle style,
                                java.util.Locale locale)
Gets the textual representation, such as 'Mon' or 'Friday'.

This enum uses the ISODateTimeRule.DAY_OF_WEEK rule to obtain the text. This allows the text to be localized by language, but not by chronology.

If no textual mapping is found then the numeric value is returned.

Parameters:
locale - the locale to use, not null
Returns:
the short text value of the day-of-week, not null

next

public DayOfWeek next()
Gets the next day-of-week.

This calculates based on the time-line, thus it rolls around the end of the week. The next day after Sunday is Monday.

Returns:
the next day-of-week, not null

previous

public DayOfWeek previous()
Gets the previous day-of-week.

This calculates based on the time-line, thus it rolls around the end of the week. The previous day before Monday is Sunday.

Returns:
the previous day-of-week, not null

roll

public DayOfWeek roll(int days)
Rolls the day-of-week, adding the specified number of days.

This calculates based on the time-line, thus it rolls around the end of the week from Sunday to Monday. The days to roll by may be negative.

This instance is immutable and unaffected by this method call.

Parameters:
days - the days to roll by, positive or negative
Returns:
the resulting day-of-week, not null

matchesCalendrical

public boolean matchesCalendrical(Calendrical calendrical)
Checks if the day-of-month extracted from the calendrical matches this.

This method implements the CalendricalMatcher interface. It is intended that applications use LocalDate.matches(javax.time.calendar.CalendricalMatcher) rather than this method.

Specified by:
matchesCalendrical in interface CalendricalMatcher
Parameters:
calendrical - the calendrical to match, not null
Returns:
true if the calendrical matches, false otherwise

toField

public DateTimeField toField()
Converts this day-of-week to an equivalent field.

The field is based on ISODateTimeRule.DAY_OF_WEEK.

Returns:
the equivalent day-of-week field, not null