Top Description Fields Constructors Methods
org.h2.api

public final Class Interval

extends Object
Class Inheritance
Static Imports
org.h2.util.DateTimeUtils.NANOS_PER_MINUTE, .DateTimeUtils.NANOS_PER_SECOND

INTERVAL representation for result sets.

Field Summary

Modifier and TypeField and Description
private final long
leading

Non-negative long with value of leading field.

private final boolean
negative

false for zero or positive intervals, true for negative intervals.

private final IntervalQualifier
private final long
remaining

Non-negative long with combined value of all remaining field, or 0 for single-field intervals, with exception for INTERVAL SECOND that uses this field to store fractional part of seconds measured in nanoseconds.

Constructor Summary

AccessConstructor and Description
public
Interval(IntervalQualifier
qualifier
qualifier
,
boolean
whether interval is negative
negative
,
long
value of leading field
leading
,
long
combined value of all remaining fields
remaining
)

Creates a new interval.

Method Summary

Modifier and TypeMethod and Description
public 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 long

Returns:

days, or 0
getDays
()

Returns days value, if any.

public long

Returns:

hours, or 0
getHours
()

Returns hours value, if any.

public long

Returns:

value of leading field
getLeading
()

Returns value of leading field of this interval.

public long

Returns:

minutes, or 0
getMinutes
()

Returns minutes value, if any.

public long

Returns:

months, or 0
getMonths
()

Returns months value, if any.

public long

Returns:

nanoseconds, or 0
getNanosOfSecond
()

Returns value of fractional part of seconds (in nanoseconds), if any.

public IntervalQualifier

Returns:

qualifier
getQualifier
()

Returns qualifier of this interval.

public long

Returns:

combined value of remaining fields
getRemaining
()

Returns combined value of remaining fields of this interval.

public long

Returns:

seconds, or 0
getSeconds
()

Returns value of integer part of seconds, if any.

public long

Returns:

nanoseconds (including seconds), or 0
getSecondsAndNanos
()

Returns seconds value measured in nanoseconds, if any.

public long

Returns:

years, or 0
getYears
()

Returns years value, if any.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

where the interval is negative
isNegative
()

Returns where the interval is negative.

public static Interval

Returns:

INTERVAL DAY
ofDays
(long
days, |days|<1018
days
)

Creates a new INTERVAL DAY.

public static Interval

Returns:

INTERVAL DAY TO HOUR
ofDaysHours
(long
days, |days|<1018
days
,
int
hours, |hours|<24
hours
)

Creates a new INTERVAL DAY TO HOUR.

public static Interval

Returns:

INTERVAL DAY TO MINUTE
ofDaysHoursMinutes
(long
days, |days|<1018
days
,
int
hours, |hours|<24
hours
,
int
minutes, |minutes|<60
minutes
)

Creates a new INTERVAL DAY TO MINUTE.

public static Interval

Returns:

INTERVAL DAY TO SECOND
ofDaysHoursMinutesNanos
(long
days, |days|<1018
days
,
int
hours, |hours|<24
hours
,
int
minutes, |minutes|<60
minutes
,
long
nanoseconds, |nanos|<60,000,000,000
nanos
)

Creates a new INTERVAL DAY TO SECOND.

public static Interval

Returns:

INTERVAL DAY TO SECOND
ofDaysHoursMinutesSeconds
(long
days, |days|<1018
days
,
int
hours, |hours|<24
hours
,
int
minutes, |minutes|<60
minutes
,
int
seconds, |seconds|<60
seconds
)

Creates a new INTERVAL DAY TO SECOND.

public static Interval

Returns:

INTERVAL HOUR
ofHours
(long
hours, |hours|<1018
hours
)

Creates a new INTERVAL HOUR.

public static Interval

Returns:

INTERVAL HOUR TO MINUTE
ofHoursMinutes
(long
hours, |hours|<1018
hours
,
int
minutes, |minutes|<60
minutes
)

Creates a new INTERVAL HOUR TO MINUTE.

public static Interval

Returns:

INTERVAL HOUR TO SECOND
ofHoursMinutesNanos
(long
hours, |hours|<1018
hours
,
int
minutes, |minutes|<60
minutes
,
long
nanoseconds, |seconds|<60,000,000,000
nanos
)

Creates a new INTERVAL HOUR TO SECOND.

public static Interval

Returns:

INTERVAL HOUR TO SECOND
ofHoursMinutesSeconds
(long
hours, |hours|<1018
hours
,
int
minutes, |minutes|<60
minutes
,
int
seconds, |seconds|<60
seconds
)

Creates a new INTERVAL HOUR TO SECOND.

public static Interval

Returns:

interval
ofMinutes
(long
minutes, |minutes|<1018
minutes
)

Creates a new INTERVAL MINUTE.

public static Interval

Returns:

INTERVAL MINUTE TO SECOND
ofMinutesNanos
(long
minutes, |minutes|<1018
minutes
,
long
nanoseconds, |nanos|<60,000,000,000
nanos
)

Creates a new INTERVAL MINUTE TO SECOND.

public static Interval

Returns:

INTERVAL MINUTE TO SECOND
ofMinutesSeconds
(long
minutes, |minutes|<1018
minutes
,
int
seconds, |seconds|<60
seconds
)

Creates a new INTERVAL MINUTE TO SECOND.

public static Interval

Returns:

INTERVAL MONTH
ofMonths
(long
months, |months|<1018
months
)

Creates a new INTERVAL MONTH.

public static Interval

Returns:

INTERVAL SECOND
ofNanos
(long
nanoseconds (including seconds)
nanos
)

Creates a new INTERVAL SECOND.

public static Interval

Returns:

INTERVAL SECOND
ofSeconds
(long
seconds, |seconds|<1018
seconds
)

Creates a new INTERVAL SECOND.

public static Interval

Returns:

INTERVAL SECOND
ofSeconds
(long
seconds, |seconds|<1018
seconds
,
int
nanoseconds, |nanos|<1,000,000,000
nanos
)

Creates a new INTERVAL SECOND.

public static Interval

Returns:

INTERVAL YEAR
ofYears
(long
years, |years|<1018
years
)

Creates a new INTERVAL YEAR.

public static Interval

Returns:

INTERVAL YEAR TO MONTH
ofYearsMonths
(long
years, |years|<1018
years
,
int
months, |months|<12
months
)

Creates a new INTERVAL YEAR TO MONTH.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

leadingback to summary
private final long leading

Non-negative long with value of leading field. For INTERVAL SECOND contains only integer part of seconds.

negativeback to summary
private final boolean negative

false for zero or positive intervals, true for negative intervals.

qualifierback to summary
private final IntervalQualifier qualifier
remainingback to summary
private final long remaining

Non-negative long with combined value of all remaining field, or 0 for single-field intervals, with exception for INTERVAL SECOND that uses this field to store fractional part of seconds measured in nanoseconds.

Constructor Detail

Intervalback to summary
public Interval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)

Creates a new interval. Do not use this constructor, use static methods instead.

Parameters
qualifier:IntervalQualifier

qualifier

negative:boolean

whether interval is negative

leading:long

value of leading field

remaining:long

combined value of all remaining fields

Method Detail

equalsback to summary
public 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
getDaysback to summary
public long getDays()

Returns days value, if any.

Returns:long

days, or 0

getHoursback to summary
public long getHours()

Returns hours value, if any.

Returns:long

hours, or 0

getLeadingback to summary
public long getLeading()

Returns value of leading field of this interval. For SECOND intervals returns integer part of seconds.

Returns:long

value of leading field

getMinutesback to summary
public long getMinutes()

Returns minutes value, if any.

Returns:long

minutes, or 0

getMonthsback to summary
public long getMonths()

Returns months value, if any.

Returns:long

months, or 0

getNanosOfSecondback to summary
public long getNanosOfSecond()

Returns value of fractional part of seconds (in nanoseconds), if any.

Returns:long

nanoseconds, or 0

getQualifierback to summary
public IntervalQualifier getQualifier()

Returns qualifier of this interval.

Returns:IntervalQualifier

qualifier

getRemainingback to summary
public long getRemaining()

Returns combined value of remaining fields of this interval. For SECOND intervals returns nanoseconds.

Returns:long

combined value of remaining fields

getSecondsback to summary
public long getSeconds()

Returns value of integer part of seconds, if any.

Returns:long

seconds, or 0

getSecondsAndNanosback to summary
public long getSecondsAndNanos()

Returns seconds value measured in nanoseconds, if any.

This method returns a long value that cannot fit all possible values of INTERVAL SECOND. For a very large intervals of this type use getSeconds() and getNanosOfSecond() instead. This method can be safely used for intervals of other day-time types.

Returns:long

nanoseconds (including seconds), or 0

getYearsback to summary
public long getYears()

Returns years value, if any.

Returns:long

years, or 0

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this 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
isNegativeback to summary
public boolean isNegative()

Returns where the interval is negative.

Returns:boolean

where the interval is negative

ofDaysback to summary
public static Interval ofDays(long days)

Creates a new INTERVAL DAY.

Parameters
days:long

days, |days|<1018

Returns:Interval

INTERVAL DAY

ofDaysHoursback to summary
public static Interval ofDaysHours(long days, int hours)

Creates a new INTERVAL DAY TO HOUR.

If both arguments are not equal to zero they should have the same sign.

Parameters
days:long

days, |days|<1018

hours:int

hours, |hours|<24

Returns:Interval

INTERVAL DAY TO HOUR

ofDaysHoursMinutesback to summary
public static Interval ofDaysHoursMinutes(long days, int hours, int minutes)

Creates a new INTERVAL DAY TO MINUTE.

Non-zero arguments should have the same sign.

Parameters
days:long

days, |days|<1018

hours:int

hours, |hours|<24

minutes:int

minutes, |minutes|<60

Returns:Interval

INTERVAL DAY TO MINUTE

ofDaysHoursMinutesNanosback to summary
public static Interval ofDaysHoursMinutesNanos(long days, int hours, int minutes, long nanos)

Creates a new INTERVAL DAY TO SECOND.

Non-zero arguments should have the same sign.

Parameters
days:long

days, |days|<1018

hours:int

hours, |hours|<24

minutes:int

minutes, |minutes|<60

nanos:long

nanoseconds, |nanos|<60,000,000,000

Returns:Interval

INTERVAL DAY TO SECOND

ofDaysHoursMinutesSecondsback to summary
public static Interval ofDaysHoursMinutesSeconds(long days, int hours, int minutes, int seconds)

Creates a new INTERVAL DAY TO SECOND.

Non-zero arguments should have the same sign.

Parameters
days:long

days, |days|<1018

hours:int

hours, |hours|<24

minutes:int

minutes, |minutes|<60

seconds:int

seconds, |seconds|<60

Returns:Interval

INTERVAL DAY TO SECOND

ofHoursback to summary
public static Interval ofHours(long hours)

Creates a new INTERVAL HOUR.

Parameters
hours:long

hours, |hours|<1018

Returns:Interval

INTERVAL HOUR

ofHoursMinutesback to summary
public static Interval ofHoursMinutes(long hours, int minutes)

Creates a new INTERVAL HOUR TO MINUTE.

If both arguments are not equal to zero they should have the same sign.

Parameters
hours:long

hours, |hours|<1018

minutes:int

minutes, |minutes|<60

Returns:Interval

INTERVAL HOUR TO MINUTE

ofHoursMinutesNanosback to summary
public static Interval ofHoursMinutesNanos(long hours, int minutes, long nanos)

Creates a new INTERVAL HOUR TO SECOND.

Non-zero arguments should have the same sign.

Parameters
hours:long

hours, |hours|<1018

minutes:int

minutes, |minutes|<60

nanos:long

nanoseconds, |seconds|<60,000,000,000

Returns:Interval

INTERVAL HOUR TO SECOND

ofHoursMinutesSecondsback to summary
public static Interval ofHoursMinutesSeconds(long hours, int minutes, int seconds)

Creates a new INTERVAL HOUR TO SECOND.

Non-zero arguments should have the same sign.

Parameters
hours:long

hours, |hours|<1018

minutes:int

minutes, |minutes|<60

seconds:int

seconds, |seconds|<60

Returns:Interval

INTERVAL HOUR TO SECOND

ofMinutesback to summary
public static Interval ofMinutes(long minutes)

Creates a new INTERVAL MINUTE.

Parameters
minutes:long

minutes, |minutes|<1018

Returns:Interval

interval

ofMinutesNanosback to summary
public static Interval ofMinutesNanos(long minutes, long nanos)

Creates a new INTERVAL MINUTE TO SECOND.

If both arguments are not equal to zero they should have the same sign.

Parameters
minutes:long

minutes, |minutes|<1018

nanos:long

nanoseconds, |nanos|<60,000,000,000

Returns:Interval

INTERVAL MINUTE TO SECOND

ofMinutesSecondsback to summary
public static Interval ofMinutesSeconds(long minutes, int seconds)

Creates a new INTERVAL MINUTE TO SECOND.

If both arguments are not equal to zero they should have the same sign.

Parameters
minutes:long

minutes, |minutes|<1018

seconds:int

seconds, |seconds|<60

Returns:Interval

INTERVAL MINUTE TO SECOND

ofMonthsback to summary
public static Interval ofMonths(long months)

Creates a new INTERVAL MONTH.

Parameters
months:long

months, |months|<1018

Returns:Interval

INTERVAL MONTH

ofNanosback to summary
public static Interval ofNanos(long nanos)

Creates a new INTERVAL SECOND.

Parameters
nanos:long

nanoseconds (including seconds)

Returns:Interval

INTERVAL SECOND

ofSecondsback to summary
public static Interval ofSeconds(long seconds)

Creates a new INTERVAL SECOND.

Parameters
seconds:long

seconds, |seconds|<1018

Returns:Interval

INTERVAL SECOND

ofSecondsback to summary
public static Interval ofSeconds(long seconds, int nanos)

Creates a new INTERVAL SECOND.

If both arguments are not equal to zero they should have the same sign.

Parameters
seconds:long

seconds, |seconds|<1018

nanos:int

nanoseconds, |nanos|<1,000,000,000

Returns:Interval

INTERVAL SECOND

ofYearsback to summary
public static Interval ofYears(long years)

Creates a new INTERVAL YEAR.

Parameters
years:long

years, |years|<1018

Returns:Interval

INTERVAL YEAR

ofYearsMonthsback to summary
public static Interval ofYearsMonths(long years, int months)

Creates a new INTERVAL YEAR TO MONTH.

If both arguments are not equal to zero they should have the same sign.

Parameters
years:long

years, |years|<1018

months:int

months, |months|<12

Returns:Interval

INTERVAL YEAR TO MONTH

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override