Package org.wildfly.common.iteration
Class CodePointIterator
- java.lang.Object
-
- org.wildfly.common.iteration.CodePointIterator
-
- All Implemented Interfaces:
BiDirIntIterator,IndexIterator,IntIterator
public abstract class CodePointIterator extends java.lang.Object implements BiDirIntIterator, IndexIterator
A code point by code point iterator.
-
-
Field Summary
Fields Modifier and Type Field Description static CodePointIteratorEMPTYThe empty code point iterator.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ByteIteratorasLatin1()Get a byte iterator over the latin-1 encoding of this code point iterator.ByteIteratorasUtf8()Get a byte iterator over the UTF-8 encoding of this code point iterator.ByteIteratorasUtf8(boolean escapeNul)Get a byte iterator over the UTF-8 encoding of this code point iterator.ByteIteratorbase32Decode()Base32-decode the current stream.ByteIteratorbase32Decode(Base32Alphabet alphabet)Base32-decode the current stream.ByteIteratorbase32Decode(Base32Alphabet alphabet, boolean requirePadding)Base32-decode the current stream.ByteIteratorbase64Decode()Base64-decode the current stream.ByteIteratorbase64Decode(Base64Alphabet alphabet)Base64-decode the current stream.ByteIteratorbase64Decode(Base64Alphabet alphabet, boolean requirePadding)Base64-decode the current stream.booleancontentEquals(java.lang.String other)Determine if the remaining contents of this iterator are identical to the given string.booleancontentEquals(CodePointIterator other)Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator.CodePointIteratordelimitedBy(int... delims)Get a sub-iterator that is delimited by the given code points.java.lang.StringBuilderdrainTo(java.lang.StringBuilder b)Drain all the remaining code points in this iterator to the given string builder.java.lang.StringBuilderdrainTo(java.lang.StringBuilder b, int delim, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given delimiter after everyncode points.java.lang.StringBuilderdrainTo(java.lang.StringBuilder b, java.lang.String prefix, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix before everyncode points.java.lang.StringBuilderdrainTo(java.lang.StringBuilder b, java.lang.String prefix, int delim, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix and delimiter before and after everyncode points, respectively.java.lang.StringdrainToString()Drain all the remaining code points in this iterator to a new string.java.lang.StringdrainToString(int delim, int n)Drain all the remaining code points in this iterator to a new string, inserting the given delimiter after everyncode points.java.lang.StringdrainToString(java.lang.String prefix, int n)Drain all the remaining code points in this iterator to a new string, inserting the given prefix before everyncode points.java.lang.StringdrainToString(java.lang.String prefix, int delim, int n)Drain all the remaining code points in this iterator to a new string, inserting the given prefix and delimiter before and after everyncode points, respectively.abstract longgetIndex()Get the current offset, by code point.abstract booleanhasNext()Determine if there are more code points after the current code point.abstract booleanhasPrevious()Determine if there are more code points before the current code point.ByteIteratorhexDecode()Hex-decode the current stream.CodePointIteratorlimitedTo(long size)Return a copy of this iterator which is limited to the given number of code points after the current one.abstract intnext()Get the next code point.static CodePointIteratorofChars(char[] chars)Get a code point iterator for a character array.static CodePointIteratorofChars(char[] chars, int offs)Get a code point iterator for a character array.static CodePointIteratorofChars(char[] chars, int offs, int len)Get a code point iterator for a character array.static CodePointIteratorofLatin1Bytes(byte[] bytes)Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.static CodePointIteratorofLatin1Bytes(byte[] bytes, int offs, int len)Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.static CodePointIteratorofString(java.lang.String string)Get a code point iterator for a string.static CodePointIteratorofString(java.lang.String string, int offs, int len)Get a code point iterator for a string.static CodePointIteratorofUtf8Bytes(byte[] bytes)Get a code point iterator for a UTF-8 encoded byte array.static CodePointIteratorofUtf8Bytes(byte[] bytes, int offs, int len)Get a code point iterator for a UTF-8 encoded array.abstract intpeekNext()Peek at the next code point without advancing.abstract intpeekPrevious()Peek at the previous code point without moving backwards.abstract intprevious()Get the previous code point.CodePointIteratorskip(java.util.function.IntPredicate predicate)Get a sub-iterator that removes code points based on apredicate.CodePointIteratorskipAll()Skip all the remaining code points in this iterator.CodePointIteratorskipCrLf()Get a sub-iterator that removes the following code points:10(\n) and13(\r).
-
-
-
Field Detail
-
EMPTY
public static final CodePointIterator EMPTY
The empty code point iterator.
-
-
Method Detail
-
hasNext
public abstract boolean hasNext()
Determine if there are more code points after the current code point.- Specified by:
hasNextin interfaceBiDirIntIterator- Specified by:
hasNextin interfaceIntIterator- Returns:
trueif there are more code points,falseotherwise
-
hasPrevious
public abstract boolean hasPrevious()
Determine if there are more code points before the current code point.- Specified by:
hasPreviousin interfaceBiDirIntIterator- Returns:
trueif there are more code points,falseotherwise
-
next
public abstract int next() throws java.util.NoSuchElementExceptionGet the next code point.- Specified by:
nextin interfaceBiDirIntIterator- Specified by:
nextin interfaceIntIterator- Returns:
- the next code point
- Throws:
java.util.NoSuchElementException- ifhasNext()returnsfalse
-
peekNext
public abstract int peekNext() throws java.util.NoSuchElementExceptionPeek at the next code point without advancing.- Specified by:
peekNextin interfaceBiDirIntIterator- Specified by:
peekNextin interfaceIntIterator- Returns:
- the next code point
- Throws:
java.util.NoSuchElementException- ifhasNext()returnsfalse
-
previous
public abstract int previous() throws java.util.NoSuchElementExceptionGet the previous code point.- Specified by:
previousin interfaceBiDirIntIterator- Returns:
- the previous code point
- Throws:
java.util.NoSuchElementException- ifhasPrevious()returnsfalse
-
peekPrevious
public abstract int peekPrevious() throws java.util.NoSuchElementExceptionPeek at the previous code point without moving backwards.- Specified by:
peekPreviousin interfaceBiDirIntIterator- Returns:
- the previous code point
- Throws:
java.util.NoSuchElementException- ifhasPrevious()returnsfalse
-
getIndex
public abstract long getIndex()
Get the current offset, by code point.- Specified by:
getIndexin interfaceIndexIterator- Returns:
- the code point offset
-
contentEquals
public final boolean contentEquals(CodePointIterator other)
Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator. If the contents are not equal, the iterators will be positioned at the location of the first difference (i.e. the code point returned bynext()will be the differing code point. If the contents are equal, the iterators will both be positioned at the end of their contents.- Parameters:
other- the other byte iterator- Returns:
trueif the contents are equal,falseotherwise
-
contentEquals
public boolean contentEquals(java.lang.String other)
Determine if the remaining contents of this iterator are identical to the given string. If the contents are not equal, the iterator will be positioned at the location of the first difference (i.e. the code point returned bynext()will be the differing code point. If the contents are equal, the iterator will be positioned at the end of its contents.- Parameters:
other- the other string- Returns:
trueif the contents are equal,falseotherwise
-
limitedTo
public final CodePointIterator limitedTo(long size)
Return a copy of this iterator which is limited to the given number of code points after the current one. Advancing the returned iterator will also advance this one.- Parameters:
size- the number of code points- Returns:
- the limited code point iterator
-
delimitedBy
public final CodePointIterator delimitedBy(int... delims)
Get a sub-iterator that is delimited by the given code points. The returned iterator offset starts at 0 and cannot be backed up before that point. The returned iterator will returnfalseforhasNext()if the next character in the encapsulated iterator is a delimiter or if the underlying iterator returnsfalseforhasNext().- Parameters:
delims- the code point delimiters- Returns:
- the sub-iterator
-
drainTo
public java.lang.StringBuilder drainTo(java.lang.StringBuilder b)
Drain all the remaining code points in this iterator to the given string builder.- Parameters:
b- the string builder- Returns:
- the same string builder
-
skipAll
public CodePointIterator skipAll()
Skip all the remaining code points in this iterator. (Useful in combination withdelimitedBy(int...))- Returns:
- the same code point iterator
-
drainTo
public java.lang.StringBuilder drainTo(java.lang.StringBuilder b, java.lang.String prefix, int delim, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix and delimiter before and after everyncode points, respectively.- Parameters:
b- the string builderprefix- the prefixdelim- the delimitern- the number of code points between each prefix and delimiter- Returns:
- the same string builder
-
drainTo
public java.lang.StringBuilder drainTo(java.lang.StringBuilder b, int delim, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given delimiter after everyncode points.- Parameters:
b- the string builderdelim- the delimitern- the number of code points between each delimiter- Returns:
- the same string builder
-
drainTo
public java.lang.StringBuilder drainTo(java.lang.StringBuilder b, java.lang.String prefix, int n)Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix before everyncode points.- Parameters:
b- the string builderprefix- the prefixn- the number of code points between each prefix- Returns:
- the same string builder
-
drainToString
public java.lang.String drainToString()
Drain all the remaining code points in this iterator to a new string.- Returns:
- the string
-
drainToString
public java.lang.String drainToString(java.lang.String prefix, int delim, int n)Drain all the remaining code points in this iterator to a new string, inserting the given prefix and delimiter before and after everyncode points, respectively.- Parameters:
prefix- the prefixdelim- the delimitern- the number of code points between each prefix and delimiter- Returns:
- the string
-
drainToString
public java.lang.String drainToString(int delim, int n)Drain all the remaining code points in this iterator to a new string, inserting the given delimiter after everyncode points.- Parameters:
delim- the delimitern- the number of code points between each delimiter- Returns:
- the string
-
drainToString
public java.lang.String drainToString(java.lang.String prefix, int n)Drain all the remaining code points in this iterator to a new string, inserting the given prefix before everyncode points.- Parameters:
prefix- the prefixn- the number of code points between each prefix- Returns:
- the string
-
base64Decode
public ByteIterator base64Decode(Base64Alphabet alphabet, boolean requirePadding)
Base64-decode the current stream.- Parameters:
alphabet- the alphabet to userequirePadding-trueto require padding,falseif padding is optional- Returns:
- an iterator over the decoded bytes
-
base32Decode
public ByteIterator base32Decode(Base32Alphabet alphabet, boolean requirePadding)
Base32-decode the current stream.- Parameters:
alphabet- the alphabet to userequirePadding-trueto require padding,falseif padding is optional- Returns:
- an iterator over the decoded bytes
-
hexDecode
public ByteIterator hexDecode()
Hex-decode the current stream.- Returns:
- an iterator over the decoded bytes
-
base64Decode
public ByteIterator base64Decode(Base64Alphabet alphabet)
Base64-decode the current stream.- Parameters:
alphabet- the alphabet to use- Returns:
- an iterator over the decoded bytes
-
base64Decode
public ByteIterator base64Decode()
Base64-decode the current stream.- Returns:
- an iterator over the decoded bytes
-
base32Decode
public ByteIterator base32Decode(Base32Alphabet alphabet)
Base32-decode the current stream.- Parameters:
alphabet- the alphabet to use- Returns:
- an iterator over the decoded bytes
-
base32Decode
public ByteIterator base32Decode()
Base32-decode the current stream.- Returns:
- an iterator over the decoded bytes
-
asLatin1
public ByteIterator asLatin1()
Get a byte iterator over the latin-1 encoding of this code point iterator.- Returns:
- the byte iterator
-
asUtf8
public ByteIterator asUtf8()
Get a byte iterator over the UTF-8 encoding of this code point iterator.- Returns:
- the byte iterator
-
asUtf8
public ByteIterator asUtf8(boolean escapeNul)
Get a byte iterator over the UTF-8 encoding of this code point iterator.- Parameters:
escapeNul-trueto escape NUL (0) characters as two bytes,falseto encode them as one byte- Returns:
- the byte iterator
-
ofString
public static CodePointIterator ofString(java.lang.String string)
Get a code point iterator for a string.- Parameters:
string- the string- Returns:
- the code point iterator
-
ofString
public static CodePointIterator ofString(java.lang.String string, int offs, int len)
Get a code point iterator for a string.- Parameters:
string- the string- Returns:
- the code point iterator
-
ofChars
public static CodePointIterator ofChars(char[] chars)
Get a code point iterator for a character array.- Parameters:
chars- the array- Returns:
- the code point iterator
-
ofChars
public static CodePointIterator ofChars(char[] chars, int offs)
Get a code point iterator for a character array.- Parameters:
chars- the arrayoffs- the array offset- Returns:
- the code point iterator
-
ofChars
public static CodePointIterator ofChars(char[] chars, int offs, int len)
Get a code point iterator for a character array.- Parameters:
chars- the arrayoffs- the array offsetlen- the number of characters to include- Returns:
- the code point iterator
-
ofUtf8Bytes
public static CodePointIterator ofUtf8Bytes(byte[] bytes)
Get a code point iterator for a UTF-8 encoded byte array.- Parameters:
bytes- the array- Returns:
- the code point iterator
-
ofUtf8Bytes
public static CodePointIterator ofUtf8Bytes(byte[] bytes, int offs, int len)
Get a code point iterator for a UTF-8 encoded array.- Parameters:
bytes- the arrayoffs- the array offsetlen- the number of characters to include- Returns:
- the code point iterator
-
ofLatin1Bytes
public static CodePointIterator ofLatin1Bytes(byte[] bytes)
Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.- Parameters:
bytes- the array- Returns:
- the code point iterator
-
ofLatin1Bytes
public static CodePointIterator ofLatin1Bytes(byte[] bytes, int offs, int len)
Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.- Parameters:
bytes- the arrayoffs- the array offsetlen- the number of characters to include- Returns:
- the code point iterator
-
skipCrLf
public CodePointIterator skipCrLf()
Get a sub-iterator that removes the following code points:10(\n) and13(\r).- Returns:
- the code point iterator
-
skip
public CodePointIterator skip(java.util.function.IntPredicate predicate)
Get a sub-iterator that removes code points based on apredicate.- Parameters:
predicate- aIntPredicatethat evaluates the code points that should be skipper. Returning true from the predicate indicates that the code point must be skipped.- Returns:
- the code point iterator
-
-