public class NumberedStringsIterator extends java.lang.Object implements java.util.Iterator<java.lang.String>
Iterator
that returns strings with defined prefix followed by an integer from a specified range.
This tool class is e.g. helpful for implementing data adapters in JPhyloIO or alignment models in LibrAlign that use numbered IDs.
The example applications of JPhyloIO demonstrate the usage of this class.
Constructor and Description |
---|
NumberedStringsIterator(java.lang.String prefix,
long count)
Creates a new instance of this class starting with the index 0.
|
NumberedStringsIterator(java.lang.String prefix,
long startIndex,
long count)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
static int |
extractIntIndexFromString(java.lang.String string,
java.lang.String prefix)
Extracts an index from a numbered string.
|
static long |
extractLongIndexFromString(java.lang.String string,
java.lang.String prefix)
Extracts an index from a numbered string.
|
boolean |
hasNext() |
java.lang.String |
next() |
void |
remove() |
public NumberedStringsIterator(java.lang.String prefix, long startIndex, long count)
prefix
- the prefix all returned IDs (strings) shall havestartIndex
- the index of the first ID (string) to be returnedcount
- the number of elements to be returned by this iteratorpublic NumberedStringsIterator(java.lang.String prefix, long count)
prefix
- the prefix all returned strings shall havecount
- the number of elements to be returned by this iteratorpublic boolean hasNext()
hasNext
in interface java.util.Iterator<java.lang.String>
public java.lang.String next()
next
in interface java.util.Iterator<java.lang.String>
public void remove()
remove
in interface java.util.Iterator<java.lang.String>
public static long extractLongIndexFromString(java.lang.String string, java.lang.String prefix)
string
- the string containing the indexprefix
- the prefix strings are expected to contain before the indexjava.lang.IllegalArgumentException
- if no index could be extracted from the specified stringpublic static int extractIntIndexFromString(java.lang.String string, java.lang.String prefix)
string
- the string containing the indexprefix
- the prefix strings are expected to contain before the indexjava.lang.IllegalArgumentException
- if no index could be extracted from the specified string