public final class

RandomIDGenerator

extends AbstractIDGenerator
java.lang.Object
   ↳ org.apache.commons.betwixt.io.id.AbstractIDGenerator
     ↳ org.apache.commons.betwixt.io.id.RandomIDGenerator

Class Overview

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) constructor.

Summary

Public Constructors
RandomIDGenerator()
Constructor sets the PositiveIds property to true.
RandomIDGenerator(boolean onlyPositiveIds)
Constructor sets PositiveIds property.
Public Methods
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
[Expand]
Inherited Methods
From class org.apache.commons.betwixt.io.id.AbstractIDGenerator
From class java.lang.Object
From interface org.apache.commons.betwixt.io.IDGenerator

Public Constructors

public RandomIDGenerator ()

Constructor sets the PositiveIds property to true.

public RandomIDGenerator (boolean onlyPositiveIds)

Constructor sets PositiveIds property.

Parameters
onlyPositiveIds set PositiveIds property to this value

Public Methods

public boolean getPositiveIds ()

Gets whether only positive ID's should be generated

Returns
  • whether only positive IDs should be generated

public 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.

Returns
  • a random integer (converted to a string)

public void setPositiveIds (boolean onlyPositiveIds)

Sets whether only positive ID's should be generated

Parameters
onlyPositiveIds pass true if only positive IDs should be generated