org.op4j.functions
Class FnDate

Object
  extended by org.op4j.functions.FnDate

public final class FnDate
extends Object

Since:
1.0
Author:
Daniel Fernández

Method Summary
static Function<Date,Date> add(int calendarField, int amount)
           Modifies a Date by adding a positive or negative amount to one of its fields.
static Function<Date,Date> addDays(int amount)
           Modifies a Date by adding a positive or negative amount to one the "day" property (java.util.Calendar.DATE).
static Function<Date,Date> addHours(int amount)
           Modifies a Date by adding a positive or negative amount to one the "hour" property (java.util.Calendar.HOUR).
static Function<Date,Date> addMilliseconds(int amount)
           Modifies a Date by adding a positive or negative amount to one the "millisecond" property (java.util.Calendar.MILLISECOND).
static Function<Date,Date> addMinutes(int amount)
           Modifies a Date by adding a positive or negative amount to one the "minutes" property (java.util.Calendar.MINUTES).
static Function<Date,Date> addMonths(int amount)
           Modifies a Date by adding a positive or negative amount to one the "month" property (java.util.Calendar.MONTH).
static Function<Date,Date> addWeeks(int amount)
           Modifies a Date by adding a positive or negative amount to one the "week" property (java.util.Calendar.WEEK).
static Function<Date,Date> addYears(int amount)
           Modifies a Date by adding a positive or negative amount to one the "year" property (java.util.Calendar.YEAR).
static Function<Date,Boolean> after(Date date)
           Determines whether the target Date represents a moment in time after the Date specified as a parameter.
static Function<Date,Boolean> before(Date date)
           Determines whether the target Date represents a moment in time before the Date specified as a parameter.
static Function<Object,Boolean> eq(Date object)
           Determines whether the target object and the specified object are equal by calling the equals method on the target object.
static Function<Integer[],Date> fieldIntegerArrayToDate()
           Converts an Integer[] containing the components of a date to a java.util.Date object.
static Function<List<Integer>,Date> fieldIntegerListToDate()
           Converts a List<Integer> containing the components of a date to a java.util.Date object.
static Function<String[],Date> fieldStringArrayToDate()
           Converts a String[] containing the components of a date to a java.util.Date object.
static Function<List<String>,Date> fieldStringListToDate()
           Converts a List<String> containing the components of a date to a java.util.Date object.
protected static Date fromInts(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second, Integer milli)
           
static Function<Object,Boolean> isNotNull()
           Determines whether the target object is null or not.
static Function<Object,Boolean> isNull()
           Determines whether the target object is null or not.
static Function<Object,Boolean> notEq(Date object)
           Determines whether the target object and the specified object are NOT equal by calling the equals method on the target object.
static Function<Date,Date> round(int calendarField)
           Rounds the target Date, setting the specified field as the most significant field.
static Function<Date,Date> set(int calendarField, int value)
           Modifies a Date by setting one of its to the specified value.
static Function<Date,Date> setDay(int value)
           Modifies a Date by setting the "day" property (java.util.Calendar.DATE) to the specified value.
static Function<Date,Date> setHour(int value)
           Modifies a Date by setting the "hour" property (java.util.Calendar.HOUR) to the specified value.
static Function<Date,Date> setMillisecond(int value)
           Modifies a Date by setting the "millisecond" property (java.util.Calendar.MILLISECOND) to the specified value.
static Function<Date,Date> setMinute(int value)
           Modifies a Date by setting the "minute" property (java.util.Calendar.MINUTE) to the specified value.
static Function<Date,Date> setMonth(int value)
           Modifies a Date by setting the "month" property (java.util.Calendar.MONTH) to the specified value.
static Function<Date,Date> setWeek(int value)
           Modifies a Date by setting the "week" property (java.util.Calendar.WEEK_OF_YEAR) to the specified value.
static Function<Date,Date> setYear(int value)
           Modifies a Date by setting the "year" property (java.util.Calendar.YEAR) to the specified value.
static Function<Long,Date> timeInMillisToDate()
           Converts the target Long (representing a time in milliseconds) into a Date.
static Function<Long,Date> timeInMillisToDate(int truncateField)
           Converts the target Long (representing a time in milliseconds) into a Date, truncating by the specified field (java.util.Calendar constant field).
static Function<Timestamp,Date> timestampToDate()
           Converts the target java.sql.Timestamp into a Date.
static Function<Timestamp,Date> timestampToDate(int truncateField)
           Converts the target java.sql.Timestamp into a Date, truncating by the specified field (java.util.Calendar constant field).
static Function<Date,Calendar> toCalendar()
           
static Function<Date,Calendar> toCalendar(int truncateField)
           
static Function<Date,String> toStr(DateStyle dateStyle, TimeStyle timeStyle)
           Converts the target Date into a String using the specified date (DateStyle) and time (TimeStyle) styles.
static Function<Date,String> toStr(DateStyle dateStyle, TimeStyle timeStyle, Locale locale)
           Converts the target Date into a String using the specified date (DateStyle) and time (TimeStyle) styles, and resolving text-based components like month names using the specified locale.
static Function<Date,String> toStr(DateStyle dateStyle, TimeStyle timeStyle, String locale)
           Converts the target Calendar into a String using the specified date (DateStyle) and time (TimeStyle) styles, and resolving text-based components like month names using the specified locale.
static Function<Date,String> toStr(String pattern)
           Converts the target Date into a String using the specified pattern.
static Function<Date,String> toStr(String pattern, Locale locale)
           Converts the target Date into a String using the specified pattern.
static Function<Date,String> toStr(String pattern, String locale)
           Converts the target Date into a String using the specified pattern.
static Function<Date,Date> truncate(int calendarField)
           Truncates the target Date, setting the specified field as the most significant field.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toCalendar

public static final Function<Date,Calendar> toCalendar()

toCalendar

public static final Function<Date,Calendar> toCalendar(int truncateField)

add

public static final Function<Date,Date> add(int calendarField,
                                            int amount)

Modifies a Date by adding a positive or negative amount to one of its fields.

Fields are specified by means of java.util.Calendar constants, like FnDate.add(Calendar.DAY_OF_MONTH, 1).

Parameters:
calendarField - the field that will be modified (java.util.Calendar constant).
amount - the positive or negative amount to be added
Returns:
the modified Date

addDays

public static final Function<Date,Date> addDays(int amount)

Modifies a Date by adding a positive or negative amount to one the "day" property (java.util.Calendar.DATE).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addHours

public static final Function<Date,Date> addHours(int amount)

Modifies a Date by adding a positive or negative amount to one the "hour" property (java.util.Calendar.HOUR).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addMilliseconds

public static final Function<Date,Date> addMilliseconds(int amount)

Modifies a Date by adding a positive or negative amount to one the "millisecond" property (java.util.Calendar.MILLISECOND).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addMinutes

public static final Function<Date,Date> addMinutes(int amount)

Modifies a Date by adding a positive or negative amount to one the "minutes" property (java.util.Calendar.MINUTES).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addMonths

public static final Function<Date,Date> addMonths(int amount)

Modifies a Date by adding a positive or negative amount to one the "month" property (java.util.Calendar.MONTH).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addWeeks

public static final Function<Date,Date> addWeeks(int amount)

Modifies a Date by adding a positive or negative amount to one the "week" property (java.util.Calendar.WEEK).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

addYears

public static final Function<Date,Date> addYears(int amount)

Modifies a Date by adding a positive or negative amount to one the "year" property (java.util.Calendar.YEAR).

Parameters:
amount - the positive or negative amount to be added
Returns:
the modified Date

set

public static final Function<Date,Date> set(int calendarField,
                                            int value)

Modifies a Date by setting one of its to the specified value.

Fields are specified by means of java.util.Calendar constants, like FnDate.set(Calendar.DAY_OF_MONTH, 12).

Parameters:
calendarField - the field that will be modified (java.util.Calendar constant).
value - the new value
Returns:
the modified Date

setDay

public static final Function<Date,Date> setDay(int value)

Modifies a Date by setting the "day" property (java.util.Calendar.DATE) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setHour

public static final Function<Date,Date> setHour(int value)

Modifies a Date by setting the "hour" property (java.util.Calendar.HOUR) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setMillisecond

public static final Function<Date,Date> setMillisecond(int value)

Modifies a Date by setting the "millisecond" property (java.util.Calendar.MILLISECOND) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setMinute

public static final Function<Date,Date> setMinute(int value)

Modifies a Date by setting the "minute" property (java.util.Calendar.MINUTE) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setMonth

public static final Function<Date,Date> setMonth(int value)

Modifies a Date by setting the "month" property (java.util.Calendar.MONTH) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setWeek

public static final Function<Date,Date> setWeek(int value)

Modifies a Date by setting the "week" property (java.util.Calendar.WEEK_OF_YEAR) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

setYear

public static final Function<Date,Date> setYear(int value)

Modifies a Date by setting the "year" property (java.util.Calendar.YEAR) to the specified value.

Parameters:
value - the new value for the property
Returns:
the modified Date

round

public static final Function<Date,Date> round(int calendarField)

Rounds the target Date, setting the specified field as the most significant field.

Based on org.apache.commons.lang.time.DateUtils.round().

Parameters:
calendarField - the field on which the Date will be rounded (java.util.Calendar field).
Returns:
the resulting Date

truncate

public static final Function<Date,Date> truncate(int calendarField)

Truncates the target Date, setting the specified field as the most significant field.

Based on org.apache.commons.lang.time.DateUtils.truncate().

Parameters:
calendarField - the field on which the Date will be truncated (java.util.Calendar field).
Returns:
the resulting Date

before

public static final Function<Date,Boolean> before(Date date)

Determines whether the target Date represents a moment in time before the Date specified as a parameter.

Parameters:
date - the date to compare to
Returns:
true if target is before, false otherwise

after

public static final Function<Date,Boolean> after(Date date)

Determines whether the target Date represents a moment in time after the Date specified as a parameter.

Parameters:
date - the date to compare to
Returns:
true if target is after, false otherwise

toStr

public static final Function<Date,String> toStr(String pattern)

Converts the target Date into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format.

As no locale is specified, if pattern includes locale-dependent texts like month names (MMM) or week days (EEE), the default locale will be used for resolving these components.

Parameters:
pattern - the pattern to be used, as specified by java.text.SimpleDateFormat.
Returns:
the String representation of the target Date.

toStr

public static final Function<Date,String> toStr(String pattern,
                                                Locale locale)

Converts the target Date into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format, and the specified locale will be used for text-based pattern components (like month names or week days).

Parameters:
pattern - the pattern to be used, as specified by java.text.SimpleDateFormat.
locale - the locale to be used for text-based pattern components
Returns:
the String representation of the target Date.

toStr

public static final Function<Date,String> toStr(String pattern,
                                                String locale)

Converts the target Date into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format, and the specified locale will be used for text-based pattern components (like month names or week days).

Parameters:
pattern - the pattern to be used, as specified by java.text.SimpleDateFormat.
locale - the locale to be used for text-based pattern components
Returns:
the String representation of the target Date.

toStr

public static final Function<Date,String> toStr(DateStyle dateStyle,
                                                TimeStyle timeStyle)

Converts the target Date into a String using the specified date (DateStyle) and time (TimeStyle) styles.

Parameters:
dateStyle - the date style to be used
timeStyle - the time style to be used
Returns:
the String representation of the Date.

toStr

public static final Function<Date,String> toStr(DateStyle dateStyle,
                                                TimeStyle timeStyle,
                                                Locale locale)

Converts the target Date into a String using the specified date (DateStyle) and time (TimeStyle) styles, and resolving text-based components like month names using the specified locale.

Parameters:
dateStyle - the date style to be used
timeStyle - the time style to be used
locale - the locale to be used
Returns:
the String representation of the Date.

toStr

public static final Function<Date,String> toStr(DateStyle dateStyle,
                                                TimeStyle timeStyle,
                                                String locale)

Converts the target Calendar into a String using the specified date (DateStyle) and time (TimeStyle) styles, and resolving text-based components like month names using the specified locale.

Parameters:
dateStyle - the date style to be used
timeStyle - the time style to be used
locale - the locale to be used
Returns:
the String representation of the Calendar.

timestampToDate

public static final Function<Timestamp,Date> timestampToDate()

Converts the target java.sql.Timestamp into a Date.

Returns:
the resulting Date.

timestampToDate

public static final Function<Timestamp,Date> timestampToDate(int truncateField)

Converts the target java.sql.Timestamp into a Date, truncating by the specified field (java.util.Calendar constant field).

Returns:
the resulting Date.

timeInMillisToDate

public static final Function<Long,Date> timeInMillisToDate()

Converts the target Long (representing a time in milliseconds) into a Date.

Returns:
the resulting Date.

timeInMillisToDate

public static final Function<Long,Date> timeInMillisToDate(int truncateField)

Converts the target Long (representing a time in milliseconds) into a Date, truncating by the specified field (java.util.Calendar constant field).

Returns:
the resulting Date.

fieldIntegerListToDate

public static final Function<List<Integer>,Date> fieldIntegerListToDate()

Converts a List<Integer> containing the components of a date to a java.util.Date object.

The target list can contain the following combinations of elements, in the specified order:

Returns:
the resulting Date

fieldIntegerArrayToDate

public static final Function<Integer[],Date> fieldIntegerArrayToDate()

Converts an Integer[] containing the components of a date to a java.util.Date object.

The target array can contain the following combinations of elements, in the specified order:

Returns:
the resulting Date

fieldStringListToDate

public static final Function<List<String>,Date> fieldStringListToDate()

Converts a List<String> containing the components of a date to a java.util.Date object.

The target list can contain the following combinations of elements, all of them in numeric format, in the specified order:

Returns:
the resulting Date

fieldStringArrayToDate

public static final Function<String[],Date> fieldStringArrayToDate()

Converts a String[] containing the components of a date to a java.util.Date object.

The target array can contain the following combinations of elements, all of them in numeric format, in the specified order:

Returns:
the resulting Date

eq

public static final Function<Object,Boolean> eq(Date object)

Determines whether the target object and the specified object are equal by calling the equals method on the target object.

Parameters:
object - the object to compare to the target
Returns:
true if both objects are equal, false if not.

notEq

public static final Function<Object,Boolean> notEq(Date object)

Determines whether the target object and the specified object are NOT equal by calling the equals method on the target object.

Parameters:
object - the object to compare to the target
Returns:
false if both objects are equal, true if not.

isNull

public static final Function<Object,Boolean> isNull()

Determines whether the target object is null or not.

Returns:
true if the target object is null, false if not.

isNotNull

public static final Function<Object,Boolean> isNotNull()

Determines whether the target object is null or not.

Returns:
false if the target object is null, true if not.

fromInts

protected static Date fromInts(Integer year,
                               Integer month,
                               Integer day,
                               Integer hour,
                               Integer minute,
                               Integer second,
                               Integer milli)
                        throws Exception
Throws:
Exception


Copyright © 2012 The OP4J team. All Rights Reserved.