public final class RandomIDGenerator extends AbstractIDGenerator
Generates ID
's at random.
The random number source is java.util.Random
.
Random ID
's are very useful if you're inserting
elements created by Betwixt
into a stream with existing
elements.
Using random ID
's should reduce the danger of collision
with existing element ID
's.
This class can generate positive-only ids (the default)
or it can generate a mix of negative and postive ones.
This behaviour can be set by setPositiveIds(boolean)
or by using the RandomIDGenerator(boolean onlyPositiveIds)
constructor.
Constructor and Description |
---|
RandomIDGenerator()
Constructor sets the
PositiveIds property to true . |
RandomIDGenerator(boolean onlyPositiveIds)
Constructor sets
PositiveIds property. |
Modifier and Type | Method and Description |
---|---|
boolean |
getPositiveIds()
Gets whether only positive
ID 's should be generated |
String |
nextIdImpl()
Generates a random
ID . |
void |
setPositiveIds(boolean onlyPositiveIds)
Sets whether only positive
ID 's should be generated |
getLastId, nextId
public RandomIDGenerator()
PositiveIds
property to true
.public RandomIDGenerator(boolean onlyPositiveIds)
PositiveIds
property.onlyPositiveIds
- set PositiveIds
property to this valuepublic String nextIdImpl()
Generates a random ID
.
If the PositiveIds
property is true,
then this method will recursively call itself if the random
ID
is less than zero.
nextIdImpl
in class AbstractIDGenerator
public boolean getPositiveIds()
ID
's should be generatedpublic void setPositiveIds(boolean onlyPositiveIds)
ID
's should be generatedonlyPositiveIds
- pass true if only positive IDs should be generatedCopyright © 2002-2013 Apache Software Foundation. All Rights Reserved.