Class ArrayUtilities


  • public final class ArrayUtilities
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean arrayRangesEquals​(byte[] b1, int start_b1, byte[] b2, int start_b2, int len)
      Returns true if a portion of byte array b1 equals an equally sized portion of byte array b2.
      static int compare​(byte[] a, byte[] b)
      Compare two byte arrays by their corresponding entries If the two arrays have differing lengths, the shorter precedes the longer.
      static <T> T[] copyAndAppend​(T[] array, T element)
      Returns a copy of the given array with the provided element appended.
      static boolean isArrayPrimativeEqual​(java.lang.Object o1, java.lang.Object o2)
      Compares two primitive arrays for equality
      static byte[] reverse​(byte[] array)
      Returns a new copy of the specified byte array with the elements in reversed order.
      • Methods inherited from class java.lang.Object

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

      • ArrayUtilities

        public ArrayUtilities()
    • Method Detail

      • reverse

        public static byte[] reverse​(byte[] array)
        Returns a new copy of the specified byte array with the elements in reversed order.
        Parameters:
        array - byte array to reverse
        Returns:
        new array instance with elements in reverse order
      • isArrayPrimativeEqual

        public static boolean isArrayPrimativeEqual​(java.lang.Object o1,
                                                    java.lang.Object o2)
        Compares two primitive arrays for equality
        Parameters:
        o1 - the first array
        o2 - the second array
        Returns:
        true if each element of the array is equal
        Throws:
        java.lang.IllegalArgumentException - if either argument is not an array
      • arrayRangesEquals

        public static boolean arrayRangesEquals​(byte[] b1,
                                                int start_b1,
                                                byte[] b2,
                                                int start_b2,
                                                int len)
        Returns true if a portion of byte array b1 equals an equally sized portion of byte array b2.

        If the sizes of b1 or b2 do not allow for a full comparison of len bytes, this function will return false.

        Parameters:
        b1 - first byte array
        start_b1 - offset to start comparison in b1
        b2 - second byte array
        start_b2 - offset to start comparison in b2
        len - number of bytes to compare
        Returns:
        true or false if the portion is equal
      • copyAndAppend

        public static <T> T[] copyAndAppend​(T[] array,
                                            T element)
        Returns a copy of the given array with the provided element appended. The length of the returned array will be one element greater than the given array.
        Parameters:
        array - The array to copy.
        element - The element to append to the copy.
        Returns:
        A copy of the given array with the provided element appended.
      • compare

        public static int compare​(byte[] a,
                                  byte[] b)
        Compare two byte arrays by their corresponding entries If the two arrays have differing lengths, the shorter precedes the longer. Otherwise, they are compared as in C's memcmp, except that Java bytes are signed.
        Parameters:
        a - the first array
        b - the second array
        Returns:
        a comparison result as in Comparable.compareTo(Object)