Class ArrayUtil


  • public final class ArrayUtil
    extends java.lang.Object
    Methods for manipulating arrays.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getNextSize​(int targetSize)  
      static int getShrinkSize​(int currentSize, int targetSize)  
      static byte[] grow​(byte[] array)  
      static byte[] grow​(byte[] array, int minSize)  
      static int[] grow​(int[] array)  
      static int[] grow​(int[] array, int minSize)  
      static long[] grow​(long[] array)  
      static long[] grow​(long[] array, int minSize)  
      static int hashCode​(byte[] array, int start, int end)
      Returns hash of chars in range start (inclusive) to end (inclusive)
      static int hashCode​(char[] array, int start, int end)
      Returns hash of chars in range start (inclusive) to end (inclusive)
      static int parseInt​(char[] chars)
      Parses the string argument as if it was an int value and returns the result.
      static int parseInt​(char[] chars, int offset, int len)
      Parses a char array into an int.
      static int parseInt​(char[] chars, int offset, int len, int radix)
      Parses the string argument as if it was an int value and returns the result.
      static byte[] shrink​(byte[] array, int targetSize)  
      static int[] shrink​(int[] array, int targetSize)  
      static long[] shrink​(long[] array, int targetSize)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArrayUtil

        public ArrayUtil()
    • Method Detail

      • getNextSize

        public static int getNextSize​(int targetSize)
      • getShrinkSize

        public static int getShrinkSize​(int currentSize,
                                        int targetSize)
      • grow

        public static byte[] grow​(byte[] array)
      • grow

        public static byte[] grow​(byte[] array,
                                  int minSize)
      • grow

        public static int[] grow​(int[] array)
      • grow

        public static int[] grow​(int[] array,
                                 int minSize)
      • grow

        public static long[] grow​(long[] array)
      • grow

        public static long[] grow​(long[] array,
                                  int minSize)
      • hashCode

        public static int hashCode​(byte[] array,
                                   int start,
                                   int end)
        Returns hash of chars in range start (inclusive) to end (inclusive)
      • hashCode

        public static int hashCode​(char[] array,
                                   int start,
                                   int end)
        Returns hash of chars in range start (inclusive) to end (inclusive)
      • parseInt

        public static int parseInt​(char[] chars)
                            throws java.lang.NumberFormatException
        Parses the string argument as if it was an int value and returns the result. Throws NumberFormatException if the string does not represent an int quantity.
        Parameters:
        chars - a string representation of an int quantity.
        Returns:
        int the value represented by the argument
        Throws:
        java.lang.NumberFormatException - if the argument could not be parsed as an int quantity.
      • parseInt

        public static int parseInt​(char[] chars,
                                   int offset,
                                   int len)
                            throws java.lang.NumberFormatException
        Parses a char array into an int.
        Parameters:
        chars - the character array
        offset - The offset into the array
        len - The length
        Returns:
        the int
        Throws:
        java.lang.NumberFormatException - if it can't parse
      • parseInt

        public static int parseInt​(char[] chars,
                                   int offset,
                                   int len,
                                   int radix)
                            throws java.lang.NumberFormatException
        Parses the string argument as if it was an int value and returns the result. Throws NumberFormatException if the string does not represent an int quantity. The second argument specifies the radix to use when parsing the value.
        Parameters:
        chars - a string representation of an int quantity.
        radix - the base to use for conversion.
        Returns:
        int the value represented by the argument
        Throws:
        java.lang.NumberFormatException - if the argument could not be parsed as an int quantity.
      • shrink

        public static byte[] shrink​(byte[] array,
                                    int targetSize)
      • shrink

        public static int[] shrink​(int[] array,
                                   int targetSize)
      • shrink

        public static long[] shrink​(long[] array,
                                    int targetSize)