ProgramixGenericLib v5.0.1

com.programix.time
Class DayOfWeek

java.lang.Object
  extended by com.programix.time.DayOfWeek
All Implemented Interfaces:
Serializable, Comparable<DayOfWeek>

public final class DayOfWeek
extends Object
implements Serializable, Comparable<DayOfWeek>

An enumeration of the days of the week in the Gregorian calendar and the US English language. Also following both Java's placement of Sunday as the first day in Calendar (at least as far as its constant value goes) and the traditions of the US, Sunday (not Monday) is set as the first day of the week.

If instead you want to do sorting with Monday being the first day of the week, there is a Comparator that handles that: MONDAY_TO_SUNDAY_COMPARATOR.

Author:
Paul Hyde
See Also:
Serialized Form

Field Summary
static DayOfWeek FRIDAY
          The day of the week called Friday.
static DayOfWeek MONDAY
          The day of the week called Monday.
static Comparator<DayOfWeek> MONDAY_TO_SUNDAY_COMPARATOR
          Sorts as Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday with no protection against null's.
static Comparator<DayOfWeek> MONDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR
          Sorts as null, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (with any null's coming first).
static Comparator<DayOfWeek> MONDAY_TO_SUNDAY_NULL_LAST_COMPARATOR
          Sorts as Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, null (with any null's coming last).
static DayOfWeek SATURDAY
          The day of the week called Saturday.
static Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_COMPARATOR
          Sorts as Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday with no protection against null's.
static Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR
          Sorts as null, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday (with any null's coming first).
static Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_NULL_LAST_COMPARATOR
          Sorts as Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday, null (with any null's coming last).
static DayOfWeek SUNDAY
          The day of the week called Sunday.
static Comparator<DayOfWeek> SUNDAY_TO_MONDAY_COMPARATOR
          Sorts as Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday with no protection against null's.
static Comparator<DayOfWeek> SUNDAY_TO_MONDAY_NULL_FIRST_COMPARATOR
          Sorts as null, Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday (with any null's coming first).
static Comparator<DayOfWeek> SUNDAY_TO_MONDAY_NULL_LAST_COMPARATOR
          Sorts as Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday null (with any null's coming last).
static Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_COMPARATOR
          Sorts as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday with no protection against null's.
static Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_NULL_FIRST_COMPARATOR
          Sorts as null, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (with any null's coming first).
static Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_NULL_LAST_COMPARATOR
          Sorts as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, null (with any null's coming last).
static DayOfWeek THURSDAY
          The day of the week called Thursday.
static DayOfWeek TUESDAY
          The day of the week called Tuesday.
static List<DayOfWeek> VALUE_LIST
          An unmodifiable List of all the instances of DayOfWeek.
static DayOfWeek WEDNESDAY
          The day of the week called Wednesday.
 
Method Summary
 int compareTo(DayOfWeek other)
          The "natural ordering" considers Sunday to be the first day of the week.
static DayOfWeek convertFromCalendar(int calendarDayOfWeek)
          Returns one of the DayOfWeek instances converted from the value from the "day of week" field of java.util.Calendar.
 boolean equals(Object obj)
           
 int getDaysUntil(DayOfWeek target)
          Returns the number of days from this day of the week until the specified target day of the week which is always in the range 0..6.
 String getDisplayNameFull()
          Returns the full US English name of the day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday).
 String getDisplayNameMedium()
          Returns the 3-char US English abbreviation for the day (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
 String getDisplayNameShort()
          Returns the 2-char US English abbreviation for the day (Su, Mo, Tu, We, Th, Fr, Sa).
 String getName()
          Returns the name of the constant in Java (all caps: SUNDAY, MONDAY, etc).
static DayOfWeek[] getValues()
          Returns an array of all the instances of DayOfWeek.
 int hashCode()
           
 boolean isFriday()
           
 boolean isMonday()
           
 boolean isNotFriday()
           
 boolean isNotMonday()
           
 boolean isNotSaturday()
           
 boolean isNotSunday()
           
 boolean isNotThursday()
           
 boolean isNotTuesday()
           
 boolean isNotWednesday()
           
 boolean isSaturday()
           
 boolean isSunday()
           
 boolean isThursday()
           
 boolean isTuesday()
           
 boolean isWednesday()
           
 String toString()
           
static DayOfWeek valueOf(String name)
          Returns the instance whose getName() method returns a String that matches the name passed in.
static DayOfWeek valueOfDisplayNameFull(String fullName)
          Returns the instance whose getDisplayNameFull() method returns a String that matches the name passed in.
static DayOfWeek valueOfDisplayNameMedium(String mediumName)
          Returns the instance whose getDisplayNameMedium() method returns a String that matches the name passed in.
static DayOfWeek valueOfDisplayNameShort(String shortName)
          Returns the instance whose getDisplayNameShort() method returns a String that matches the name passed in.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUNDAY

public static final DayOfWeek SUNDAY
The day of the week called Sunday. Default sorting considers Sunday to be the first day of the week.
Name Display Name
FullMediumShort
SUNDAYSundaySunSu
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


MONDAY

public static final DayOfWeek MONDAY
The day of the week called Monday. Default sorting considers Sunday to be the first day of the week.
Name Display Name
FullMediumShort
MONDAYMondayMonMo
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


TUESDAY

public static final DayOfWeek TUESDAY
The day of the week called Tuesday.
Name Display Name
FullMediumShort
TUESDAYTuesdayTueTu
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


WEDNESDAY

public static final DayOfWeek WEDNESDAY
The day of the week called Wednesday.
Name Display Name
FullMediumShort
WEDNESDAYWednesdayWedWe
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


THURSDAY

public static final DayOfWeek THURSDAY
The day of the week called Thursday.
Name Display Name
FullMediumShort
THURSDAYThursdayThuTh
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


FRIDAY

public static final DayOfWeek FRIDAY
The day of the week called Friday.
Name Display Name
FullMediumShort
FRIDAYFridayFriFr
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


SATURDAY

public static final DayOfWeek SATURDAY
The day of the week called Saturday. Default sorting considers Sunday to be the first day of the week and Saturday to be the last day of the week.
Name Display Name
FullMediumShort
SATURDAYSaturdaySatSa
For access to all four names, use getName(), getDisplayNameFull(), getDisplayNameMedium(), and getDisplayNameShort().


VALUE_LIST

public static final List<DayOfWeek> VALUE_LIST
An unmodifiable List of all the instances of DayOfWeek.


SUNDAY_TO_SATURDAY_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_COMPARATOR
Sorts as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday with no protection against null's.


SUNDAY_TO_SATURDAY_NULL_FIRST_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_NULL_FIRST_COMPARATOR
Sorts as null, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (with any null's coming first).


SUNDAY_TO_SATURDAY_NULL_LAST_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_SATURDAY_NULL_LAST_COMPARATOR
Sorts as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, null (with any null's coming last).


SATURDAY_TO_SUNDAY_COMPARATOR

public static final Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_COMPARATOR
Sorts as Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday with no protection against null's.


SATURDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR

public static final Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR
Sorts as null, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday (with any null's coming first).


SATURDAY_TO_SUNDAY_NULL_LAST_COMPARATOR

public static final Comparator<DayOfWeek> SATURDAY_TO_SUNDAY_NULL_LAST_COMPARATOR
Sorts as Saturday, Friday, Thursday, Wednesday, Tuesday, Monday, Sunday, null (with any null's coming last).


MONDAY_TO_SUNDAY_COMPARATOR

public static final Comparator<DayOfWeek> MONDAY_TO_SUNDAY_COMPARATOR
Sorts as Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday with no protection against null's.


MONDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR

public static final Comparator<DayOfWeek> MONDAY_TO_SUNDAY_NULL_FIRST_COMPARATOR
Sorts as null, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (with any null's coming first).


MONDAY_TO_SUNDAY_NULL_LAST_COMPARATOR

public static final Comparator<DayOfWeek> MONDAY_TO_SUNDAY_NULL_LAST_COMPARATOR
Sorts as Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, null (with any null's coming last).


SUNDAY_TO_MONDAY_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_MONDAY_COMPARATOR
Sorts as Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday with no protection against null's.


SUNDAY_TO_MONDAY_NULL_FIRST_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_MONDAY_NULL_FIRST_COMPARATOR
Sorts as null, Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday (with any null's coming first).


SUNDAY_TO_MONDAY_NULL_LAST_COMPARATOR

public static final Comparator<DayOfWeek> SUNDAY_TO_MONDAY_NULL_LAST_COMPARATOR
Sorts as Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday null (with any null's coming last).

Method Detail

getValues

public static DayOfWeek[] getValues()
Returns an array of all the instances of DayOfWeek. A cloned copy is returned, so no special care is required.


valueOf

public static DayOfWeek valueOf(String name)
                         throws IllegalArgumentException
Returns the instance whose getName() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
name - the name to search for.
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

valueOfDisplayNameFull

public static DayOfWeek valueOfDisplayNameFull(String fullName)
                                        throws IllegalArgumentException
Returns the instance whose getDisplayNameFull() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
fullName - the name to search for (Sunday, Monday, etc.)
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

valueOfDisplayNameMedium

public static DayOfWeek valueOfDisplayNameMedium(String mediumName)
                                          throws IllegalArgumentException
Returns the instance whose getDisplayNameMedium() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
mediumName - the name to search for (Sun, Mon, etc.)
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

valueOfDisplayNameShort

public static DayOfWeek valueOfDisplayNameShort(String shortName)
                                         throws IllegalArgumentException
Returns the instance whose getDisplayNameShort() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
shortName - the name to search for (Su, Mo, Tu, etc.)
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

convertFromCalendar

public static DayOfWeek convertFromCalendar(int calendarDayOfWeek)
                                     throws IllegalArgumentException
Returns one of the DayOfWeek instances converted from the value from the "day of week" field of java.util.Calendar.

Parameters:
calendarDayOfWeek - value from the "day of week" field of java.util.Calendar.
Returns:
one of the instances of this class
Throws:
IllegalArgumentException - if the "day of week" code passed in does not make sense.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(DayOfWeek other)
The "natural ordering" considers Sunday to be the first day of the week. If you want to consider Monday to be the first day of the week, then consider using MONDAY_TO_SUNDAY_COMPARATOR.

Specified by:
compareTo in interface Comparable<DayOfWeek>

getName

public String getName()
Returns the name of the constant in Java (all caps: SUNDAY, MONDAY, etc).


getDisplayNameFull

public String getDisplayNameFull()
Returns the full US English name of the day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday).


getDisplayNameMedium

public String getDisplayNameMedium()
Returns the 3-char US English abbreviation for the day (Sun, Mon, Tue, Wed, Thu, Fri, Sat).


getDisplayNameShort

public String getDisplayNameShort()
Returns the 2-char US English abbreviation for the day (Su, Mo, Tu, We, Th, Fr, Sa).


getDaysUntil

public int getDaysUntil(DayOfWeek target)
Returns the number of days from this day of the week until the specified target day of the week which is always in the range 0..6. Zero is returned if the target is the same day of the week as this instance. The largest value ever returned is 6.
This instancetargetDays Until
TUESDAYWEDNESDAY1
TUESDAYFRIDAY3
TUESDAYSUNDAY5
TUESDAYMONDAY6
TUESDAYTUESDAY0
SATURDAYMONDAY2


isSunday

public boolean isSunday()

isNotSunday

public boolean isNotSunday()

isMonday

public boolean isMonday()

isNotMonday

public boolean isNotMonday()

isTuesday

public boolean isTuesday()

isNotTuesday

public boolean isNotTuesday()

isWednesday

public boolean isWednesday()

isNotWednesday

public boolean isNotWednesday()

isThursday

public boolean isThursday()

isNotThursday

public boolean isNotThursday()

isFriday

public boolean isFriday()

isNotFriday

public boolean isNotFriday()

isSaturday

public boolean isSaturday()

isNotSaturday

public boolean isNotSaturday()

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.