JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.calendar
Class JCCalendar

java.lang.Object
  |
  +--com.klg.jclass.util.calendar.JCCalendar

public class JCCalendar
extends Object

For use in conjunction with a standard java.util.Calendar. This component allows storage of special dates and then will match a given Calendar object to those dates.


Nested Class Summary
static class JCCalendar.DateMonthYear
          Class to store a DateMonthYear value.
static class JCCalendar.DayOfWeek
          Class to store a day of the week.
static class JCCalendar.MonthDayOfMonth
          Class to store Month and Day of Month.
 class JCCalendar.MonthWeekDayOfWeek
          Class to store a Month, Week, and Day of Week.
 
Field Summary
protected static byte[][] daytable
           
protected  Vector specialDates
           
 
Constructor Summary
JCCalendar()
           
 
Method Summary
 void addSpecialDate(com.klg.jclass.util.calendar.SpecialDate sd)
          Adds a special day given a date, month and year.
static Object convertCalendarToObject(Calendar from, Class classType)
          Converts the Calendar object to an object designed by the class_type, if its one of the supported class types.
static Calendar convertObjectToCalendar(Object obj, Locale l)
          Converts the specified type (if possible) to a supported type.
static Calendar copyCalendar(Calendar cal)
          Convenience method to clone a calendar.
static int dayOfWeek(int date, int month, int year)
          Calculates the day of week given the date, month, and year.
static int daysInMonth(int month, int year)
          Calculates the number of days in a given month.
static String[] getDays(Locale l)
          Gets the list of short week day names for a given locale.
static String[] getMonths(Locale l, boolean isShort)
          Gets the list of short or long month names for a given locale.
protected  int isInSpecialDateList(int year, int month, int date, int week)
          Returns the index in the specialDays vector if the object is in the list.
static boolean isLeapYear(int year)
          Checks to see if the year is a leap year.
 boolean isSpecialDate(Calendar c)
          Determines is a specified date is a special date.
 boolean isSpecialDate(int year, int month, int date, int week)
          Determines if a specified date is a special date.
protected static String[] processArray(String[] input)
          Processes array for empty or null Strings and returns a new array with them stripped out.
 void removeSpecialDate(com.klg.jclass.util.calendar.SpecialDate sd)
          Removes a special day given a date, month, and year.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

specialDates

protected Vector specialDates

daytable

protected static final byte[][] daytable
Constructor Detail

JCCalendar

public JCCalendar()
Method Detail

isLeapYear

public static boolean isLeapYear(int year)
Checks to see if the year is a leap year. For Gregorian Calendars, centennial years are leap years only if they are multiples of 400. Otherwise, any year which is a multiple of 4 is a leap year.

Parameters:
year - the year to check
Returns:
whether the given year is a leap year

dayOfWeek

public static int dayOfWeek(int date,
                            int month,
                            int year)
Calculates the day of week given the date, month, and year. (for example, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday)

Parameters:
date - the day of the month
month - the month (0 to 11)
year - the year to use (for example, 1997)
Returns:
the day of the week (0 = Sunday, ..., 6 = Saturday)

daysInMonth

public static int daysInMonth(int month,
                              int year)
Calculates the number of days in a given month.

Parameters:
year - the year to use (for example, 1997)
month - the month (0 to 11)
Returns:
the number of days in the given month and year

processArray

protected static String[] processArray(String[] input)
Processes array for empty or null Strings and returns a new array with them stripped out.

Parameters:
input - the input array to be checked
Returns:
the new output array with no empty or null Strings

getDays

public static String[] getDays(Locale l)
Gets the list of short week day names for a given locale.

Parameters:
l - the locale for which the day names are required
Returns:
the list of short week day names (with nulls and empty Strings removed)

getMonths

public static String[] getMonths(Locale l,
                                 boolean isShort)
Gets the list of short or long month names for a given locale.

Parameters:
l - the locale for which the month names are required
isShort - if true, returns the short month names
Returns:
the list of month names (with nulls and empty Strings removed)

addSpecialDate

public void addSpecialDate(com.klg.jclass.util.calendar.SpecialDate sd)
Adds a special day given a date, month and year.

Parameters:
sd - the SpecialDate to add
See Also:
JCCalendar.DateMonthYear, JCCalendar.DayOfWeek, JCCalendar.MonthDayOfMonth, JCCalendar.MonthWeekDayOfWeek, removeSpecialDate(com.klg.jclass.util.calendar.SpecialDate)

removeSpecialDate

public void removeSpecialDate(com.klg.jclass.util.calendar.SpecialDate sd)
Removes a special day given a date, month, and year.

Parameters:
sd - the SpecialDate to remove
See Also:
JCCalendar.DateMonthYear, JCCalendar.DayOfWeek, JCCalendar.MonthDayOfMonth, JCCalendar.MonthWeekDayOfWeek, addSpecialDate(com.klg.jclass.util.calendar.SpecialDate)

isSpecialDate

public boolean isSpecialDate(int year,
                             int month,
                             int date,
                             int week)
Determines if a specified date is a special date.

Parameters:
year - the year to use (for example, 1997)
month - the month (0 to 11)
date - the day of the month
week - the week of the month
Returns:
true if the date specified has been designated as special

isSpecialDate

public boolean isSpecialDate(Calendar c)
Determines is a specified date is a special date.

Parameters:
c - the Calendar object which contains the specified date
Returns:
true if the date specified has been designated as special

isInSpecialDateList

protected int isInSpecialDateList(int year,
                                  int month,
                                  int date,
                                  int week)
Returns the index in the specialDays vector if the object is in the list. Otherwise, it returns -1.

Parameters:
year - the year to use (for example, 1997)
month - the month (0 to 11)
date - the day of the month
week - the week of the month
Returns:
the index in the specialDays vector if the object is in the list; otherwise, it returns -1

copyCalendar

public static Calendar copyCalendar(Calendar cal)
Convenience method to clone a calendar.

Parameters:
cal - the calendar object to clone
Returns:
the new calendar clone

convertObjectToCalendar

public static Calendar convertObjectToCalendar(Object obj,
                                               Locale l)
Converts the specified type (if possible) to a supported type. To reverse this operation, use the convertCalendarToSupported() method. The supported types are java.util.Date, java.util.Calendar, java.util.GregorianCalendar, java.sql.Time, java.sql.Timestamp, and java.sql.Date.

Parameters:
obj - The supported object to convert to Calendar.
l - The locale to use
Returns:
A Calendar object converted from the passed in supported object. If the object is not support, null is returned.
See Also:
convertCalendarToObject(java.util.Calendar, java.lang.Class)

convertCalendarToObject

public static Object convertCalendarToObject(Calendar from,
                                             Class classType)
Converts the Calendar object to an object designed by the class_type, if its one of the supported class types. The supported types are java.util.Date, java.util.Calendar, java.util.GregorianCalendar, java.sql.Time, java.sql.Timestamp, and java.sql.Date.
Note: The object passed in is not modified, but only used as a reference.

Parameters:
from - The Calendar object to convert.
classType - The supported type to which the Calendar object is converted. If the type is unsupported, null will be returned. The supported types are java.util.Date, java.util.Calendar, java.util.GregorianCalendar, java.sql.Time, java.sql.Timestamp, and java.sql.Date.
Returns:
An object of the requested type converted from the passed in Calendar object.
See Also:
convertObjectToCalendar(java.lang.Object, java.util.Locale)

Copyright © 2004 Quest Software Inc..
All rights reserved.