Top Description Fields Constructors Methods
org.jooq.types

public final Class YearToMonth

extends Number
implements Interval, Comparable<YearToMonth>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, org.jooq.types.Interval, java.io.Serializable
Imports
java.time.Duration, java.util.regex.Matcher, .Pattern, org.jooq.Field, .SQLDialect

An implementation for the SQL standard INTERVAL YEAR TO MONTH data type.

YearToMonth is a Number whose Number#intValue() represents the number of months of the interval.

Note: only a few databases actually support this data type on its own. You can still use it for date time arithmetic in other databases, though, through Field#add(Field) and Field#sub(Field) Databases that have been observed to natively support INTERVAL data types are:

These dialects have been observed to partially support INTERVAL data types in date time arithmetic functions, such as TIMESTAMPADD, and TIMESTAMPDIFF:

Author
Lukas Eder
See Also
Interval

Field Summary

Modifier and TypeField and Description
private final int
private final boolean
private static final Pattern
private static final Pattern
private final int

Constructor Summary

AccessConstructor and Description
public
YearToMonth()

Create a new year-month interval.

public
YearToMonth(int years)

Create a new year-month interval.

public
YearToMonth(int years, int months)

Create a new year-month interval.

pack-priv
YearToMonth(int years, int months, boolean negative)

Method Summary

Modifier and TypeMethod and Description
public final YearToMonth
abs()

Implements org.jooq.types.Interval.abs.

Get the absolute value of the interval (set its sign to positive)
public final int
compareTo(YearToMonth
the object to be compared.
that
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public final double
doubleValue()

Implements abstract java.lang.Number.doubleValue.

Implements org.jooq.types.Interval.doubleValue.

Returns the value of the specified number as a double.
public final boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public final float
floatValue()

Implements abstract java.lang.Number.floatValue.

Implements org.jooq.types.Interval.floatValue.

Returns the value of the specified number as a float.
public final int
public final int
getSign()

Implements org.jooq.types.Interval.getSign.

The sign of the interval
public final int
public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public final int
intValue()

Implements abstract java.lang.Number.intValue.

Implements org.jooq.types.Interval.intValue.

Returns the value of the specified number as an int.
public final long
longValue()

Implements abstract java.lang.Number.longValue.

Implements org.jooq.types.Interval.longValue.

Returns the value of the specified number as a long.
public static YearToMonth

Returns:

The parsed MONTH object, or null if the string could not be parsed.
month
(String
A string representation of the form [+|-][months]
string
)

Parse a standard SQL string representation of a INTERVAL MONTH.

public final YearToMonth
neg()

Implements org.jooq.types.Interval.neg.

Negate the interval (change its sign)
public final Duration
toDuration()

Implements org.jooq.types.Interval.toDuration.

Get a duration representation of this interval.
public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static YearToMonth

Returns:

The parsed YEAR TO MONTH object, or null if the string could not be parsed.
valueOf
(String
A string representation of the form [+|-][years]-[months]
string
)

Parse a string representation of a INTERVAL YEAR TO MONTH.

public static YearToMonth

Returns:

The parsed YEAR object, or null if the string could not be parsed.
year
(String
A string representation of the form [+|-][years]
string
)

Parse a standard SQL string representation of a INTERVAL YEAR.

public static YearToMonth

Returns:

The parsed YEAR TO MONTH object, or null if the string could not be parsed.
yearToMonth
(String
A string representation of the form [+|-][years]-[months]
string
)

Parse a standard SQL string representation of a INTERVAL YEAR TO MONTH.

Inherited from java.lang.Number:
byteValueshortValue

Field Detail

monthsback to summary
private final int months
negativeback to summary
private final boolean negative
PATTERN_ISOback to summary
private static final Pattern PATTERN_ISO
PATTERN_SQLback to summary
private static final Pattern PATTERN_SQL
yearsback to summary
private final int years

Constructor Detail

YearToMonthback to summary
public YearToMonth()

Create a new year-month interval.

YearToMonthback to summary
public YearToMonth(int years)

Create a new year-month interval.

YearToMonthback to summary
public YearToMonth(int years, int months)

Create a new year-month interval.

YearToMonthback to summary
pack-priv YearToMonth(int years, int months, boolean negative)

Method Detail

absback to summary
public final YearToMonth abs()

Implements org.jooq.types.Interval.abs.

Doc from org.jooq.types.Interval.abs.

Get the absolute value of the interval (set its sign to positive)

Annotations
@Override
compareToback to summary
public final int compareTo(YearToMonth that)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
that:YearToMonth

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
doubleValueback to summary
public final double doubleValue()

Implements abstract java.lang.Number.doubleValue.

Implements org.jooq.types.Interval.doubleValue.

Doc from java.lang.Number.doubleValue.

Returns the value of the specified number as a double.

Returns:double

the numeric value represented by this object after conversion to type double.

Annotations
@Override
equalsback to summary
public final boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
floatValueback to summary
public final float floatValue()

Implements abstract java.lang.Number.floatValue.

Implements org.jooq.types.Interval.floatValue.

Doc from java.lang.Number.floatValue.

Returns the value of the specified number as a float.

Returns:float

the numeric value represented by this object after conversion to type float.

Annotations
@Override
getMonthsback to summary
public final int getMonths()
getSignback to summary
public final int getSign()

Implements org.jooq.types.Interval.getSign.

Doc from org.jooq.types.Interval.getSign.

The sign of the interval

Returns:int

1 for positive or zero, -1 for negative

Annotations
@Override
getYearsback to summary
public final int getYears()
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
intValueback to summary
public final int intValue()

Implements abstract java.lang.Number.intValue.

Implements org.jooq.types.Interval.intValue.

Doc from java.lang.Number.intValue.

Returns the value of the specified number as an int.

Returns:int

the numeric value represented by this object after conversion to type int.

Annotations
@Override
longValueback to summary
public final long longValue()

Implements abstract java.lang.Number.longValue.

Implements org.jooq.types.Interval.longValue.

Doc from java.lang.Number.longValue.

Returns the value of the specified number as a long.

Returns:long

the numeric value represented by this object after conversion to type long.

Annotations
@Override
monthback to summary
public static YearToMonth month(String string)

Parse a standard SQL string representation of a INTERVAL MONTH.

Parameters
string:String

A string representation of the form [+|-][months]

Returns:YearToMonth

The parsed MONTH object, or null if the string could not be parsed.

negback to summary
public final YearToMonth neg()

Implements org.jooq.types.Interval.neg.

Doc from org.jooq.types.Interval.neg.

Negate the interval (change its sign)

Annotations
@Override
toDurationback to summary
public final Duration toDuration()

Implements org.jooq.types.Interval.toDuration.

Doc from org.jooq.types.Interval.toDuration.

Get a duration representation of this interval.

There is an obvious Duration representation for DayToSecond intervals. If the interval contains YearMonth information, then the corresponding duration will use:

  • 1 year = 365.25 days
  • 1 month = 30 days

This corresponds to PostgreSQL's EXTRACT(EPOCH FROM my_interval) behaviour.

Annotations
@Override
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
valueOfback to summary
public static YearToMonth valueOf(String string)

Parse a string representation of a INTERVAL YEAR TO MONTH.

Parameters
string:String

A string representation of the form [+|-][years]-[months]

Returns:YearToMonth

The parsed YEAR TO MONTH object, or null if the string could not be parsed.

yearback to summary
public static YearToMonth year(String string)

Parse a standard SQL string representation of a INTERVAL YEAR.

Parameters
string:String

A string representation of the form [+|-][years]

Returns:YearToMonth

The parsed YEAR object, or null if the string could not be parsed.

yearToMonthback to summary
public static YearToMonth yearToMonth(String string)

Parse a standard SQL string representation of a INTERVAL YEAR TO MONTH.

Parameters
string:String

A string representation of the form [+|-][years]-[months]

Returns:YearToMonth

The parsed YEAR TO MONTH object, or null if the string could not be parsed.