Class Interval
- java.lang.Object
-
- org.h2.api.Interval
-
public final class Interval extends java.lang.Object
INTERVAL representation for result sets.
-
-
Field Summary
Fields Modifier and Type Field Description private long
leading
Non-negative long with value of leading field.private boolean
negative
false
for zero or positive intervals,true
for negative intervals.private IntervalQualifier
qualifier
private 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
Constructors Constructor Description Interval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Creates a new interval.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
long
getDays()
Returns days value, if any.long
getHours()
Returns hours value, if any.long
getLeading()
Returns value of leading field of this interval.long
getMinutes()
Returns minutes value, if any.long
getMonths()
Returns months value, if any.long
getNanosOfSecond()
Returns value of fractional part of seconds (in nanoseconds), if any.IntervalQualifier
getQualifier()
Returns qualifier of this interval.long
getRemaining()
Returns combined value of remaining fields of this interval.long
getSeconds()
Returns value of integer part of seconds, if any.long
getSecondsAndNanos()
Returns seconds value measured in nanoseconds, if any.long
getYears()
Returns years value, if any.int
hashCode()
boolean
isNegative()
Returns where the interval is negative.static Interval
ofDays(long days)
Creates a new INTERVAL DAY.static Interval
ofDaysHours(long days, int hours)
Creates a new INTERVAL DAY TO HOUR.static Interval
ofDaysHoursMinutes(long days, int hours, int minutes)
Creates a new INTERVAL DAY TO MINUTE.static Interval
ofDaysHoursMinutesNanos(long days, int hours, int minutes, long nanos)
Creates a new INTERVAL DAY TO SECOND.static Interval
ofDaysHoursMinutesSeconds(long days, int hours, int minutes, int seconds)
Creates a new INTERVAL DAY TO SECOND.static Interval
ofHours(long hours)
Creates a new INTERVAL HOUR.static Interval
ofHoursMinutes(long hours, int minutes)
Creates a new INTERVAL HOUR TO MINUTE.static Interval
ofHoursMinutesNanos(long hours, int minutes, long nanos)
Creates a new INTERVAL HOUR TO SECOND.static Interval
ofHoursMinutesSeconds(long hours, int minutes, int seconds)
Creates a new INTERVAL HOUR TO SECOND.static Interval
ofMinutes(long minutes)
Creates a new INTERVAL MINUTE.static Interval
ofMinutesNanos(long minutes, long nanos)
Creates a new INTERVAL MINUTE TO SECOND.static Interval
ofMinutesSeconds(long minutes, int seconds)
Creates a new INTERVAL MINUTE TO SECOND.static Interval
ofMonths(long months)
Creates a new INTERVAL MONTH.static Interval
ofNanos(long nanos)
Creates a new INTERVAL SECOND.static Interval
ofSeconds(long seconds)
Creates a new INTERVAL SECOND.static Interval
ofSeconds(long seconds, int nanos)
Creates a new INTERVAL SECOND.static Interval
ofYears(long years)
Creates a new INTERVAL YEAR.static Interval
ofYearsMonths(long years, int months)
Creates a new INTERVAL YEAR TO MONTH.java.lang.String
toString()
-
-
-
Field Detail
-
qualifier
private final IntervalQualifier qualifier
-
negative
private final boolean negative
false
for zero or positive intervals,true
for negative intervals.
-
leading
private final long leading
Non-negative long with value of leading field. For INTERVAL SECOND contains only integer part of seconds.
-
remaining
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
-
Interval
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
- qualifiernegative
- whether interval is negativeleading
- value of leading fieldremaining
- combined value of all remaining fields
-
-
Method Detail
-
ofYears
public static Interval ofYears(long years)
Creates a new INTERVAL YEAR.- Parameters:
years
- years, |years|<1018- Returns:
- INTERVAL YEAR
-
ofMonths
public static Interval ofMonths(long months)
Creates a new INTERVAL MONTH.- Parameters:
months
- months, |months|<1018- Returns:
- INTERVAL MONTH
-
ofDays
public static Interval ofDays(long days)
Creates a new INTERVAL DAY.- Parameters:
days
- days, |days|<1018- Returns:
- INTERVAL DAY
-
ofHours
public static Interval ofHours(long hours)
Creates a new INTERVAL HOUR.- Parameters:
hours
- hours, |hours|<1018- Returns:
- INTERVAL HOUR
-
ofMinutes
public static Interval ofMinutes(long minutes)
Creates a new INTERVAL MINUTE.- Parameters:
minutes
- minutes, |minutes|<1018- Returns:
- interval
-
ofSeconds
public static Interval ofSeconds(long seconds)
Creates a new INTERVAL SECOND.- Parameters:
seconds
- seconds, |seconds|<1018- Returns:
- INTERVAL SECOND
-
ofSeconds
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
- seconds, |seconds|<1018nanos
- nanoseconds, |nanos|<1,000,000,000- Returns:
- INTERVAL SECOND
-
ofNanos
public static Interval ofNanos(long nanos)
Creates a new INTERVAL SECOND.- Parameters:
nanos
- nanoseconds (including seconds)- Returns:
- INTERVAL SECOND
-
ofYearsMonths
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
- years, |years|<1018months
- months, |months|<12- Returns:
- INTERVAL YEAR TO MONTH
-
ofDaysHours
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
- days, |days|<1018hours
- hours, |hours|<24- Returns:
- INTERVAL DAY TO HOUR
-
ofDaysHoursMinutes
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
- days, |days|<1018hours
- hours, |hours|<24minutes
- minutes, |minutes|<60- Returns:
- INTERVAL DAY TO MINUTE
-
ofDaysHoursMinutesSeconds
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
- days, |days|<1018hours
- hours, |hours|<24minutes
- minutes, |minutes|<60seconds
- seconds, |seconds|<60- Returns:
- INTERVAL DAY TO SECOND
-
ofDaysHoursMinutesNanos
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
- days, |days|<1018hours
- hours, |hours|<24minutes
- minutes, |minutes|<60nanos
- nanoseconds, |nanos|<60,000,000,000- Returns:
- INTERVAL DAY TO SECOND
-
ofHoursMinutes
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
- hours, |hours|<1018minutes
- minutes, |minutes|<60- Returns:
- INTERVAL HOUR TO MINUTE
-
ofHoursMinutesSeconds
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
- hours, |hours|<1018minutes
- minutes, |minutes|<60seconds
- seconds, |seconds|<60- Returns:
- INTERVAL HOUR TO SECOND
-
ofHoursMinutesNanos
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
- hours, |hours|<1018minutes
- minutes, |minutes|<60nanos
- nanoseconds, |seconds|<60,000,000,000- Returns:
- INTERVAL HOUR TO SECOND
-
ofMinutesSeconds
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
- minutes, |minutes|<1018seconds
- seconds, |seconds|<60- Returns:
- INTERVAL MINUTE TO SECOND
-
ofMinutesNanos
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
- minutes, |minutes|<1018nanos
- nanoseconds, |nanos|<60,000,000,000- Returns:
- INTERVAL MINUTE TO SECOND
-
getQualifier
public IntervalQualifier getQualifier()
Returns qualifier of this interval.- Returns:
- qualifier
-
isNegative
public boolean isNegative()
Returns where the interval is negative.- Returns:
- where the interval is negative
-
getLeading
public long getLeading()
Returns value of leading field of this interval. ForSECOND
intervals returns integer part of seconds.- Returns:
- value of leading field
-
getRemaining
public long getRemaining()
Returns combined value of remaining fields of this interval. ForSECOND
intervals returns nanoseconds.- Returns:
- combined value of remaining fields
-
getYears
public long getYears()
Returns years value, if any.- Returns:
- years, or 0
-
getMonths
public long getMonths()
Returns months value, if any.- Returns:
- months, or 0
-
getDays
public long getDays()
Returns days value, if any.- Returns:
- days, or 0
-
getHours
public long getHours()
Returns hours value, if any.- Returns:
- hours, or 0
-
getMinutes
public long getMinutes()
Returns minutes value, if any.- Returns:
- minutes, or 0
-
getSeconds
public long getSeconds()
Returns value of integer part of seconds, if any.- Returns:
- seconds, or 0
-
getNanosOfSecond
public long getNanosOfSecond()
Returns value of fractional part of seconds (in nanoseconds), if any.- Returns:
- nanoseconds, or 0
-
getSecondsAndNanos
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()
andgetNanosOfSecond()
instead. This method can be safely used for intervals of other day-time types.- Returns:
- nanoseconds (including seconds), or 0
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-