Package adams.core

Class Utils


  • public class Utils
    extends Object
    Class implementing some simple utility methods.
    Author:
    Eibe Frank, Yong Wang, Len Trigg, Julien Prados, FracPete (fracpete at waikat dot ac dot nz), Herong Yang
    See Also:
    Utils
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • doubleToStringFixed

        public static String doubleToStringFixed​(double value,
                                                 int afterDecimalPoint)
        Rounds a double and converts it into String. Always displays the specified number of decimals. Uses the default locale.
        Parameters:
        value - the double value
        afterDecimalPoint - the number of digits permitted after the decimal point; if -1 then all decimals are displayed; also if number > Long.MAX_VALUE
        Returns:
        the double as a formatted string
      • doubleToStringFixed

        public static String doubleToStringFixed​(double value,
                                                 int afterDecimalPoint,
                                                 Locale locale)
        Rounds a double and converts it into String. Always displays the specified number of decimals.
        Parameters:
        value - the double value
        afterDecimalPoint - the number of digits permitted after the decimal point; if -1 then all decimals are displayed; also if number > Long.MAX_VALUE
        locale - the locale to use
        Returns:
        the double as a formatted string
      • doubleToString

        public static String doubleToString​(double value,
                                            int afterDecimalPoint)
        Rounds a double and converts it into String. Uses the default locale.
        Parameters:
        value - the double value
        afterDecimalPoint - the (maximum) number of digits permitted after the decimal point
        Returns:
        the double as a formatted string
      • doubleToString

        public static String doubleToString​(double value,
                                            int afterDecimalPoint,
                                            Locale locale)
        Rounds a double and converts it into String.
        Parameters:
        value - the double value
        afterDecimalPoint - the (maximum) number of digits permitted after the decimal point
        locale - the locale to use
        Returns:
        the double as a formatted string
      • doubleToString

        public static String doubleToString​(double value,
                                            int width,
                                            int afterDecimalPoint)
        Rounds a double and converts it into a formatted decimal-justified String. Trailing 0's are replaced with spaces. Uses the default locale.
        Parameters:
        value - the double value
        width - the width of the string
        afterDecimalPoint - the number of digits after the decimal point
        Returns:
        the double as a formatted string
      • doubleToString

        public static String doubleToString​(double value,
                                            int width,
                                            int afterDecimalPoint,
                                            Locale locale)
        Rounds a double and converts it into a formatted decimal-justified String. Trailing 0's are replaced with spaces.
        Parameters:
        value - the double value
        width - the width of the string
        afterDecimalPoint - the number of digits after the decimal point
        locale - the locale to use
        Returns:
        the double as a formatted string
      • getArrayClass

        public static Class getArrayClass​(Class c)
        Returns the basic class of an array class (handles multi-dimensional arrays).
        Parameters:
        c - the array to inspect
        Returns:
        the class of the innermost elements
      • getArrayDimensions

        public static int getArrayDimensions​(Class array)
        Returns the dimensions of the given array. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].
        Parameters:
        array - the array to determine the dimensions for
        Returns:
        the dimensions of the array
      • getArrayDimensions

        public static int getArrayDimensions​(Object array)
        Returns the dimensions of the given array. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].
        Parameters:
        array - the array to determine the dimensions for
        Returns:
        the dimensions of the array
      • arrayToString

        public static String arrayToString​(Object array,
                                           boolean outputClass)
        Returns the given Array in a string representation. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].
        Parameters:
        array - the array to return in a string representation
        outputClass - whether to output the class name instead of calling the object's "toString()" method
        Returns:
        the array as string
      • arrayToString

        public static String arrayToString​(Object array)
        Returns the given Array in a string representation. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].
        Parameters:
        array - the array to return in a string representation
        Returns:
        the array as string
      • backQuoteChars

        public static String backQuoteChars​(String string,
                                            char[] find,
                                            String[] replace)
        Converts specified characters into the string equivalents.
        Parameters:
        string - the string
        find - the characters to replace
        replace - the replacement strings for the characters
        Returns:
        the converted string
        See Also:
        unbackQuoteChars(String, String[], char[])
      • backQuoteChars

        public static String backQuoteChars​(String string)
        Converts carriage returns and new lines in a string into \r and \n. Backquotes the following characters: ` " \ \t and %
        Parameters:
        string - the string
        Returns:
        the converted string
        See Also:
        unbackQuoteChars(String)
      • unbackQuoteChars

        public static String unbackQuoteChars​(String string,
                                              String[] find,
                                              char[] replace)
        The inverse operation of backQuoteChars(). Converts the specified strings into their character representations.
        Parameters:
        string - the string
        find - the string to find
        replace - the character equivalents of the strings
        Returns:
        the converted string
        See Also:
        backQuoteChars(String, char[], String[])
      • unbackQuoteChars

        public static String unbackQuoteChars​(String string)
        The inverse operation of backQuoteChars(). Converts back-quoted carriage returns and new lines in a string to the corresponding character ('\r' and '\n'). Also "un"-back-quotes the following characters: ` " \ \t and %
        Parameters:
        string - the string
        Returns:
        the converted string
        See Also:
        backQuoteChars(String)
      • doubleQuote

        public static String doubleQuote​(String string)
        Quotes a string if it contains special characters. The following rules are applied: A character is backquoted version of it is one of " ' % \ \n \r \t. A string is enclosed within double quotes if a character has been backquoted using the previous rule above or contains { } or is exactly equal to the strings , ? space or "" (empty string). A quoted question mark distinguishes it from the missing value which is represented as an unquoted question mark in arff files.
        Parameters:
        string - the string to be quoted
        Returns:
        the string (possibly quoted)
        See Also:
        unDoubleQuote(String)
      • quote

        public static String quote​(String string)
        Quotes a string if it contains special characters. The following rules are applied: A character is backquoted version of it is one of " ' % \ \n \r \t. A string is enclosed within single quotes if a character has been backquoted using the previous rule above or contains { } or is exactly equal to the strings , ? space or "" (empty string). A quoted question mark distinguishes it from the missing value which is represented as an unquoted question mark in arff files.
        Parameters:
        string - the string to be quoted
        Returns:
        the string (possibly quoted)
        See Also:
        unquote(String)
      • quote

        public static String quote​(String string,
                                   String quoteChar)
        Quotes a string if it contains special characters. The following rules are applied: A character is backquoted version of it is one of " ' % \ \n \r \t. A string is enclosed within the quote character if a character has been backquoted using the previous rule above or contains { } or is exactly equal to the strings , ? space or "" (empty string). A quoted question mark distinguishes it from the missing value which is represented as an unquoted question mark in arff files.
        Parameters:
        string - the string to be quoted
        quoteChar - the quote character to use
        Returns:
        the string (possibly quoted)
        See Also:
        unquote(String,String)
      • unDoubleQuote

        public static String unDoubleQuote​(String string)
        unquotes are previously quoted string (but only if necessary), i.e., it removes the double quotes around it. Inverse to doubleQuote(String).
        Parameters:
        string - the string to process
        Returns:
        the unquoted string
        See Also:
        doubleQuote(String)
      • unquote

        public static String unquote​(String string)
        unquotes are previously quoted string (but only if necessary), i.e., it removes the single quotes around it. Inverse to quote(String).
        Parameters:
        string - the string to process
        Returns:
        the unquoted string
        See Also:
        quote(String)
      • unquote

        public static String unquote​(String string,
                                     String quoteChar)
        unquotes are previously quoted string (but only if necessary), i.e., it removes the quote characters around it. Inverse to quote(String,String).
        Parameters:
        string - the string to process
        quoteChar - the quote character to use
        Returns:
        the unquoted string
        See Also:
        quote(String,String)
      • doubleUpQuotes

        public static String doubleUpQuotes​(String s,
                                            char quote,
                                            char[] chars,
                                            String[] strings)
        Surrounds the strings with the specified quotes. If the quote character is part of the string itself, it gets doubled up. Tab characters get escaped as well.
        Parameters:
        s - the string to quote
        quote - the quote character, e.g., ' or "
        Returns:
        the quoted character
      • unDoubleUpQuotes

        public static String unDoubleUpQuotes​(String s,
                                              char quote,
                                              String[] strings,
                                              char[] chars)
        Surrounds the strings with the specified quotes. If the quote character is part of the string itself, it gets doubled up. Tab characters get escaped as well.
        Parameters:
        s - the string to quote
        quote - the quote character, e.g., ' or "
        Returns:
        the quoted character
      • breakUp

        public static String[] breakUp​(String s,
                                       int columns)
        Breaks up the string, if wider than "columns" characters.
        Parameters:
        s - the string to process
        columns - the width in columns
        Returns:
        the processed string
      • insertLineBreaks

        public static String insertLineBreaks​(String s,
                                              int columns)
        Inserts line breaks into the string, if wider than "columns" characters.
        Parameters:
        s - the string to process
        columns - the width in columns
        Returns:
        the processed string
      • commentOut

        public static String commentOut​(String s,
                                        String comment)
        Inserts comment characters at the start of each line.
        Parameters:
        s - the string to process
        comment - the comment string
        Returns:
        the processed string
      • indent

        public static String indent​(String s,
                                    int numBlanks)
        Inserts blanks at the start of each line.
        Parameters:
        s - the string to process
        numBlanks - the number of blanks to insert
        Returns:
        the processed string
      • indent

        public static String indent​(String s,
                                    String indentStr)
        Indents each line with the specified string.
        Parameters:
        s - the string to process
        indentStr - the string to use for indentation
        Returns:
        the processed string
      • unComment

        public static String unComment​(String s,
                                       String comment)
        Removes the comment characters from the start of each line.
        Parameters:
        s - the string to process
        comment - the comment string
        Returns:
        the processed string
      • flatten

        public static String flatten​(List lines,
                                     String sep)
        Flattens the list into a single, long string. The separator string gets added between the objects, but not after the last one.
        Parameters:
        lines - the lines to flatten
        sep - the separator
        Returns:
        the generated string
      • flatten

        public static String flatten​(Object[] lines,
                                     String sep)
        Flattens the array into a single, long string. The separator string gets added between the objects, but not after the last one. Uses the "toString()" method of the objects to turn them into a string.
        Parameters:
        lines - the lines to flatten
        sep - the separator
        Returns:
        the generated string
      • removeEmptyLines

        public static void removeEmptyLines​(List<String> lines)
        Removes empty lines from the vector. Performs trimming before ascertaining whether the line is empty.
        Parameters:
        lines - the list to clean up
      • removeEmptyLines

        public static void removeEmptyLines​(List<String> lines,
                                            boolean trim)
        Removes empty lines from the vector.
        Parameters:
        lines - the list to clean up
        trim - whether to trim the line first before checking whether it is empty or not
      • removeComments

        public static void removeComments​(List<String> lines,
                                          String comment)
        Removes comment lines from the vector.
        Parameters:
        lines - the list to clean up
        comment - the start of a comment
      • adjustArray

        public static Object adjustArray​(Object array,
                                         int newLen,
                                         Object defValue)
        Creates a new array of the specified length and fills it with the values of the old array before returning it.
        Parameters:
        array - the array to adjust
        newLen - the new length
        defValue - the default value to fill the new array with
        Returns:
        the fixed array
      • stringToClass

        public static Class stringToClass​(String classname)
        Turns a class name into a Class instance. Arrays are indicated by "[]" at the end of the name. Multiple array indicators can be used.
        Parameters:
        classname - the class name to return the Class instance for
        Returns:
        the generated class instance, null if failed to create
      • newArray

        public static Object newArray​(String elementClass,
                                      int length)
        Creates a new array of the specified element type with the specified number of elements. Arrays are indicated by "[]" at the end of the clas name. Multiple array indicators can be used. E.g., newArray("java.lang.Double[]", 5) will generate "Double[5][]".
        Parameters:
        elementClass - the class type for the array elements
        Returns:
        the generated array instance, null if failed to create
      • classToString

        public static String classToString​(Object o)
        Turns the class of the object into a string.
        Parameters:
        o - the object to turn into a class string
        Returns:
        the string
      • classToString

        public static String classToString​(Class c)
        Turns a class into a string.
        Parameters:
        c - the class to turn into a string
        Returns:
        the string
      • classesToString

        public static String classesToString​(Class[] c)
        Turns a class array into a string.
        Parameters:
        c - the class array to turn into a string
        Returns:
        the string
      • classesToString

        public static String classesToString​(Object[] o)
        Turns the classes of an array into a string.
        Parameters:
        o - the object array to turn into a string
        Returns:
        the string
      • classesToString

        public static String classesToString​(Object[] o,
                                             String separator)
        Turns the classes of an array into a string.
        Parameters:
        o - the object array to turn into a string
        separator - the separator between the classes
        Returns:
        the string
      • classesToString

        public static String classesToString​(Class[] c,
                                             String separator)
        Turns a class array into a string.
        Parameters:
        c - the class array to turn into a string
        separator - the separator between the classes
        Returns:
        the string
      • toFloat

        public static float[] toFloat​(double[] array)
        Turns the double array into a float array.
        Parameters:
        array - the array to convert
        Returns:
        the converted array
      • toDouble

        public static double[] toDouble​(float[] array)
        Turns the float array into a double array.
        Parameters:
        array - the array to convert
        Returns:
        the converted array
      • padLeft

        public static String padLeft​(String s,
                                     char padding,
                                     int width)
        Pads the string with a padding character with to at most "width" width. Does not truncate the string.
        Parameters:
        s - the string to pad
        padding - the padding character
        width - the maximum width
        Returns:
        the padded string
      • padLeft

        public static String padLeft​(String s,
                                     char padding,
                                     int width,
                                     boolean truncate)
        Pads the string with a padding character with to at most "width" width. Truncating, if string is longer than "width", is optional.
        Parameters:
        s - the string to pad
        padding - the padding character
        width - the maximum width
        truncate - if true then the string can be truncated (on the left) to fit width
        Returns:
        the padded string
      • padRight

        public static String padRight​(String s,
                                      char padding,
                                      int width)
        Pads the string with a padding character with to at most "width" width. Does not truncate the string.
        Parameters:
        s - the string to pad
        padding - the padding character
        width - the maximum width
        Returns:
        the padded string
      • padRight

        public static String padRight​(String s,
                                      char padding,
                                      int width,
                                      boolean truncate)
        Pads the string with a padding character with to at most "width" width. Truncating, if string is longer than "width", is optional.
        Parameters:
        s - the string to pad
        padding - the padding character
        width - the maximum width
        truncate - if true then the string can be truncated (on the left) to fit width
        Returns:
        the padded string
      • toBase

        public static List<Integer> toBase​(int n,
                                           int base)
        Converts the given decimal number into a different base.
        Parameters:
        n - the decimal number to convert
        base - the base
        Returns:
        the digits in the new base; index refers to power, ie, 0 = base^0, 3 = base^3
      • toHex

        public static String toHex​(byte value)
        Returns a hexadecimal representation of the byte value.

        Taken from here.
        Parameters:
        value - the value to convert
        Returns:
        the hexadecimal representation
      • fromHex

        public static byte fromHex​(String s)
        Parses the hex string (00 - FF) and returns the byte.
        Parameters:
        s - the string to parse
        Returns:
        the byte value
      • toHexArray

        public static String toHexArray​(byte[] binary)
        Turns the binary array to a hexadecimal string.
        Parameters:
        binary - the array to convert
        Returns:
        the hex string
      • fromHexArray

        public static byte[] fromHexArray​(String hex)
        Turns the hex string (even number of chars) into an array of bytes.
        Parameters:
        hex - the string to convert
        Returns:
        the extracted bytes
      • isBoolean

        public static boolean isBoolean​(String s)
        Tries to parse the given string as boolean (true|false - any case).
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid boolean
      • isByte

        public static boolean isByte​(String s)
        Tries to parse the given string as byte.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid byte
      • isShort

        public static boolean isShort​(String s)
        Tries to parse the given string as short.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid short
      • isInteger

        public static boolean isInteger​(String s)
        Tries to parse the given string as integer.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid integer
      • isLong

        public static boolean isLong​(String s)
        Tries to parse the given string as long.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid long
      • isFloat

        public static boolean isFloat​(String s)
        Tries to parse the given string as float. Fails if number is too large/small to be represented by a float (ie infinity, but the string does not contain infinity itself). Uses the default locale.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid float
      • isFloat

        public static boolean isFloat​(String s,
                                      Locale locale)
        Tries to parse the given string as float. Fails if number is too large/small to be represented by a float (ie infinity, but the string does not contain infinity itself).
        Parameters:
        s - the string to check
        locale - the locale to use
        Returns:
        true if it represents a valid float
      • toFloat

        public static Float toFloat​(String s)
        Tries to parse the given string as float. Uses the default locale.
        Parameters:
        s - the string to parse
        Returns:
        the float or null if failed to parse
      • toFloat

        public static Float toFloat​(String s,
                                    Locale locale)
        Tries to parse the given string as float.
        Parameters:
        s - the string to parse
        locale - the locale to use
        Returns:
        the float or null if failed to parse
      • isDouble

        public static boolean isDouble​(String s)
        Tries to parse the given string as double. Fails if number is too large/small to be represented by a double (ie infinity, but the string does not contain infinity itself). Uses the default locale.
        Parameters:
        s - the string to check
        Returns:
        true if it represents a valid double
      • isDouble

        public static boolean isDouble​(String s,
                                       Locale locale)
        Tries to parse the given string as double. Fails if number is too large/small to be represented by a double (ie infinity, but the string does not contain infinity itself).
        Parameters:
        s - the string to check
        locale - the locale to use
        Returns:
        true if it represents a valid double
      • toDouble

        public static Double toDouble​(String s)
        Tries to parse the given string as double. Uses the default locale.
        Parameters:
        s - the string to parse
        Returns:
        the double or null if failed to parse
      • toDouble

        public static Double toDouble​(String s,
                                      Locale locale)
        Tries to parse the given string as double.
        Parameters:
        s - the string to parse
        locale - the locale to use
        Returns:
        the double or null if failed to parse
      • split

        public static String[] split​(String line,
                                     char delimiter)
        Splits the row into separate cells based on the delimiter character. String.split(regexp) does not work with empty cells (eg ",,,").
        Parameters:
        line - the row to split
        delimiter - the delimiter to use
        Returns:
        the cells
      • split

        public static String[] split​(String line,
                                     String delimiter)
        Splits the row into separate cells based on the delimiter string. String.split(regexp) does not work with empty cells (eg ",,,").
        Parameters:
        line - the row to split
        delimiter - the delimiter to use
        Returns:
        the cells
      • swap

        public static void swap​(int[] array)
        Swaps the two integers in the array.
        Parameters:
        array - the array with two elements to swap
      • swap

        public static void swap​(long[] array)
        Swaps the two longs in the array.
        Parameters:
        array - the array with two elements to swap
      • swap

        public static void swap​(float[] array)
        Swaps the two floats in the array.
        Parameters:
        array - the array with two elements to swap
      • swap

        public static void swap​(double[] array)
        Swaps the two doubles in the array.
        Parameters:
        array - the array with two elements to swap
      • swap

        public static void swap​(Object[] array)
        Swaps the two objects in the array.
        Parameters:
        array - the array with two elements to swap
      • toList

        public static List<Byte> toList​(byte[] array)
        Turns the byte array into a Byte list.
        Parameters:
        array - the array to convert
        Returns:
        the generated list
      • toByteArray

        public static byte[] toByteArray​(List<Byte> list)
        Turns the Byte list into a byte array.
        Parameters:
        list - the list to convert
        Returns:
        the generated array
      • toList

        public static List<Integer> toList​(int[] array)
        Turns the int array into an Integer list.
        Parameters:
        array - the array to convert
        Returns:
        the generated list
      • toIntArray

        public static int[] toIntArray​(List<Integer> list)
        Turns the Integer list into an int array.
        Parameters:
        list - the list to convert
        Returns:
        the generated array
      • toList

        public static List<Long> toList​(long[] array)
        Turns the long array into a Long list.
        Parameters:
        array - the array to convert
        Returns:
        the generated list
      • toLongArray

        public static long[] toLongArray​(List<Long> list)
        Turns the Long list into a long array.
        Parameters:
        list - the list to convert
        Returns:
        the generated array
      • toList

        public static List<Double> toList​(double[] array)
        Turns the double array into a Double list.
        Parameters:
        array - the array to convert
        Returns:
        the generated list
      • toDoubleArray

        public static double[] toDoubleArray​(List<Double> list)
        Turns the Double list into a double array.
        Parameters:
        list - the list to convert
        Returns:
        the generated array
      • toList

        public static List<Float> toList​(float[] array)
        Turns the float array into a Float list.
        Parameters:
        array - the array to convert
        Returns:
        the generated list
      • toFloatArray

        public static float[] toFloatArray​(List<Float> list)
        Turns the Float list into a float array.
        Parameters:
        list - the list to convert
        Returns:
        the generated array
      • wait

        public static void wait​(LoggingSupporter obj,
                                int msec,
                                int interval)
        A simple waiting method.
        Parameters:
        obj - the object to use for logging and synchronizing
        msec - the maximum number of milli-seconds to wait, no waiting if 0
        interval - the amount msecs to wait before checking state (interval < msec)
      • wait

        public static void wait​(LoggingSupporter obj,
                                StoppableWithFeedback stoppable,
                                int msec,
                                int interval)
        A simple waiting method.
        Parameters:
        obj - the object to use for logging and synchronizing
        stoppable - the object to use for checking stoppped state
        msec - the maximum number of milli-seconds to wait, no waiting if 0
        interval - the amount msecs to wait before checking state (interval < msec)
      • isPrimitive

        public static boolean isPrimitive​(Class cls)
        Checks whether the class is a wrapper for a primitive.
        Parameters:
        cls - the class to test
        Returns:
        true if primitve
      • getWrapperClass

        public static Class getWrapperClass​(Class cls)
        Returns the corresponding BaseObject-derived wrapper class.
        Parameters:
        cls - the primitive class to wrap
        Returns:
        the wrapper class, null if not available
      • getPrimitiveClass

        public static Class getPrimitiveClass​(Class cls)
        Returns the corresponding BaseObject-derived wrapper class.
        Parameters:
        cls - the primitive class to wrap
        Returns:
        the wrapper class, null if not available
      • isPrimitive

        public static boolean isPrimitive​(Object obj)
        Checks whether the object is a wrapper for a primitive.
        Parameters:
        obj - the object to test
        Returns:
        true if primitve
      • wrapPrimitive

        public static BaseObject wrapPrimitive​(Object obj)
        Wraps the primitive in a BaseObject-derived object.
        Parameters:
        obj - the primitive to wrap
        Returns:
        the wrapped object, null if failed to wrap
      • unwrapPrimitive

        public static Object unwrapPrimitive​(Object obj)
        Unwraps the primitve from the BaseObject-derived object.
        Parameters:
        obj - the BaseObject to unwrap
        Returns:
        the primitve, null if failed to unwrap
      • log2

        public static double log2​(int n)
        Calculates the log2 of the specified integer.
        Parameters:
        n - the number to calculate log2 for
        Returns:
        the log2
      • escapeUnicode

        public static String escapeUnicode​(String s)
        Escapes any non-ASCII characters as unicode sequences.
        Parameters:
        s - the string to process
        Returns:
        the string with the escaped sequences
      • unescapeUnicode

        public static String unescapeUnicode​(String s)
        Unescapes unicode sequences and stores them as unicode characters instead.
        Parameters:
        s - the string to process
        Returns:
        the unescaped string
      • extractClassnames

        public static Set<String> extractClassnames​(String s,
                                                    boolean onlyManaged)
        Extracts all classnames from the string.
        Parameters:
        s - the string to parse
        onlyManaged - whether to extract only classnames from hierarchies
        Returns:
        the classnames
      • adjustIndices

        public static int[] adjustIndices​(int[] indices,
                                          int adjustment)
        Updates the indices with the supplied adjustment value.
        Parameters:
        indices - the indices to adjust
        Returns:
        the updated indices
      • toOneBasedIndices

        public static int[] toOneBasedIndices​(int[] indices)
        Turns the 0-based indices into 1-based ones.
        Parameters:
        indices - the 0-based indices to convert
        Returns:
        the 1-based indices
      • toZeroBasedIndices

        public static int[] toZeroBasedIndices​(int[] indices)
        Turns the 1-based indices into 0-based ones.
        Parameters:
        indices - the 1-based indices to convert
        Returns:
        the 0-based indices
      • fillIndices

        public static int[] fillIndices​(int from,
                                        int to)
        Creates an int array with the specified indices.
        Parameters:
        from - the first index
        to - the last index (excluded)
        Returns:
        the int array