com.amazon.redshift.util

## Class RedshiftInterval

- java.lang.Object
- - com.amazon.redshift.util.RedshiftObject
  - - com.amazon.redshift.util.RedshiftInterval

All Implemented Interfaces:
  Serializable, Cloneable

    public class RedshiftInterval
    extends RedshiftObject
    implements Serializable, Cloneable

This implements a class that handles the Redshift interval type.

See Also:
  Serialized Form

### Field Summary

### Fields inherited from class com.amazon.redshift.util.RedshiftObject

`type, value`

### Constructor Summary

Constructors
Constructor and Description
`RedshiftInterval()` required by the driver.
`RedshiftInterval(int years, int months, int days, int hours, int minutes, double seconds)` Initializes all values of this interval to the specified values.
`RedshiftInterval(String value)` Initialize a interval with a given interval string representation.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `add(Calendar cal)` Rolls this interval on a given calendar.
`void` `add(Date date)` Rolls this interval on a given date.
`void` `add(RedshiftInterval interval)` Add this interval's value to the passed interval.
`Object` `clone()` This must be overidden to allow the object to be cloned.
`boolean` `equals(Object obj)` Returns whether an object is equal to this one or not.
`int` `getDays()` Returns the days represented by this interval.
`int` `getHours()` Returns the hours represented by this interval.
`int` `getMicroSeconds()`
`int` `getMinutes()` Returns the minutes represented by this interval.
`int` `getMonths()` Returns the months represented by this interval.
`double` `getSeconds()` Returns the seconds represented by this interval.
`String` `getValue()` Returns the stored interval information as a string.
`int` `getWholeSeconds()`
`int` `getYears()` Returns the years represented by this interval.
`int` `hashCode()` Returns a hashCode for this object.
`void` `scale(int factor)` Scale this interval by an integer factor.
`void` `setDays(int days)` Set the days of this interval to the specified value.
`void` `setHours(int hours)` Set the hours of this interval to the specified value.
`void` `setMinutes(int minutes)` Set the minutes of this interval to the specified value.
`void` `setMonths(int months)` Set the months of this interval to the specified value.
`void` `setSeconds(double seconds)` Set the seconds of this interval to the specified value.
`void` `setValue(int years, int months, int days, int hours, int minutes, double seconds)` Set all values of this interval to the specified values.
`void` `setValue(String value)` Sets a interval string represented value to this instance.
`void` `setYears(int years)` Set the years of this interval to the specified value.

### Methods inherited from class com.amazon.redshift.util.RedshiftObject

`getType, setType, toString`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### RedshiftInterval

    public RedshiftInterval()

required by the driver.

#### RedshiftInterval

    public RedshiftInterval(String value)
                     throws SQLException

Initialize a interval with a given interval string representation.

Parameters:
  `value` - String representated interval (e.g. '3 years 2 mons')
Throws:
  `SQLException` - Is thrown if the string representation has an unknown format
See Also:
  `setValue(String)`

#### RedshiftInterval

    public RedshiftInterval(int years,
                            int months,
                            int days,
                            int hours,
                            int minutes,
                            double seconds)

Initializes all values of this interval to the specified values.

Parameters:
  `years` - years
  `months` - months
  `days` - days
  `hours` - hours
  `minutes` - minutes
  `seconds` - seconds
See Also:
  `setValue(int, int, int, int, int, double)`

### Method Detail

#### setValue

    public void setValue(String value)
                  throws SQLException

Sets a interval string represented value to this instance. This method only recognize the format, that Postgres returns - not all input formats are supported (e.g. '1 yr 2 m 3 s').

Overrides:
  `setValue` in class `RedshiftObject`
Parameters:
  `value` - String representated interval (e.g. '3 years 2 mons')
Throws:
  `SQLException` - Is thrown if the string representation has an unknown format

#### setValue

    public void setValue(int years,
                         int months,
                         int days,
                         int hours,
                         int minutes,
                         double seconds)

Set all values of this interval to the specified values.

Parameters:
  `years` - years
  `months` - months
  `days` - days
  `hours` - hours
  `minutes` - minutes
  `seconds` - seconds

#### getValue

    public String getValue()

Returns the stored interval information as a string.

Overrides:
  `getValue` in class `RedshiftObject`
Returns:
  String represented interval

#### getYears

    public int getYears()

Returns the years represented by this interval.

Returns:
  years represented by this interval

#### setYears

    public void setYears(int years)

Set the years of this interval to the specified value.

Parameters:
  `years` - years to set

#### getMonths

    public int getMonths()

Returns the months represented by this interval.

Returns:
  months represented by this interval

#### setMonths

    public void setMonths(int months)

Set the months of this interval to the specified value.

Parameters:
  `months` - months to set

#### getDays

    public int getDays()

Returns the days represented by this interval.

Returns:
  days represented by this interval

#### setDays

    public void setDays(int days)

Set the days of this interval to the specified value.

Parameters:
  `days` - days to set

#### getHours

    public int getHours()

Returns the hours represented by this interval.

Returns:
  hours represented by this interval

#### setHours

    public void setHours(int hours)

Set the hours of this interval to the specified value.

Parameters:
  `hours` - hours to set

#### getMinutes

    public int getMinutes()

Returns the minutes represented by this interval.

Returns:
  minutes represented by this interval

#### setMinutes

    public void setMinutes(int minutes)

Set the minutes of this interval to the specified value.

Parameters:
  `minutes` - minutes to set

#### getSeconds

    public double getSeconds()

Returns the seconds represented by this interval.

Returns:
  seconds represented by this interval

#### getWholeSeconds

    public int getWholeSeconds()

#### getMicroSeconds

    public int getMicroSeconds()

#### setSeconds

    public void setSeconds(double seconds)

Set the seconds of this interval to the specified value.

Parameters:
  `seconds` - seconds to set

#### add

    public void add(Calendar cal)

Rolls this interval on a given calendar.

Parameters:
  `cal` - Calendar instance to add to

#### add

    public void add(Date date)

Rolls this interval on a given date.

Parameters:
  `date` - Date instance to add to

#### add

    public void add(RedshiftInterval interval)

Add this interval's value to the passed interval. This is backwards to what I would expect, but this makes it match the other existing add methods.

Parameters:
  `interval` - intval to add

#### scale

    public void scale(int factor)

Scale this interval by an integer factor. The server can scale by arbitrary factors, but that would require adjusting the call signatures for all the existing methods like getDays() or providing our own justification of fractional intervals. Neither of these seem like a good idea without a strong use case.

Parameters:
  `factor` - scale factor

#### equals

    public boolean equals(Object obj)

Returns whether an object is equal to this one or not.

Overrides:
  `equals` in class `RedshiftObject`
Parameters:
  `obj` - Object to compare with
Returns:
  true if the two intervals are identical

#### hashCode

    public int hashCode()

Returns a hashCode for this object.

Overrides:
  `hashCode` in class `RedshiftObject`
Returns:
  hashCode

#### clone

    public Object clone()
                 throws CloneNotSupportedException

Description copied from class: `RedshiftObject`
This must be overidden to allow the object to be cloned.

Overrides:
  `clone` in class `RedshiftObject`
Throws:
  `CloneNotSupportedException`