org.progeeks.tool.gen
Class DateGenerator
java.lang.Object
org.progeeks.tool.gen.BaseDataGenerator
org.progeeks.tool.gen.DateGenerator
- All Implemented Interfaces:
- DataGenerator
public class DateGenerator
- extends BaseDataGenerator
Generates a date between start and stop times. If stop is set less than start, will properly
reverse them. If start is not set, it is set by new Date(0)
. If stop is not set,
it is set by new Date()
each time generateData is called . In other words,
it will always represent the current time.
If movingRange
is true, the starting time will be converted to a time relative to
the stopping time as follows:
currentStart = new Date(stop.getTime() - start.getTime())
This is most useful if stop is not specified (i.e. is always the current time) and you want to
generate a date over some fixed-length period around the current time. Usually this means that
start should be set to some time relatively near Jan 1, 1970. Note that if you want to generate a
time after the present time, start should be set to before Jan 1, 1970 since that will
yield a negative value from start.getTime()
. currentStart
and
stop
are properly reversed in this case.
Field Summary |
protected static Log |
log
|
Methods inherited from class org.progeeks.tool.gen.BaseDataGenerator |
generateData, getAllowNull, getDataClass, getDataClazz, getEnforceResolvable, getNullPercentage, isDataValid, setAllowNull, setDataClass, setEnforceResolvable, setNullPercentage |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
log
protected static final Log log
DateGenerator
public DateGenerator()
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
generateRealData
protected java.lang.Object generateRealData(DataGeneratorContext context)
- Description copied from class:
BaseDataGenerator
- Left for sub-classes. Subclasses should usually not return null from this.
- Specified by:
generateRealData
in class BaseDataGenerator
testData
protected boolean testData(java.lang.Object testItem,
DataGeneratorContext context)
- Checks if the given item meets the criteria set for this generator. Assumes that the object
is of the proper type. Any date that is after the initial starting date (set during the
first call to
generateRealData
) and before the current stop date is valid. This
handles the case where movingRange is true and the current possible range of dates has moved
away from earlier values.
- Specified by:
testData
in class BaseDataGenerator
setCurrentRange
protected void setCurrentRange()
setStop
public void setStop(java.util.Date max)
- Parameters:
stop
- The stop to set.
setStart
public void setStart(java.util.Date min)
- Parameters:
start
- The start to set.
getStop
public java.util.Date getStop()
- Returns:
- Returns the stop.
getStart
public java.util.Date getStart()
- Returns:
- Returns the start.
isMovingRange
public boolean isMovingRange()
- Returns:
- Returns the movingRange.
setMovingRange
public void setMovingRange(boolean movingRange)
- Sets if this is a range based around the current time. Defaults to false.
- Parameters:
movingRange
- The movingRange to set.
Copyright © 2002-2003 Paul Speed. All Rights Reserved.