com.miginfocom.util.dates
Class BoundaryRounder

java.lang.Object
  extended by com.miginfocom.util.dates.BoundaryRounder
All Implemented Interfaces:
DateRangeRounder, java.io.Serializable

public class BoundaryRounder
extends java.lang.Object
implements DateRangeRounder

Rounds DateRangeI's and Calendar's to specified intervals.
NOTE! This rounder rounds to a specific point i absolute time with no compensation for rounding over daylight savings and such..

See Also:
Serialized Form

Constructor Summary
BoundaryRounder(int boundaryType)
          Constructor that rounds start and end but doesn't try to keep the same length
BoundaryRounder(int boundaryType, boolean roundStart, boolean roundEnd, boolean keepSameLength)
          Constructor.
BoundaryRounder(int boundaryType, boolean roundStart, boolean roundEnd, boolean keepSameLength, java.lang.Integer minSize, java.lang.Integer maxSize, java.lang.Integer cutAlignment)
          Constructor.
 
Method Summary
 int getBoundaryType()
          Return the boundary type to round to.
 int getCutAlignment()
          Returns how to align a cutted/expanded oundary.
 boolean getKeepSameLength()
          Returns if the length of the rounded range should be kept.
 int getMaximumSize()
          Returns the maximum number of boundaryType that the rounded MutableDateRange should be able to span.
 int getMinimumSize()
          Returns the minimum number of boundaryType that the rounded MutableDateRange should be able to span.
 boolean getRoundEnd()
          Returns if the end date/time should be rounded.
 boolean getRoundStart()
          Returns if the start date/time should be rounded.
 MutableDateRange round(MutableDateRange dateRange)
          Rounds the start and/or end dates and possibly ajdusts the not rounded date/time so the length will be same.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundaryRounder

public BoundaryRounder(int boundaryType)
Constructor that rounds start and end but doesn't try to keep the same length

Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.RANGE_TYPE_DAY.

BoundaryRounder

public BoundaryRounder(int boundaryType,
                       boolean roundStart,
                       boolean roundEnd,
                       boolean keepSameLength)
Constructor.

Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.RANGE_TYPE_DAY.
roundStart - If the start date/time should be rounded.
roundEnd - If the end date/time should be rounded.
keepSameLength - If not both of roundStart and roundEnd of a MutableDateRange are rounded and keepSameLength is true, the one of roundStart or roundEnd time that is not rounded will be set so that the spanned time in the range will remain the same.
If this is true, the result is actually a rounded move of the range rather than a resize.
keepSameLength can't be true if both roundStart and roundEnd is true.

BoundaryRounder

public BoundaryRounder(int boundaryType,
                       boolean roundStart,
                       boolean roundEnd,
                       boolean keepSameLength,
                       java.lang.Integer minSize,
                       java.lang.Integer maxSize,
                       java.lang.Integer cutAlignment)
Constructor.

Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.RANGE_TYPE_DAY.
roundStart - If the start date/time should be rounded.
roundEnd - If the end date/time should be rounded.
keepSameLength - If not both of roundStart and roundEnd of a MutableDateRange are rounded and keepSameLength is true, the one of roundStart or roundEnd time that is not rounded will be set so that the spanned time in the range will remain the same.
If this is true, the result is actually a rounded move of the range rather than a resize.
keepSameLength can't be true if both roundStart and roundEnd is true.
Note! minSize and maxSize has precidence over keepSameLength.
minSize - Minimum number of boundaryType that the rounded MutableDateRange should be able to span. null means no boundary.
maxSize - Maximum number of boundaryType that the rounded MutableDateRange should be able to span. null means no boundary.
cutAlignment - If the range has to be cutted or expanded to comply with minSize or maxSize there is a matter of where to cut/add the superfluous/extra time. If null the rounded edge is always cut/added to and if both are rounded both sides are handled equally thus the alignment can be said to be "centered".
Setting this value becomes a little more complicated if one think of that the returned range can be unsorted (I.e. start > end). That is why there are five choices. They are MutableDateRange.ALIGN_CENTER_DOWN, MutableDateRange.ALIGN_CENTER_UP, MutableDateRange.ALIGN_START, MutableDateRange.ALIGN_END, MutableDateRange.ALIGN_EARLIEST, MutableDateRange.ALIGN_LATEST.
Method Detail

round

public MutableDateRange round(MutableDateRange dateRange)
Description copied from interface: DateRangeRounder
Rounds the start and/or end dates and possibly ajdusts the not rounded date/time so the length will be same.

Specified by:
round in interface DateRangeRounder
Parameters:
dateRange - The MutableDateRange to round. Will be changed.
Returns:
dateRange for the possiblility to chain.

getBoundaryType

public int getBoundaryType()
Return the boundary type to round to. E.g. DateRangeI.RANGE_TYPE_DAY.

Returns:
The boundary type to round to. E.g. DateRangeI.RANGE_TYPE_DAY.

getCutAlignment

public int getCutAlignment()
Returns how to align a cutted/expanded oundary. If not 0 the cut alignment if forced to one of MutableDateRange.ALIGN_CENTER_DOWN, MutableDateRange.ALIGN_CENTER_UP, MutableDateRange.ALIGN_START, MutableDateRange.ALIGN_END, MutableDateRange.ALIGN_EARLIEST, MutableDateRange.ALIGN_LATEST.

Returns:
How to align a cutted/expanded oundary. E.g. MutableDateRange.ALIGN_END.
See Also:
getAlignment(boolean, boolean)

getKeepSameLength

public boolean getKeepSameLength()
Returns if the length of the rounded range should be kept. If not both of roundStart and roundEnd of a MutableDateRange are rounded and keepSameLength is true, the one of roundStart or roundEnd time that is not rounded will be set so that the spanned time in the range will remain the same.
If this is true, the result is actually a rounded move of the range rather than a resize.
keepSameLength can't be true if both roundStart and roundEnd is true.
Note! minSize and maxSize has precidence over keepSameLength.

Returns:
If the length of the rounded range should be kept.

getMinimumSize

public int getMinimumSize()
Returns the minimum number of boundaryType that the rounded MutableDateRange should be able to span.

Returns:
The minimum number of boundaryType that the rounded MutableDateRange should be able to span.

getMaximumSize

public int getMaximumSize()
Returns the maximum number of boundaryType that the rounded MutableDateRange should be able to span.

Returns:
The maximum number of boundaryType that the rounded MutableDateRange should be able to span.

getRoundStart

public boolean getRoundStart()
Returns if the start date/time should be rounded.

Returns:
If the start date/time should be rounded.

getRoundEnd

public boolean getRoundEnd()
Returns if the end date/time should be rounded.

Returns:
If the end date/time should be rounded.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.