Package com.github.tommyettinger.digital
Class Base
java.lang.Object
com.github.tommyettinger.digital.Base
Provides ways to encode digits in different base systems, or radixes, and decode numbers written in those bases. This
includes base systems such as binary (
Each of these base systems provides a way to write bytes, shorts, ints, and longs as variable-character-count signed numbers or as fixed-character-count unsigned numbers, using
BASE2
, using just 0 and 1), octal (BASE8
, 0 through 7),
decimal (BASE10
, 0 through 9), hexadecimal (BASE16
, 0-9 then A-F), and the even larger
hexatrigesimal (BASE36
, 0 through 9 then A-Z). Of special note are the two different approaches to encoding
base-64 data: BASE64
is the standard format, and URI_SAFE
is the different format used when
encoding data for a URI (typically meant for the Internet). The newest is BASE86
, which is also the largest
base, and uses 0-9, A-Z, a-z, and then many punctuation characters. Even more bases can be created with
scrambledBase(Random)
, which when called creates a base-72 Base with randomized choices for digits;
this could be useful for obfuscating plain-text saved data so the average player can't read it.
Each of these base systems provides a way to write bytes, shorts, ints, and longs as variable-character-count signed numbers or as fixed-character-count unsigned numbers, using
signed(long)
and unsigned(long)
respectively. There is only one reading method for each size of number, but it is capable of reading both the signed
and unsigned results, and never throws an Exception (it just returns 0 if no number could be read). Each base system
can also read and write floats and doubles, but only using their bit representation, treated as an int or long.-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal int
What base or radix this uses; if you useunsigned(int)
, then base must be an even number.static final Base
Decimal, using the digits 0-9.static final Base
Hexadecimal, using the digits 0-9 and then A-F (case-insensitive).static final Base
Binary, using the digits 0 and 1.static final Base
Hexatrigesimal, using the digits 0-9 and then A-Z (case-insensitive).static final Base
One of three base-64 schemes available here, this is the more-standard one, using the digits A-Z, then a-z, then 0-9, then + and / (case-sensitive).static final Base
Octal, using the digits 0-7.static final Base
The largest base here, this uses digits 0-9 first, then A-Z, then a-z, them many punctuation characters:'/!@#$%^&*()[]{}<>:?;|_=
.final boolean
Will be true if this base system treats upper- and lower-case letters present in the encoding as the same.final int[]
An array of the digit values corresponding to different ASCII codepoints, with -1 used for codepoints that do not correspond to any digit in this base.final char
Used to indicate negative numbers withsigned(int)
and when reading them back withreadInt(CharSequence)
; like-
in most numeral systems.final char
When an encoding needs to indicate that a char is not considered part of a number, it uses this padding char; this is mostly relevant for other code using Base-64 and URI-safe encodings, and is not used here.final char
Can be used to indicate positive numbers; like+
in most numeral systems, this is usually ignored.static final Base
One of three base-64 schemes available here, this is a non-standard one that is more in-line with common expectations for how numbers should look.final char[]
The digits this will encode to, in order from smallest to largest.static final Base
One of three base-64 schemes available here, this is meant for URI-encoding, using the digits A-Z, then a-z, then 0-9, then + and - (case-sensitive). -
Constructor Summary
ConstructorsConstructorDescriptionAn unlikely-to-be-used copy constructor.Constructs a Base with the given digits, ordered from smallest to largest, with any letters in the digits treated as case-insensitive, and the normal sign characters '+' and '-'.Constructs a base with the given digits, ordered from smallest to largest, specified treatment for case, and specified padding char (currently unused other than to provide a separator), positive sign, and negative sign. -
Method Summary
Modifier and TypeMethodDescriptionappendJoined
(StringBuilder sb, String delimiter, byte[] elements) Given a byte array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all bytes from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, char[] elements) Given a char array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all chars (as numbers) from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, double[] elements) Given a double array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all doubles from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, float[] elements) Given a float array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all floats from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, int[] elements) Given an int array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all ints from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, long[] elements) Given a long array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all longs from elements, in this Base, separated by delimiter.appendJoined
(StringBuilder sb, String delimiter, short[] elements) Given a short array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all shorts from elements, in this Base, separated by delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, byte[][] elements) Given a byte 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all bytes from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, char[][] elements) Given a char 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all chars from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, double[][] elements) Given a double 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all doubles from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, float[][] elements) Given a float 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all floats from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, int[][] elements) Given an int 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all ints from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, long[][] elements) Given a long 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all longs from elements, in this Base, separated by minor delimiter and then by major delimiter.appendJoined2D
(StringBuilder sb, String majorDelimiter, String minorDelimiter, short[][] elements) Given a short 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all shorts from elements, in this Base, separated by minor delimiter and then by major delimiter.appendSigned
(StringBuilder builder, byte number) Converts the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, char number) Converts the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, double number) Converts the bits of the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, float number) Converts the bits of the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, int number) Converts the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, long number) Converts the givennumber
to this Base as signed, appending the result tobuilder
.appendSigned
(StringBuilder builder, short number) Converts the givennumber
to this Base as signed, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, byte number) Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, char number) Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, double number) Converts the bits of the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, float number) Converts the bits of the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, int number) Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, long number) Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.appendUnsigned
(StringBuilder builder, short number) Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.byte[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a byte array.byte[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a byte array.byte[][]
byteSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D byte array.byte[][]
byteSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D byte array.char[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a char array.char[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a char array.char[][]
charSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D char array.char[][]
charSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D char array.protected static int
Scans repeatedly insource
(only using the area from startIndex, inclusive, to endIndex, exclusive) for the Stringsearch
, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source or search is null or if the searched area is empty.static Base
deserializeFromString
(String data) Given a String of a serialized Base (almost always produced byserializeToString()
), this re-creates that Base and returns it.double[]
doubleSplit
(String source, String delimiter) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a double array.double[]
doubleSplit
(String source, String delimiter, int startIndex, int endIndex) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a double array.double[][]
doubleSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D double array.double[][]
doubleSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D double array.boolean
float[]
floatSplit
(String source, String delimiter) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a float array.float[]
floatSplit
(String source, String delimiter, int startIndex, int endIndex) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a float array.float[][]
floatSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D float array.float[][]
floatSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D float array.int
hashCode()
int[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as an int array.int[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as an int array.int[][]
intSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D int array.int[][]
intSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D int array.Given a byte array and a delimiter to separate the items of that array, produces a String containing all bytes from elements, in this Base, separated by delimiter.Given a char array and a delimiter to separate the items of that array, produces a String containing all chars (as numbers) from elements, in this Base, separated by delimiter.Given a double array and a delimiter to separate the items of that array, produces a String containing all doubles from elements, in this Base, separated by delimiter.Given a float array and a delimiter to separate the items of that array, produces a String containing all floats from elements, in this Base, separated by delimiter.Given an int array and a delimiter to separate the items of that array, produces a String containing all ints from elements, in this Base, separated by delimiter.Given a long array and a delimiter to separate the items of that array, produces a String containing all longs from elements, in this Base, separated by delimiter.Given a short array and a delimiter to separate the items of that array, produces a String containing all shorts from elements, in this Base, separated by delimiter.long[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a long array.long[]
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a long array.long[][]
longSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D long array.long[][]
longSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D long array.byte
readByte
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read.byte
readByte
(CharSequence cs) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read.byte
readByte
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read.char
readChar
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read.char
readChar
(CharSequence cs) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read.char
readChar
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read.double
readDouble
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read.double
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read.double
readDouble
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read.float
readFloat
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read.float
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read.float
readFloat
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read.int
readInt
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read.int
readInt
(CharSequence cs) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read.int
readInt
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read.long
readLong
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read.long
readLong
(CharSequence cs) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read.long
readLong
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read.short
readShort
(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read.short
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read.short
readShort
(CharSequence cs, int start, int end) Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read.Copies this Base and shuffles the digit values in the copy.static Base
scrambledBase
(Random random) Returns a seemingly-gibberish Base that uses a radix of 72 and a randomly-ordered set of characters to represent the different digit values.Stores this Base as a compact String; the String this produces is usually given todeserializeFromString(String)
to restore the Base.short[]
shortSplit
(String source, String delimiter) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a short array.short[]
shortSplit
(String source, String delimiter, int startIndex, int endIndex) Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a short array.short[][]
shortSplit2D
(String source, String majorDelimiter, String minorDelimiter) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D short array.short[][]
shortSplit2D
(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D short array.signed
(byte number) Converts the givennumber
to this Base as signed, returning a new String.signed
(char number) Converts the givennumber
to this Base as signed, returning a new String.signed
(double number) Converts the bits of the givennumber
to this Base as signed, returning a new String.signed
(float number) Converts the bits of the givennumber
to this Base as signed, returning a new String.signed
(int number) Converts the givennumber
to this Base as signed, returning a new String.signed
(long number) Converts the givennumber
to this Base as signed, returning a new String.signed
(short number) Converts the givennumber
to this Base as signed, returning a new String.unsigned
(byte number) Converts the givennumber
to this Base as unsigned, returning a new String.unsigned
(char number) Converts the givennumber
to this Base as unsigned, returning a new String.unsigned
(double number) Converts the bits of the givennumber
to this Base as unsigned, returning a new String.unsigned
(float number) Converts the bits of the givennumber
to this Base as unsigned, returning a new String.unsigned
(int number) Converts the givennumber
to this Base as unsigned, returning a new String.unsigned
(long number) Converts the givennumber
to this Base as unsigned, returning a new String.unsigned
(short number) Converts the givennumber
to this Base as unsigned, returning a new String.values()
Returns an immutable List of the Base instances this knows about from the start.
-
Field Details
-
BASE2
Binary, using the digits 0 and 1. -
BASE8
Octal, using the digits 0-7. -
BASE10
Decimal, using the digits 0-9. -
BASE16
Hexadecimal, using the digits 0-9 and then A-F (case-insensitive). -
BASE36
Hexatrigesimal, using the digits 0-9 and then A-Z (case-insensitive). -
BASE64
One of three base-64 schemes available here, this is the more-standard one, using the digits A-Z, then a-z, then 0-9, then + and / (case-sensitive). This uses * in place of + to indicate a positive sign, and - for negative. Because this can use the / character, it sometimes needs quoting when used with libGDX's "minimal JSON" format. -
URI_SAFE
One of three base-64 schemes available here, this is meant for URI-encoding, using the digits A-Z, then a-z, then 0-9, then + and - (case-sensitive). This uses * in place of + to indicate a positive sign, and ! in place of - . -
SIMPLE64
One of three base-64 schemes available here, this is a non-standard one that is more in-line with common expectations for how numbers should look. It uses the digits 0-9, then A-Z, then a-z, then ! and ? (all case-sensitive). Unlike the other base-64 schemes, this uses + for its positive sign and - for its negative sign. -
BASE86
The largest base here, this uses digits 0-9 first, then A-Z, then a-z, them many punctuation characters:'/!@#$%^&*()[]{}<>:?;|_=
. This uses + to indicate a positive sign, and - for negative. This can encode a 32-bit number with 5 chars (unsigned); none of the other bases can. As a drawback, if a BASE86 encoded number is stored in libGDX's "minimal JSON" format, it will often need quoting, which of the other bases, onlyBASE64
requires sometimes. -
toEncoded
public final char[] toEncodedThe digits this will encode to, in order from smallest to largest. These must all be in the ASCII range.
This should not be changed after the Base has been used; changing this makes a Base incompatible with its previously-returned numbers as Strings. -
fromEncoded
public final int[] fromEncodedAn array of the digit values corresponding to different ASCII codepoints, with -1 used for codepoints that do not correspond to any digit in this base.
This should not be changed after the Base has been used; changing this makes a Base incompatible with its previously-returned numbers as Strings. You can change it in conjunction withtoEncoded
as part of creating a different Base, but if you are doing that to obfuscate output, you can usescrambledBase(Random)
instead. -
paddingChar
public final char paddingCharWhen an encoding needs to indicate that a char is not considered part of a number, it uses this padding char; this is mostly relevant for other code using Base-64 and URI-safe encodings, and is not used here. It defaults to the space char,' '
, if not specified. -
positiveSign
public final char positiveSignCan be used to indicate positive numbers; like+
in most numeral systems, this is usually ignored. -
negativeSign
public final char negativeSignUsed to indicate negative numbers withsigned(int)
and when reading them back withreadInt(CharSequence)
; like-
in most numeral systems. -
caseInsensitive
public final boolean caseInsensitiveWill be true if this base system treats upper- and lower-case letters present in the encoding as the same. -
base
public final int baseWhat base or radix this uses; if you useunsigned(int)
, then base must be an even number.
-
-
Constructor Details
-
Base
Constructs a Base with the given digits, ordered from smallest to largest, with any letters in the digits treated as case-insensitive, and the normal sign characters '+' and '-'. All digits must be unique when compared as case-insensitive; this means you can't have 'a' and 'A' both in the digits String, or any other repeats. You also can't use '$', '+', or '-' in digits, and all chars in it should usually be ASCII. In many cases, Unicode numbering systems outside of ASCII, but within a block of 128 or fewer chars may work, but this isn't assured.- Parameters:
digits
- a String with two or more ASCII characters, all unique; none can be '$', '+', or '-'
-
Base
public Base(String digits, boolean caseInsensitive, char padding, char positiveSign, char negativeSign) Constructs a base with the given digits, ordered from smallest to largest, specified treatment for case, and specified padding char (currently unused other than to provide a separator), positive sign, and negative sign. All digits must be unique, and if caseInsensitive is true, must also be unique when compared as case-insensitive; this means that if caseInsensitive is true, you can't have 'a' and 'A' both in the digits String, and you can never have any repeats. You also can't use padding, positiveSign, or negativeSign in digits, and all chars in it should usually be ASCII. In many cases, Unicode numbering systems outside of ASCII, but within a block of 128 or fewer chars may work, but this isn't assured.- Parameters:
digits
- a String with two or more ASCII characters, all unique; none can be the same as the later sign parameterscaseInsensitive
- if true, digits will be converted to upper-case before any operations on them.padding
- only used to guarantee a separator is possible between numberspositiveSign
- typically '+'negativeSign
- typically '-'
-
Base
An unlikely-to-be-used copy constructor. A Base doesn't have any changing state between method calls, so the only reason you would need to copy an existing Base is to edit it. Even then, most changes would need to be made to the contents offromEncoded
andtoEncoded
, since those can be edited, but other fields are generally final here.- Parameters:
other
- another Base; must be non-null
-
-
Method Details
-
values
Returns an immutable List of the Base instances this knows about from the start. Mostly useful for testing. This is something like an enum's values() method, but unlike an enum, this returns the same, immutable List every time it is called.- Returns:
- an immutable List of all Base instances this knows about from the start
-
scrambledBase
Returns a seemingly-gibberish Base that uses a radix of 72 and a randomly-ordered set of characters to represent the different digit values. This is randomized by a Random generator, so if the parameter is seeded identically (and is the same implementation), then an equivalent Base will be produced. This randomly chooses 72 digits from a large set,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?!@#$%^&*-|=+
, and sets the positive and negative signs to two different chars left over. The padding char is always space, ' '.- Parameters:
random
- a Random used to shuffle the possible digits- Returns:
- a new Base with 72 random digits, as well as a random positive and negative sign
-
scramble
Copies this Base and shuffles the digit values in the copy. Uses the given Random to perform the shuffle. This can be useful to lightly obfuscate save files, or better, parts of save files, so that certain fields appear to be one number but are actually a different one. If users don't know which entries use which scrambled Base, then that could be a nice way to at least slow down unskilled tampering.- Parameters:
random
- a Random used to shuffle the possible digits- Returns:
- a new Base that uses the same digits, but almost always with different values for those digits
-
serializeToString
Stores this Base as a compact String; the String this produces is usually given todeserializeFromString(String)
to restore the Base. Note that if you are usingscrambledBase(Random)
, you are also able to serialize the Random or its state, and that can be used to produce a scrambled base again; this could be useful to conceal a scrambled base slightly.- Returns:
- a String that can be given to
deserializeFromString(String)
to obtain this Base again
-
deserializeFromString
Given a String of a serialized Base (almost always produced byserializeToString()
), this re-creates that Base and returns it.- Parameters:
data
- a String that was almost always produced byserializeToString()
- Returns:
- the Base that
data
stores
-
unsigned
Converts the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any long- Returns:
- a new String containing
number
in the radix this specifies.
-
appendUnsigned
Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any long- Returns:
builder
, with the encodednumber
appended
-
signed
Converts the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any long- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any long- Returns:
builder
, with the encodednumber
appended
-
readLong
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(long)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the long that cs represents
-
readLong
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(long)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the long that cs represents
-
readLong
public long readLong(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the long they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(long)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the long that cs represents
-
unsigned
Converts the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any int- Returns:
- a new String containing
number
in the radix this specifies.
-
appendUnsigned
Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any int- Returns:
builder
, with the encodednumber
appended
-
signed
Converts the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any int- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any int- Returns:
builder
, with the encodednumber
appended
-
readInt
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(int)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the int that cs represents
-
readInt
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(int)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the int that cs represents
-
readInt
public int readInt(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the int they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(int)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the int that cs represents
-
unsigned
Converts the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any short- Returns:
- a new String containing
number
in the radix this specifies.
-
appendUnsigned
Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any short- Returns:
builder
, with the encodednumber
appended
-
signed
Converts the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any short- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any short- Returns:
builder
, with the encodednumber
appended
-
readShort
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(short)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFF" would return the short -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for shorts. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the short that cs represents
-
readShort
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(short)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFF" would return the short -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for shorts. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the short that cs represents
-
readShort
public short readShort(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the short they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(short)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FFFF" would return the short -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for shorts. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the short that cs represents
-
unsigned
Converts the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any byte- Returns:
- a new String containing
number
in the radix this specifies.
-
appendUnsigned
Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any byte- Returns:
builder
, with the encodednumber
appended
-
signed
Converts the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any byte- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any byte- Returns:
builder
, with the encodednumber
appended
-
readByte
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(byte)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FF" would return the byte -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for bytes. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the byte that cs represents
-
readByte
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(byte)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FF" would return the byte -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for bytes. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the byte that cs represents
-
readByte
public byte readByte(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the byte they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'unsigned(byte)
method; that is, if the first char of a max-length digit sequence is in the upper half of possible digits (such as 8 for hex digits or 4 for octal), then the whole number represents a negative number, using two's complement and so on. This means when using base-16, "FF" would return the byte -1 when passed to this, though you could also simply use "-1". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for bytes. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the byte that cs represents
-
unsigned
Converts the bits of the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any double- Returns:
- a new String containing the bits of
number
in the radix this specifies.
-
appendUnsigned
Converts the bits of the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any double- Returns:
builder
, with the bits ofnumber
appended in the radix this specifies
-
signed
Converts the bits of the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any double- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the bits of the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any double- Returns:
builder
, with the encodednumber
appended
-
readDouble
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(double)
,unsigned(double)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the double that cs represents
-
readDouble
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(double)
,unsigned(double)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the double that cs represents
-
readDouble
public double readDouble(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the double those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(double)
,unsigned(double)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the double that cs represents
-
unsigned
Converts the bits of the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any float- Returns:
- a new String containing the bits of
number
in the radix this specifies.
-
appendUnsigned
Converts the bits of the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any float- Returns:
builder
, with the bits ofnumber
appended in the radix this specifies
-
signed
Converts the bits of the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any float- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the bits of the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any float- Returns:
builder
, with the encodednumber
appended
-
readFloat
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(float)
,unsigned(float)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the float that cs represents
-
readFloat
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(float)
,unsigned(float)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the float that cs represents
-
readFloat
public float readFloat(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the float those bits represent, or 0.0 if nothing could be read. The leading sign can bepositiveSign
ornegativeSign
if present, and is almost always '+' or '-'. This is meant entirely for non-human-editable content, and the digit strings this can read will almost always be produced bysigned(float)
,unsigned(float)
, or their append versions.
This doesn't throw on invalid input, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the float that cs represents
-
unsigned
Converts the givennumber
to this Base as unsigned, returning a new String. This always uses the same number of chars in any String it returns, as long as the Base is the same.- Parameters:
number
- any char- Returns:
- a new String containing
number
in the radix this specifies.
-
appendUnsigned
Converts the givennumber
to this Base as unsigned, appending the result tobuilder
.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any char- Returns:
builder
, with the encodednumber
appended
-
signed
Converts the givennumber
to this Base as signed, returning a new String. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
number
- any char- Returns:
- a new String containing
number
in the radix this specifies.
-
appendSigned
Converts the givennumber
to this Base as signed, appending the result tobuilder
. This can vary in how many chars it uses, since it does not show leading zeroes and may use a-
sign.- Parameters:
builder
- a non-null StringBuilder that will be modified (appended to)number
- any char- Returns:
builder
, with the encodednumber
appended
-
readChar
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. Note that chars are unsigned 16-bit numbers by default, so even having a sign runs counter to the normal behavior;unsigned(char)
behaves as Java expects it, whilesigned(char)
is the anomaly. This means chars are always in the 0 to 65535 range, so if you give this a String representing a negative number, it treats it like a negative short and effectively casts it to char.
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for chars. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)- Returns:
- the char that cs represents
-
readChar
Reads in a CharSequence containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. Note that chars are unsigned 16-bit numbers by default, so even having a sign runs counter to the normal behavior;unsigned(char)
behaves as Java expects it, whilesigned(char)
is the anomaly. This means chars are always in the 0 to 65535 range, so if you give this a String representing a negative number, it treats it like a negative short and effectively casts it to char.
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for chars. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a CharSequence, such as a String, containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the char that cs represents
-
readChar
public char readChar(char[] cs, int start, int end) Reads in a char array containing only the digits present in this Base, with an optional sign at the start, and returns the char they represent, or 0 if nothing could be read. The leading sign can be thepositiveSign
ornegativeSign
if present; these are almost always '+' and '-'. Note that chars are unsigned 16-bit numbers by default, so even having a sign runs counter to the normal behavior;unsigned(char)
behaves as Java expects it, whilesigned(char)
is the anomaly. This means chars are always in the 0 to 65535 range, so if you give this a String representing a negative number, it treats it like a negative short and effectively casts it to char.
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which doesn't exist for chars. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a valid digit, or stopping the parse process early if an invalid digit is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs
- a char array containing only the digits in this Base and/or an optional initial sign (usually + or -)start
- the (inclusive) first character position in cs to readend
- the (exclusive) last character position in cs to read (this after reading enough chars to represent the largest possible value)- Returns:
- the char that cs represents
-
longSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a long array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a long array of the numbers found in source
-
longSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a long array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a long array of the numbers found in source
-
intSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as an int array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- an int array of the numbers found in source
-
intSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as an int array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- an int array of the numbers found in source
-
shortSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a short array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a short array of the numbers found in source
-
shortSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a short array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a short array of the numbers found in source
-
byteSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a byte array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a byte array of the numbers found in source
-
byteSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a byte array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a byte array of the numbers found in source
-
charSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a char array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a char array of the numbers found in source
-
charSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a char array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a char array of the numbers found in source
-
doubleSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a double array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a double array of the numbers found in source
-
doubleSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a double array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a double array of the numbers found in source
-
floatSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a float array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the sourcestartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a float array of the numbers found in source
-
floatSplit
Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a float array. If source or delimiter is null, or if source or delimiter is empty, this returns an empty array.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimiterdelimiter
- the String that separates numbers in the source- Returns:
- a float array of the numbers found in source
-
join
Given a long array and a delimiter to separate the items of that array, produces a String containing all longs from elements, in this Base, separated by delimiter.- Parameters:
delimiter
- the separator to put between numberselements
- a long array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a long array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all longs from elements, in this Base, separated by delimiter.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a long array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given an int array and a delimiter to separate the items of that array, produces a String containing all ints from elements, in this Base, separated by delimiter.- Parameters:
delimiter
- the separator to put between numberselements
- an int array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given an int array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all ints from elements, in this Base, separated by delimiter.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- an int array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given a short array and a delimiter to separate the items of that array, produces a String containing all shorts from elements, in this Base, separated by delimiter.- Parameters:
delimiter
- the separator to put between numberselements
- a short array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a short array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all shorts from elements, in this Base, separated by delimiter.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a short array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given a byte array and a delimiter to separate the items of that array, produces a String containing all bytes from elements, in this Base, separated by delimiter.- Parameters:
delimiter
- the separator to put between numberselements
- a byte array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a byte array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all bytes from elements, in this Base, separated by delimiter.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a byte array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given a char array and a delimiter to separate the items of that array, produces a String containing all chars (as numbers) from elements, in this Base, separated by delimiter.- Parameters:
delimiter
- the separator to put between numberselements
- a char array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a char array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all chars (as numbers) from elements, in this Base, separated by delimiter.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a char array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given a double array and a delimiter to separate the items of that array, produces a String containing all doubles from elements, in this Base, separated by delimiter. This usesappendSigned(StringBuilder, double)
, which means this does not produce human-readable numbers.- Parameters:
delimiter
- the separator to put between numberselements
- a double array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a double array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all doubles from elements, in this Base, separated by delimiter. This usesappendSigned(StringBuilder, double)
, which means this does not produce human-readable numbers.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a double array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
join
Given a float array and a delimiter to separate the items of that array, produces a String containing all floats from elements, in this Base, separated by delimiter. This usesappendSigned(StringBuilder, float)
, which means this does not produce human-readable numbers.- Parameters:
delimiter
- the separator to put between numberselements
- a float array; if null, this returns an empty String- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined
Given a float array, a delimiter to separate the items of that array, and a StringBuilder to append to, appends to the StringBuilder all floats from elements, in this Base, separated by delimiter. This usesappendSigned(StringBuilder, float)
, which means this does not produce human-readable numbers.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nulldelimiter
- the separator to put between numberselements
- a float array; if null, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by delimiter
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, long[][] elements) Given a long 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all longs from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a long 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, int[][] elements) Given an int 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all ints from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- an int 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, short[][] elements) Given a short 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all shorts from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a short 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, byte[][] elements) Given a byte 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all bytes from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a byte 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, char[][] elements) Given a char 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all chars from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a char 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, double[][] elements) Given a double 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all doubles from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a double 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
appendJoined2D
public StringBuilder appendJoined2D(StringBuilder sb, String majorDelimiter, String minorDelimiter, float[][] elements) Given a float 2D array, a major delimiter to separate the inner arrays, a minor delimiter to separate the items in each inner array, and a StringBuilder to append to, appends to the StringBuilder all floats from elements, in this Base, separated by minor delimiter and then by major delimiter. For any non-null, non-empty elements, this will append at least one major delimiter before it appends any items.- Parameters:
sb
- the StringBuilder to append to; if null, this returns nullmajorDelimiter
- the separator to put between arraysminorDelimiter
- the separator to put between numberselements
- a float 2D array; if null or empty, this returns sb without changes- Returns:
- a String containing all numbers in elements, written in this Base, separated by the delimiters
-
longSplit2D
public long[][] longSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D long array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, long[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D long array of the numbers found in source
-
longSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D long array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, long[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D long array of the numbers found in source
-
intSplit2D
public int[][] intSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D int array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, int[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D int array of the numbers found in source
-
intSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D int array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, int[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D int array of the numbers found in source
-
shortSplit2D
public short[][] shortSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D short array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, short[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D short array of the numbers found in source
-
shortSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D short array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, short[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D short array of the numbers found in source
-
byteSplit2D
public byte[][] byteSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D byte array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, byte[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D byte array of the numbers found in source
-
byteSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D byte array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, byte[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D byte array of the numbers found in source
-
charSplit2D
public char[][] charSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D char array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, char[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D char array of the numbers found in source
-
charSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D char array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, char[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D char array of the numbers found in source
-
doubleSplit2D
public double[][] doubleSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D double array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, double[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D double array of the numbers found in source
-
doubleSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D double array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, double[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D double array of the numbers found in source
-
floatSplit2D
public float[][] floatSplit2D(String source, String majorDelimiter, String minorDelimiter, int startIndex, int endIndex) Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D float array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, float[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbersstartIndex
- the first index, inclusive, in source to split fromendIndex
- the last index, exclusive, in source to split from- Returns:
- a 2D float array of the numbers found in source
-
floatSplit2D
Given a String containing sequences of numbers in this Base, with the sequences separated by instances of majorDelimiter and the numbers within a sequence separated by minorDelimiter returns those numbers as a 2D float array. This is specifically meant to read the format produced byappendJoined(StringBuilder, String, float[])
, including the initial majorDelimiter before each sequence.- Parameters:
source
- a String of numbers in this base, separated by a delimiter, with no trailing delimitermajorDelimiter
- the separator between sequencesminorDelimiter
- the separator between numbers- Returns:
- a 2D float array of the numbers found in source
-
count
Scans repeatedly insource
(only using the area from startIndex, inclusive, to endIndex, exclusive) for the Stringsearch
, not scanning the same char twice except as part of a larger String, and returns the number of instances of search that were found, or 0 if source or search is null or if the searched area is empty. If endIndex is negative, this will search from startIndex until the end of the source.
This really belongs in a different class with String operations, but it's the only method of its type we're using here, so it can be in Base.- Parameters:
source
- a String to look throughsearch
- a String to look forstartIndex
- the first index to search through, inclusiveendIndex
- the last index to search through, exclusive; if negative this will search the rest of source- Returns:
- the number of times search was found in source
-
equals
-
hashCode
public int hashCode()
-