ALBPM Process API (PAPI)

fuego.lang
Class Interval

java.lang.Object
  extended byfuego.lang.Interval
All Implemented Interfaces:
Comparable, Serializable

public final class Interval
extends Object
implements Serializable, Comparable

Space of time between any two points or events. The "Interval" class represents the time between two events in the time, as for example, the quantity of days in which a sale order will due (difference between 'now' and the order due date). The interval may be represented by a number of years, months, days, hours, minutes, seconds. It will depend on the possibility of expressing the interval in those units. As the interval is a quantity of time and it does not include a date sometimes it is not possible to express the years, months, days, etc. It stores time offsets, including time-of-day offsets. It makes no timezone correction, since it does not include a date. When an interval is created from the difference between two dates, something like:

d1, d2 as Time d1 = Time(1961, 1, 1) d2 = 'now' interval = d2 - d1
the interval is calculated and stored from the day unit. In this example the interval value is: 16146d37h19m18406s having 'now' equal to: 2005-06-18 13:19:18.406000-03 When an interval is created by the user, specifing the units, only the "Months" and "Seconds" are reexpress in "Years/Months" and "Hours/Minutes/Seconds" respectevely. "Days" are never reexpressed into months and years, as it is impossible to know months of what quantity of days use to make the calculation, 30 or 31?. The same happens when thinking to reexpress days into years, how many leap years. But, months can be reexpressed into years, as there are always "12 months in a year". "Seconds" are reexpressed into hours and minutes, and "minutes" into hours. "Hours" are never reexpressed into days. The quantity of days is never reexpress." - 200M25d36h10m789012s is stored as: 16Y8M25d255h20m12s - 300d18h is stored as: 300d18h, days are not reexpressed. - 600m18s is stored as: 10h18s, as minutes are reexpressed into hours. Refer to the "valueOf" method documentation to learn how a interval can be created, from a Time, a String, two Times, and more.

See Also:
Serialized Form

Nested Class Summary
static class Interval.Holder
           
 
Field Summary
static Interval ONE_DAY
          A One day Interval
static Interval ONE_HOUR
          A One hour Interval
static Interval ONE_MINUTE
          A One minute Interval
static Interval ONE_MONTH
          A One month Interval
static Interval ONE_SECOND
          A One second Interval
static Interval ONE_WEEK
          A One week Interval
static Interval ZERO
          Zero Interval
 
Constructor Summary
Interval()
           
 
Method Summary
 Interval abs()
          Absolute value of this object.
 Interval add(Interval t)
          Adds an Interval.
static Interval add(Interval op1, Interval op2)
          Adds two Intervals.
 Time add(Time t)
          Adds a interval to the Time specified as parameter.
 Interval addDays(int i)
          Adds days to an interval.
 Interval addHours(long i)
          Adds hours to an interval.
 Interval addMicroSeconds(long i)
          Adds micro-seconds to this interval
 Interval addMinutes(long i)
          Adds minutes to this interval.
 Interval addMonths(int i)
          Adds months to this interval.
 Interval addSeconds(long i)
          Adds seconds to this interval
 Interval addYears(int i)
          Adds years to this interval.
static int compare(Interval a, Interval b)
          Compares two Intervals.
 int compareTo(Object b)
          Compares this object with another Interval.
static Interval daysOnly(Interval i, int day)
          Only Sets the day value to the interval i
static boolean equals(Interval a, Interval b)
          Compares Intervals
 boolean equals(Object b)
          Compares this object with an object received as a parameter
 String format()
          Formats the interval.
 String format(IntervalUnit from, IntervalUnit to)
          Formats the interval showing the interval units included in the from/to range.
static Interval fromMinutes(int minutes)
          Constructs an interval from a number of minutes
static Interval fromSeconds(int seconds)
          Constructs an interval from a number of seconds
 long get(IntervalUnit field)
           
 double getAproximateTotal(IntervalUnit field)
           
 int getDays()
          The "days" value for this interval.
 int getDaysOnly()
          The "days" value for this interval.
static String getFieldName(IntervalUnit field)
           
 int getHours()
          The "hours" value for this interval.
 int getHoursOnly()
          The "hours" value for this interval.
 long getMicroSeconds()
          Hour portion of the interval reexpressed into microseconds.
 int getMicroSecondsOnly()
          The "microseconds" part of the interval.
 long getMilliSeconds()
          Hour portion of the interval reexpressed into milliseconds.
 int getMilliSecondsOnly()
          The "milliseconds" part of the interval.
 int getMinutes()
          Hour portion of the interval reexpressed into minutes.
 int getMinutesOnly()
          The "minutes" value of the interval.
 int getMonths()
          The "years/months" value for this interval expressed in months.
 int getMonthsOnly()
          The "months" value for this interval.
 long getOnly(IntervalUnit field)
           
 int getSeconds()
          Hour portion of the interval reexpressed into seconds.
 int getSecondsOnly()
          The "seconds" value for this interval.
 long getTotalMicroseconds()
           
 int getYears()
          The "years" value for this interval.
 int getYearsOnly()
          The "years" value for this interval.
 int hashCode()
          Returns hash code
static Interval hoursOnly(Interval i, int hour)
          Sets only the hours value to an Interval object
 int intValue()
          Number of seconds that the interval represents
static void main(String[] args)
           
 Interval max(Interval b)
          Compares this object with the argument and returns the higher.
static Interval microSecondsOnly(Interval i, long microSecond)
          Sets only the microsecond value to an Interval object
static Interval milliSecondsOnly(Interval i, long milliSecond)
          Sets only the milliseconds value to an Interval object
 Interval min(Interval b)
          Compares this object with the argument and returns the lower.
static Interval minutesOnly(Interval i, int minute)
          Sets only the minute value to an Interval object
static Interval monthsOnly(Interval i, int month)
          Sets only the month value to an Interval object
 Interval negate()
          Returns a Interval whose value is (-this).
static Interval negate(Interval op)
          Returns the value of the interval with the sign changed.
static Interval parseInterval(String t)
          Parses an interval.
 String retryIn()
          Deprecated. Maintained for backwards compatibility
static Interval secondsOnly(Interval i, int second)
           
 Interval set(IntervalUnit field, long value)
           
 Interval setOnly(IntervalUnit field, long value)
           
 void sleep()
          Causes the current execution to sleep for the milliseconds value of this object.
 Interval sub(Interval t)
          Substracts an Interval.
static Interval sub(Interval op1, Interval op2)
          Substracts two Intervals
 Time subFrom(Time t)
          Substract from a Time.
 String toString()
          Returns a string representation of an interval value
 String toXMLString()
          Returns an XML string representation of an interval value
static Interval valueOf(BigDecimal ms)
          Constructs an interval from a number of microseconds.
static Interval valueOf(double ms)
          Constructs an interval from a number of microseconds (from a double)
static Interval valueOf(int months, int days, long microSeconds)
          Constructs an interval from a number of months, days and microseconds
static Interval valueOf(long microSeconds)
          Constructs an interval from a number of microseconds (from a long)
static Interval valueOf(Object obj)
          Constructs an interval from another Object (eg: Interval, Time, Number or String).
static Interval valueOf(String t)
          Parses a string with one of the following formats: -? {tmspec}+ -? {num}:{num}(:{num}(.{num})?)? Where {tmspec} is one of: {num}{ws}*M --> months {num}{ws}*d --> days {num}{ws}*h --> hours {num}{ws}*m --> minutes {num}{ws}*s --> seconds and {num} is a number with an optional decimal part For example: 1M10d2s --> 1 month, 10 days, 2 seconds 10 d 2.5 m --> 10 days, 2 minutes, 30 seconds 365.25d 10h 3s 3.5s --> 365 days, 16 hours, 6 seconds, 500000 microseconds 10 d 2.5 --> IntervalFormatException
static Interval valueOf(Time i)
          Constructs an interval from a Time object.
static Interval valueOf(Time op1, Time op2)
          Returns the subtraction between two Times as an Interval object
static Interval yearsOnly(Interval i, int year)
          Sets only the year value to an Interval object
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Interval ZERO
Zero Interval


ONE_SECOND

public static final Interval ONE_SECOND
A One second Interval


ONE_MINUTE

public static final Interval ONE_MINUTE
A One minute Interval


ONE_HOUR

public static final Interval ONE_HOUR
A One hour Interval


ONE_DAY

public static final Interval ONE_DAY
A One day Interval


ONE_WEEK

public static final Interval ONE_WEEK
A One week Interval


ONE_MONTH

public static final Interval ONE_MONTH
A One month Interval

Constructor Detail

Interval

public Interval()
Method Detail

compare

public static int compare(Interval a,
                          Interval b)
Compares two Intervals. The comparison returns: - 0 if "a" is equal to "b"; - a value less than 0 if "b" is previous cronologically to "a"; - a value greater than 0 otherwise. If one of the parameters is null, it is considered less than the other.

Parameters:
a - Interval first Interval to be compared.
b - Interval second Interval to be compared.
Returns:
- 0 if "a" is equal to "b"; - a value less than 0 if "b" is previous cronologically to "a"; - a value greater than 0 otherwise. If one of the parameters is null, this parameter is considered less than the another.

daysOnly

public static Interval daysOnly(Interval i,
                                int day)
Only Sets the day value to the interval i

Parameters:
i - Interval The interval to be set
day - int Value of day

equals

public static boolean equals(Interval a,
                             Interval b)
Compares Intervals

Parameters:
a - an object to compare.
b - an object to compare.
Returns:
If any object are not an instance of an Interval type object or are equal to null, this method returns false, otherwise it returns the result of the comparison.

add

public static Interval add(Interval op1,
                           Interval op2)
Adds two Intervals.

Parameters:
op1 - The first interval
op2 - The second interval
Returns:
The sum of the two intervals passed as parameters: op1 + op2

hoursOnly

public static Interval hoursOnly(Interval i,
                                 int hour)
Sets only the hours value to an Interval object

Parameters:
i - Interval The Interval object
hour - int Hour value to be assigned.

microSecondsOnly

public static Interval microSecondsOnly(Interval i,
                                        long microSecond)
Sets only the microsecond value to an Interval object

Parameters:
i - Interval The Interval object
microSecond - long Microsecond value to be assigned.

milliSecondsOnly

public static Interval milliSecondsOnly(Interval i,
                                        long milliSecond)
Sets only the milliseconds value to an Interval object

Parameters:
i - Interval The Interval object
milliSecond - long Milliseconds value to be assigned.

minutesOnly

public static Interval minutesOnly(Interval i,
                                   int minute)
Sets only the minute value to an Interval object

Parameters:
i - Interval The Interval object
minute - int Minute value to be assigned.

monthsOnly

public static Interval monthsOnly(Interval i,
                                  int month)
Sets only the month value to an Interval object

Parameters:
i - Interval The Interval object
month - int Month value to be assigned.

sub

public static Interval sub(Interval op1,
                           Interval op2)
Substracts two Intervals

Parameters:
op1 - The first operand
op2 - The second operand
Returns:
op1 - op2

secondsOnly

public static Interval secondsOnly(Interval i,
                                   int second)

parseInterval

public static Interval parseInterval(String t)
                              throws IntervalFormatException
Parses an interval.

Throws:
fuego.lang.IntervalFormatException
IntervalFormatException

valueOf

public static Interval valueOf(Time i)
Constructs an interval from a Time object.

Parameters:
i - Time The object .

valueOf

public static Interval valueOf(Object obj)
Constructs an interval from another Object (eg: Interval, Time, Number or String).

Parameters:
obj - The object.

valueOf

public static Interval valueOf(int months,
                               int days,
                               long microSeconds)
Constructs an interval from a number of months, days and microseconds

Parameters:
months - The number of months, can be negative.
days - The number of days, can be negative.
microSeconds - The number of microseconds, can be negative.

valueOf

public static Interval valueOf(String t)
                        throws IntervalFormatException
Parses a string with one of the following formats: -? {tmspec}+ -? {num}:{num}(:{num}(.{num})?)? Where {tmspec} is one of: {num}{ws}*M --> months {num}{ws}*d --> days {num}{ws}*h --> hours {num}{ws}*m --> minutes {num}{ws}*s --> seconds and {num} is a number with an optional decimal part For example: 1M10d2s --> 1 month, 10 days, 2 seconds 10 d 2.5 m --> 10 days, 2 minutes, 30 seconds 365.25d 10h 3s 3.5s --> 365 days, 16 hours, 6 seconds, 500000 microseconds 10 d 2.5 --> IntervalFormatException

Parameters:
t - The string to parse
Returns:
An Interval object representing the interval
Throws:
fuego.lang.IntervalFormatException
IntervalFormatException

getFieldName

public static String getFieldName(IntervalUnit field)

main

public static void main(String[] args)

negate

public static Interval negate(Interval op)
Returns the value of the interval with the sign changed. For example: interval = Interval.valueOf("2d") intervalNegate = interval.negate intervalNegate's value is "-2d".


valueOf

public static Interval valueOf(Time op1,
                               Time op2)
Returns the subtraction between two Times as an Interval object

Parameters:
op1 - First Time object.
op2 - Second Time object.

valueOf

public static Interval valueOf(BigDecimal ms)
Constructs an interval from a number of microseconds.

Parameters:
ms - The number of microseconds, can be negative.

valueOf

public static Interval valueOf(double ms)
Constructs an interval from a number of microseconds (from a double)

Parameters:
ms - The number of microseconds, can be negative.

valueOf

public static Interval valueOf(long microSeconds)
Constructs an interval from a number of microseconds (from a long)

Parameters:
microSeconds - The number of microseconds, can be negative.

fromMinutes

public static Interval fromMinutes(int minutes)
Constructs an interval from a number of minutes

Parameters:
minutes - The number of minutes, can be negative.

fromSeconds

public static Interval fromSeconds(int seconds)
Constructs an interval from a number of seconds

Parameters:
seconds - The number of seconds, can be negative.

yearsOnly

public static Interval yearsOnly(Interval i,
                                 int year)
Sets only the year value to an Interval object


getDays

public int getDays()
The "days" value for this interval. It is not reexpressed into months.


getDaysOnly

public int getDaysOnly()
The "days" value for this interval. It is not reexpressed into months.


getHours

public int getHours()
The "hours" value for this interval. It is not reexpressed into days.


getHoursOnly

public int getHoursOnly()
The "hours" value for this interval. It is not reexpressed into days.


getMicroSeconds

public long getMicroSeconds()
Hour portion of the interval reexpressed into microseconds. For example, if the interval has the value: 5567d16h45m22.221s, this attribute will contain the value: 60322221000, as the result of: ((((16h * 3600s) + (45m * 60s)) * 1000) + 22221) * 1000.


getMicroSecondsOnly

public int getMicroSecondsOnly()
The "microseconds" part of the interval. For example, if the interval has the value: 5567d16h45m22.221s, this attribute will contain the value: 221000, as the result of: 221 * 1000.


getMilliSeconds

public long getMilliSeconds()
Hour portion of the interval reexpressed into milliseconds. For example, if the interval has the value: 5567d16h45m22.221s, this attribute will contain the value: 60322221, as the result of: ((((16h * 3600s) + (45m * 60s)) * 1000) + 22221).


getMilliSecondsOnly

public int getMilliSecondsOnly()
The "milliseconds" part of the interval. For example, if the interval has the value: 5567d16h45m22.221s, this attribute will contain the value: 221.


getMinutes

public int getMinutes()
Hour portion of the interval reexpressed into minutes. For example, if the interval has the value: 5567d15h53m47.801s, this attribute will contain the value: 953, as the result of: (15h * 60m) + 53m.


getMinutesOnly

public int getMinutesOnly()
The "minutes" value of the interval. For example, if the interval has the value: 5567d15h53m47.801s, this attribute will contain the value: 53


getSeconds

public int getSeconds()
Hour portion of the interval reexpressed into seconds. For example, if the interval has the value: 5567d15h59m44.995s, this attribute will contain the value: 57584, as the result of: (15h * 3600s) + (53m * 60s) + 44s.


getMonthsOnly

public int getMonthsOnly()
The "months" value for this interval. This attribute has value only when the interval has been created specifically indicating months or years. Otherwise, its value is 0. For example, if the interval is created indicating the value: 20Y1M45d or 241M45d, the "months" value is: "1".


getSecondsOnly

public int getSecondsOnly()
The "seconds" value for this interval. For example, if the interval has the value: 5567d15h59m44.995s, this attribute will contain the value: 44.


getMonths

public int getMonths()
The "years/months" value for this interval expressed in months. This attribute has value only when the interval has been created specifically indicating months or years. Otherwise, its value is 0. For example, if the interval is created indicating the value: 20Y1M45d or 241M45d, the "months" value is: "241".


getYears

public int getYears()
The "years" value for this interval. This attribute has value only when the interval has been created specifically indicating months or years. Otherwise, its value is 0. For example, if the interval is created indicating the value: 20Y1M45d or 241M45d, the "years" value is: "20".


getYearsOnly

public int getYearsOnly()
The "years" value for this interval. This attribute has value only when the interval has been created specifically indicating months or years. Otherwise, its value is 0. For example, if the interval is created indicating the value: 20Y1M45d or 241M45d, the "years" value is: "20".


abs

public Interval abs()
Absolute value of this object. For Example: if you build an interval as the difference between two dates, and as first operand you set the older date, the interval will result negative. Using the "abs" method, you can forget about the interval sign.

Returns:
The absolute value of the object.

addDays

public Interval addDays(int i)
Adds days to an interval. It only modifies the "days" unit of the interval. That's for example, if the interval is 241M and you add "4 days" to it, the resultant interval is: 241M4d. And if it is: 241M29d and you add "4 days" to it, the resultant interval is: 241M33d, as the "day" unit of the interval is never reexpressed into months.

Parameters:
i - Days to add (can be negative)

addHours

public Interval addHours(long i)
Adds hours to an interval. Only the hours units of the interval is modified with this addition. Hours are not reexpressed into "days", that is why if the resultant interval has more than 24 hs, it is not reexpressed. For example: an interval of "3h" plus "24h", is an interval of "27h".

Parameters:
i - Hours to add (can be negative)

addMinutes

public Interval addMinutes(long i)
Adds minutes to this interval. The resultant minutes are reexpressed into hours. For example: "1h50m" plus "65m" results in an interval of: "2h55m".

Parameters:
i - Minutes to add (can be negative)

addMonths

public Interval addMonths(int i)
Adds months to this interval. The resultant quantity of months is reexpressed into years/months. For example the interval: "29d50m" plus "65M", results: "5Y5M29d50m".

Parameters:
i - Months to add (can be negative)

addYears

public Interval addYears(int i)
Adds years to this interval.

Parameters:
i - Years to add (can be negative)

compareTo

public int compareTo(Object b)
Compares this object with another Interval. The comparison returns: - 0 if the argument is equal to the object; - a value less than 0 if this object is previous cronologically to the argument; - a value greater than 0 otherwise.

Specified by:
compareTo in interface Comparable
Parameters:
b - the Interval to be compared.

equals

public boolean equals(Object b)
Compares this object with an object received as a parameter

Parameters:
b - an object to compare to.
Returns:
If the parameter object is not an instance of an Interval type object or is equal to null, this method returns false, otherwise it returns the result of the comparison.

add

public Time add(Time t)
Adds a interval to the Time specified as parameter.

Parameters:
t - The Time to add.

getAproximateTotal

public double getAproximateTotal(IntervalUnit field)

getOnly

public long getOnly(IntervalUnit field)

getTotalMicroseconds

public long getTotalMicroseconds()

get

public long get(IntervalUnit field)

hashCode

public int hashCode()
Returns hash code


max

public Interval max(Interval b)
Compares this object with the argument and returns the higher.

Parameters:
b - Interval The argument to compare with this object

setOnly

public Interval setOnly(IntervalUnit field,
                        long value)

min

public Interval min(Interval b)
Compares this object with the argument and returns the lower.

Parameters:
b - Interval The argument to compare with this object

negate

public Interval negate()
Returns a Interval whose value is (-this).


add

public Interval add(Interval t)
Adds an Interval.

Parameters:
t - The interval to add.

sub

public Interval sub(Interval t)
Substracts an Interval.

Parameters:
t - The interval to be substracted.

subFrom

public Time subFrom(Time t)
Substract from a Time.

Parameters:
t - The Time to be substracted from.

addMicroSeconds

public Interval addMicroSeconds(long i)
Adds micro-seconds to this interval

Parameters:
i - Micro-seconds to add (can be negative)

addSeconds

public Interval addSeconds(long i)
Adds seconds to this interval

Parameters:
i - Seconds to add (can be negative)

format

public String format(IntervalUnit from,
                     IntervalUnit to)
Formats the interval showing the interval units included in the from/to range. Possible interval units to include in the interval formatting are YEAR, MONTH, DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS, MICROSECODNS. YEAR and MONTH will show data, only if the interval was created specifing them. The interval units that correspond to hour are reexpressed if possible. The DAYS interval unit is never reexpressed, as the HOURS are not reexpressed into DAYS. Having an interval like: interval =Interval.valueOf("100M30d125m") display interval.format(YEARS, MICROSECONDS) ==> shows: 8Y4M30d2h5m display interval.format(YEARS, HOURS) ==> shows: 8Y4M30d2h display interval.format(HOURS, MICROSECONDS) ==> shows: 2h5m

Parameters:
from - IntervalUnit to format the interval from
to - IntervalUnit to format the interval to
Returns:
The string with the formatted output

format

public String format()
Formats the interval.

Returns:
The string with the formatted output.

intValue

public int intValue()
Number of seconds that the interval represents

Returns:
Number of seconds

retryIn

public String retryIn()
Deprecated. Maintained for backwards compatibility

This method has been deprecated, it is maintained for backwards compatibility.

Returns:
a result for global automatic polling activities

set

public Interval set(IntervalUnit field,
                    long value)

toString

public String toString()
Returns a string representation of an interval value


toXMLString

public String toXMLString()
Returns an XML string representation of an interval value


sleep

public void sleep()
           throws InterruptedException
Causes the current execution to sleep for the milliseconds value of this object.

Throws:
InterruptedException

ALBPM Process API (PAPI)

© Copyright 1996/2005 Fuego Inc. All Rights Reserved