Class Base

java.lang.Object
com.github.tommyettinger.digital.Base

public class Base extends Object
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 (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).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    What base or radix this uses; if you use unsigned(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 with signed(int) and when reading them back with readInt(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

    Constructors
    Constructor
    Description
    Base(Base other)
    An unlikely-to-be-used copy constructor.
    Base(String digits)
    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 '-'.
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    appendJoined(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 given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, char number)
    Converts the given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, double number)
    Converts the bits of the given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, float number)
    Converts the bits of the given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, int number)
    Converts the given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, long number)
    Converts the given number to this Base as signed, appending the result to builder.
    appendSigned(StringBuilder builder, short number)
    Converts the given number to this Base as signed, appending the result to builder.
    appendUnsigned(StringBuilder builder, byte number)
    Converts the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, char number)
    Converts the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, double number)
    Converts the bits of the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, float number)
    Converts the bits of the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, int number)
    Converts the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, long number)
    Converts the given number to this Base as unsigned, appending the result to builder.
    appendUnsigned(StringBuilder builder, short number)
    Converts the given number to this Base as unsigned, appending the result to builder.
    byte[]
    byteSplit(String source, String delimiter)
    Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a byte array.
    byte[]
    byteSplit(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 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[]
    charSplit(String source, String delimiter)
    Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a char array.
    char[]
    charSplit(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 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
    count(String source, String search, int startIndex, int endIndex)
    Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the String search, 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
    Given a String of a serialized Base (almost always produced by serializeToString()), 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
     
    int[]
    intSplit(String source, String delimiter)
    Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as an int array.
    int[]
    intSplit(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 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.
    join(String delimiter, byte[] elements)
    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.
    join(String delimiter, char[] elements)
    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.
    join(String delimiter, double[] elements)
    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.
    join(String delimiter, float[] elements)
    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.
    join(String delimiter, int[] elements)
    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.
    join(String delimiter, long[] elements)
    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.
    join(String delimiter, short[] elements)
    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[]
    longSplit(String source, String delimiter)
    Given a String containing numbers in this Base, separated by instances of delimiter, returns those numbers as a long array.
    long[]
    longSplit(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 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
    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
    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
    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
    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.
    scramble(Random random)
    Copies this Base and shuffles the digit values in the copy.
    static Base
    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 to deserializeFromString(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 given number to this Base as signed, returning a new String.
    signed(char number)
    Converts the given number to this Base as signed, returning a new String.
    signed(double number)
    Converts the bits of the given number to this Base as signed, returning a new String.
    signed(float number)
    Converts the bits of the given number to this Base as signed, returning a new String.
    signed(int number)
    Converts the given number to this Base as signed, returning a new String.
    signed(long number)
    Converts the given number to this Base as signed, returning a new String.
    signed(short number)
    Converts the given number to this Base as signed, returning a new String.
    unsigned(byte number)
    Converts the given number to this Base as unsigned, returning a new String.
    unsigned(char number)
    Converts the given number to this Base as unsigned, returning a new String.
    unsigned(double number)
    Converts the bits of the given number to this Base as unsigned, returning a new String.
    unsigned(float number)
    Converts the bits of the given number to this Base as unsigned, returning a new String.
    unsigned(int number)
    Converts the given number to this Base as unsigned, returning a new String.
    unsigned(long number)
    Converts the given number to this Base as unsigned, returning a new String.
    unsigned(short number)
    Converts the given number to this Base as unsigned, returning a new String.
    static List<Base>
    Returns an immutable List of the Base instances this knows about from the start.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BASE2

      public static final Base BASE2
      Binary, using the digits 0 and 1.
    • BASE8

      public static final Base BASE8
      Octal, using the digits 0-7.
    • BASE10

      public static final Base BASE10
      Decimal, using the digits 0-9.
    • BASE16

      public static final Base BASE16
      Hexadecimal, using the digits 0-9 and then A-F (case-insensitive).
    • BASE36

      public static final Base BASE36
      Hexatrigesimal, using the digits 0-9 and then A-Z (case-insensitive).
    • BASE64

      public static final Base 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

      public static final Base 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

      public static final Base 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

      public static final Base 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, only BASE64 requires sometimes.
    • toEncoded

      public final char[] toEncoded
      The 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[] fromEncoded
      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.
      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 with toEncoded as part of creating a different Base, but if you are doing that to obfuscate output, you can use scrambledBase(Random) instead.
    • paddingChar

      public final char paddingChar
      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. It defaults to the space char, ' ', if not specified.
    • positiveSign

      public final char positiveSign
      Can be used to indicate positive numbers; like + in most numeral systems, this is usually ignored.
    • negativeSign

      public final char negativeSign
      Used to indicate negative numbers with signed(int) and when reading them back with readInt(CharSequence); like - in most numeral systems.
    • caseInsensitive

      public final boolean caseInsensitive
      Will be true if this base system treats upper- and lower-case letters present in the encoding as the same.
    • base

      public final int base
      What base or radix this uses; if you use unsigned(int), then base must be an even number.
  • Constructor Details

    • Base

      public Base(String digits)
      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 parameters
      caseInsensitive - if true, digits will be converted to upper-case before any operations on them.
      padding - only used to guarantee a separator is possible between numbers
      positiveSign - typically '+'
      negativeSign - typically '-'
    • Base

      public Base(Base other)
      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 of fromEncoded and toEncoded, since those can be edited, but other fields are generally final here.
      Parameters:
      other - another Base; must be non-null
  • Method Details

    • values

      public static List<Base> 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

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

      public Base scramble(Random random)
      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

      public String serializeToString()
      Stores this Base as a compact String; the String this produces is usually given to deserializeFromString(String) to restore the Base. Note that if you are using scrambledBase(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

      public static Base deserializeFromString(String data)
      Given a String of a serialized Base (almost always produced by serializeToString()), this re-creates that Base and returns it.
      Parameters:
      data - a String that was almost always produced by serializeToString()
      Returns:
      the Base that data stores
    • unsigned

      public String unsigned(long number)
      Converts the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, long number)
      Converts the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any long
      Returns:
      builder, with the encoded number appended
    • signed

      public String signed(long number)
      Converts the given number 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

      public StringBuilder appendSigned(StringBuilder builder, long number)
      Converts the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readLong

      public 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. The leading sign can be the positiveSign or negativeSign 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

      public 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. The leading sign can be the positiveSign or negativeSign 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 read
      end - 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 the positiveSign or negativeSign 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 read
      end - 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

      public String unsigned(int number)
      Converts the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, int number)
      Converts the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any int
      Returns:
      builder, with the encoded number appended
    • signed

      public String signed(int number)
      Converts the given number 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

      public StringBuilder appendSigned(StringBuilder builder, int number)
      Converts the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readInt

      public 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. The leading sign can be the positiveSign or negativeSign 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

      public 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. The leading sign can be the positiveSign or negativeSign 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 read
      end - 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 the positiveSign or negativeSign 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 read
      end - 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

      public String unsigned(short number)
      Converts the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, short number)
      Converts the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any short
      Returns:
      builder, with the encoded number appended
    • signed

      public String signed(short number)
      Converts the given number 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

      public StringBuilder appendSigned(StringBuilder builder, short number)
      Converts the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readShort

      public short readShort(CharSequence cs)
      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 the positiveSign or negativeSign 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

      public 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. The leading sign can be the positiveSign or negativeSign 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 read
      end - 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 the positiveSign or negativeSign 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 read
      end - 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

      public String unsigned(byte number)
      Converts the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, byte number)
      Converts the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any byte
      Returns:
      builder, with the encoded number appended
    • signed

      public String signed(byte number)
      Converts the given number 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

      public StringBuilder appendSigned(StringBuilder builder, byte number)
      Converts the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readByte

      public 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. The leading sign can be the positiveSign or negativeSign 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

      public 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. The leading sign can be the positiveSign or negativeSign 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 read
      end - 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 the positiveSign or negativeSign 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 read
      end - 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

      public String unsigned(double number)
      Converts the bits of the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, double number)
      Converts the bits of the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any double
      Returns:
      builder, with the bits of number appended in the radix this specifies
    • signed

      public String signed(double number)
      Converts the bits of the given number 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

      public StringBuilder appendSigned(StringBuilder builder, double number)
      Converts the bits of the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readDouble

      public double readDouble(CharSequence cs)
      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 be positiveSign or negativeSign 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 by signed(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

      public 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. The leading sign can be positiveSign or negativeSign 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 by signed(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 read
      end - 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 be positiveSign or negativeSign 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 by signed(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 read
      end - 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

      public String unsigned(float number)
      Converts the bits of the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, float number)
      Converts the bits of the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any float
      Returns:
      builder, with the bits of number appended in the radix this specifies
    • signed

      public String signed(float number)
      Converts the bits of the given number 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

      public StringBuilder appendSigned(StringBuilder builder, float number)
      Converts the bits of the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readFloat

      public float readFloat(CharSequence cs)
      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 be positiveSign or negativeSign 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 by signed(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

      public 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. The leading sign can be positiveSign or negativeSign 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 by signed(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 read
      end - 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 be positiveSign or negativeSign 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 by signed(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 read
      end - 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

      public String unsigned(char number)
      Converts the given number 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

      public StringBuilder appendUnsigned(StringBuilder builder, char number)
      Converts the given number to this Base as unsigned, appending the result to builder.
      Parameters:
      builder - a non-null StringBuilder that will be modified (appended to)
      number - any char
      Returns:
      builder, with the encoded number appended
    • signed

      public String signed(char number)
      Converts the given number 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

      public StringBuilder appendSigned(StringBuilder builder, char number)
      Converts the given number to this Base as signed, appending the result to builder. 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 encoded number appended
    • readChar

      public 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. The leading sign can be the positiveSign or negativeSign 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, while signed(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

      public 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. The leading sign can be the positiveSign or negativeSign 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, while signed(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 read
      end - 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 the positiveSign or negativeSign 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, while signed(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 read
      end - 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

      public long[] longSplit(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 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a long array of the numbers found in source
    • longSplit

      public long[] longSplit(String source, String delimiter)
      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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a long array of the numbers found in source
    • intSplit

      public int[] intSplit(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 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      an int array of the numbers found in source
    • intSplit

      public int[] intSplit(String source, String delimiter)
      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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      an int array of the numbers found in source
    • shortSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a short array of the numbers found in source
    • shortSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a short array of the numbers found in source
    • byteSplit

      public byte[] byteSplit(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 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a byte array of the numbers found in source
    • byteSplit

      public byte[] byteSplit(String source, String delimiter)
      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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a byte array of the numbers found in source
    • charSplit

      public char[] charSplit(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 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a char array of the numbers found in source
    • charSplit

      public char[] charSplit(String source, String delimiter)
      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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a char array of the numbers found in source
    • doubleSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a double array of the numbers found in source
    • doubleSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a double array of the numbers found in source
    • floatSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a float array of the numbers found in source
    • floatSplit

      public 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. 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 delimiter
      delimiter - the String that separates numbers in the source
      Returns:
      a float array of the numbers found in source
    • join

      public String join(String delimiter, long[] elements)
      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 numbers
      elements - 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

      public StringBuilder 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.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, int[] elements)
      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 numbers
      elements - 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

      public StringBuilder 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.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, short[] elements)
      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 numbers
      elements - 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

      public StringBuilder 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.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, byte[] elements)
      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 numbers
      elements - 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

      public StringBuilder appendJoined(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.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, char[] elements)
      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 numbers
      elements - 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

      public StringBuilder 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.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, double[] elements)
      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 uses appendSigned(StringBuilder, double), which means this does not produce human-readable numbers.
      Parameters:
      delimiter - the separator to put between numbers
      elements - 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

      public StringBuilder 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. This uses appendSigned(StringBuilder, double), which means this does not produce human-readable numbers.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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

      public String join(String delimiter, float[] elements)
      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 uses appendSigned(StringBuilder, float), which means this does not produce human-readable numbers.
      Parameters:
      delimiter - the separator to put between numbers
      elements - 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

      public StringBuilder 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. This uses appendSigned(StringBuilder, float), which means this does not produce human-readable numbers.
      Parameters:
      sb - the StringBuilder to append to; if null, this returns null
      delimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 null
      majorDelimiter - the separator to put between arrays
      minorDelimiter - the separator to put between numbers
      elements - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D long array of the numbers found in source
    • longSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D int array of the numbers found in source
    • intSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D short array of the numbers found in source
    • shortSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D byte array of the numbers found in source
    • byteSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D char array of the numbers found in source
    • charSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D double array of the numbers found in source
    • doubleSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - 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 by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      startIndex - the first index, inclusive, in source to split from
      endIndex - the last index, exclusive, in source to split from
      Returns:
      a 2D float array of the numbers found in source
    • floatSplit2D

      public 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. This is specifically meant to read the format produced by appendJoined(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 delimiter
      majorDelimiter - the separator between sequences
      minorDelimiter - the separator between numbers
      Returns:
      a 2D float array of the numbers found in source
    • count

      protected static int count(String source, String search, int startIndex, int endIndex)
      Scans repeatedly in source (only using the area from startIndex, inclusive, to endIndex, exclusive) for the String search, 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 through
      search - a String to look for
      startIndex - the first index to search through, inclusive
      endIndex - 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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object