com.emarsys.ecommon.time
Class TimeRange
java.lang.Object
com.emarsys.ecommon.time.TimeRange
public class TimeRange
- extends java.lang.Object
A TimeRange
represents a symetrical TimeInterval
around a given date (see setRangeMean(Calendar)
.
Per default a new TimeRange
will have its mean set to
the time of its instantiation, the range will be set to 0 and the
time unit, which is specified through Calendar
's time
unit constants, to Calendar.DAY_OF_YEAR
.
A TimeRange
of +- one hour around a given date
,
is for instance created this way:
Calendar date = ... ;
TimeRange range = TimeRange.getInstance()
.setRangeMean( date )
.setRange( 1 )
.setTimeUnit( Calendar.HOUR );
Calendar start = range.getStart();
Calendar end = range.getEnd();
Note that a TimeRange
is mutable!
If any property of a TimeRange
instance is changed through
the corresponding setter-method the derived ones (start, end, ...)
will be (re-)calculated on the next call of their getter method.
- Author:
- Michael "kULO" Kulovits
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
TimeRange
protected TimeRange()
- Parameters:
start
- end
- rangeMean
- range
- timeUnit
-
getInstance
public static TimeRange getInstance()
- Returns:
- a new
TimeRange
instance.
calculate
protected void calculate()
getInterval
public TimeInterval getInterval()
- Returns:
- the interval
setRangeMean
public TimeRange setRangeMean(java.util.Calendar searchDate)
- Parameters:
rangeMean
-
- Returns:
setRange
public TimeRange setRange(int range)
- Parameters:
range
-
- Returns:
setTimeUnit
public TimeRange setTimeUnit(int timeUnit)
- Parameters:
timeUnit
-
- Returns:
getDuration
public long getDuration()
- Returns:
- See Also:
TimeInterval.getDuration()
getEnd
public java.util.Calendar getEnd()
- Returns:
- See Also:
TimeInterval.getEnd()
getStart
public java.util.Calendar getStart()
- Returns:
- See Also:
TimeInterval.getStart()
intersect
public TimeInterval intersect(TimeInterval that)
- Parameters:
that
-
- Returns:
- See Also:
TimeInterval.intersect(com.emarsys.ecommon.time.TimeInterval)
isOverlapping
public boolean isOverlapping(TimeInterval that)
- Parameters:
that
-
- Returns:
- See Also:
TimeInterval.isOverlapping(com.emarsys.ecommon.time.TimeInterval)
isWithinInterval
public boolean isWithinInterval(java.util.Calendar date)
- Parameters:
date
-
- Returns:
- See Also:
TimeInterval.isWithinInterval(java.util.Calendar)
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
- Returns:
- See Also:
TimeInterval.toString()
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
- See Also:
Object.hashCode()
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in class java.lang.Object
- See Also:
Object.equals(java.lang.Object)
Copyright © 2010 emarsys AG. All Rights Reserved.