public class IdGenerator extends Object
Each value generated is made of two main parts separated by a '-':
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ROOT_ID |
static String |
DOCUMENT_PART |
static String |
END_DOCUMENT |
static String |
END_GROUP |
static String |
END_SUBDOCUMENT |
static String |
END_SUBFILTER |
static String |
START_DOCUMENT |
static String |
START_GROUP |
static String |
START_SUBDOCUMENT |
static String |
START_SUBFILTER |
static String |
SUBFILTERED_EVENT |
static String |
TEXT_UNIT |
| Constructor and Description |
|---|
IdGenerator()
Creates a generator with a empty root and no prefix.
|
IdGenerator(String root)
Creates a generator with a given root and no prefix.
|
IdGenerator(String root,
String prefix)
Creates a generator with a given root and a given prefix.
|
| Modifier and Type | Method and Description |
|---|---|
String |
createId()
Creates a new identifier.
|
String |
createId(String prefix)
Creates a new identifier with the given prefix
|
String |
createIdNotInList(List<String> list)
Creates a new identifier that is not in the given list.
|
String |
getLastId()
Gets the last identifier generated.
|
String |
getRootId()
Gets the id generated from the root string given when creating this object.
|
long |
getSequence()
Get the current sequence number.
|
void |
reset(String rootId)
Reset the
IdGenerator with a new root id. |
void |
setLastId(String lastId)
sets the internal value that is used to remember the last identifier.
|
void |
setPrefix(String prefix)
Sets the prefix to use when creating the id.
|
void |
setSequence(long sequence)
Set the sequence from outside.
|
String |
toString()
Returns the same value as
getLastId(). |
public static final String START_DOCUMENT
public static final String END_DOCUMENT
public static final String START_GROUP
public static final String END_GROUP
public static final String TEXT_UNIT
public static final String DOCUMENT_PART
public static final String START_SUBDOCUMENT
public static final String END_SUBDOCUMENT
public static final String START_SUBFILTER
public static final String SUBFILTERED_EVENT
public static final String END_SUBFILTER
public static final String DEFAULT_ROOT_ID
public IdGenerator()
public IdGenerator(String root)
root - the root to use (case-sensitive, can be null or empty)public String toString()
getLastId().public String createId()
public String createIdNotInList(List<String> list)
list - the list of identifiers not to use.public String createId(String prefix)
prefix - the prefix to be used with this idpublic String getLastId()
createId().RuntimeException - if the method createId() has not been
called at least once before call this method.public void setLastId(String lastId)
lastId - the new last id.public String getRootId()
public long getSequence()
public void setSequence(long sequence)
sequence - the new sequence.public void reset(String rootId)
IdGenerator with a new root id. Use the same prefix and set
the sequence count to 0.rootId - new root id (can be null or empty)public void setPrefix(String prefix)
prefix - the new prefix to use (can be null).Copyright © 2022. All rights reserved.