# Class Arrays

java.lang.Object
org.apache.catalina.tribes.util.Arrays

public class Arrays extends Object
Utility class for array operations in the Tribes clustering framework.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final StringManager`
  `sm`
  String manager for this class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `add(int[] data)`
  Sums all elements of an integer array.
  `static boolean`
  `contains(byte[] source, int srcoffset, byte[] key, int keyoffset, int length)`
  Checks if a byte array contains a key at a given offset.
  `static byte[]`
  `convert(String s)`
  Converts a string to a byte array using ISO-8859-1 encoding.
  `static Member[]`
  `diff(Membership complete, Membership local, Member ignore)`
  Returns members in the complete set that are not in the local set.
  `static boolean`
  `equals(byte[] o1, byte[] o2)`
  Compares two byte arrays for equality.
  `static boolean`
  `equals(Object[] o1, Object[] o2)`
  Compares two object arrays for equality.
  `static Member[]`
  `extract(Member[] all, Member[] remove)`
  Removes specified members from an array.
  `static void`
  `fill(Membership mbrship, Member[] m)`
  Adds all members from an array to a Membership.
  `static byte[]`
  `fromString(String value)`
  Parses a byte array from its string representation.
  `static UniqueId`
  `getUniqudId(byte[] data)`
  Creates a UniqueId from a byte array.
  `static UniqueId`
  `getUniqudId(ChannelMessage msg)`
  Extracts a UniqueId from a ChannelMessage.
  `static int`
  `hashCode(byte[] a)`
  Computes a hash code for a byte array.
  `static int`
  `indexOf(Member member, Member[] members)`
  Finds the index of a member in an array.
  `static Member[]`
  `merge(Member[] m1, Member[] m2)`
  Merges two member arrays, removing duplicates.
  `static int`
  `nextIndex(Member member, Member[] members)`
  Finds the index of the next member after the given one.
  `static Member[]`
  `remove(Member[] all, Member remove)`
  Removes a single member from an array.
  `static boolean`
  `sameMembers(Member[] m1, Member[] m2)`
  Checks if two member arrays contain the same members.
  `static String`
  `toNameString(Member[] data)`
  Converts a member array to a string of member names.
  `static String`
  `toNameString(Member[] data, int offset, int length)`
  Converts a portion of a member array to a string of member names.
  `static String`
  `toString(byte[] data)`
  Converts a byte array to a string representation.
  `static String`
  `toString(byte[] data, int offset, int length)`
  Converts a portion of a byte array to a string representation.
  `static String`
  `toString(byte[] data, int offset, int length, boolean unsigned)`
  Converts a portion of a byte array to a string representation, optionally treating bytes as unsigned.
  `static String`
  `toString(Object[] data)`
  Converts an object array to a string representation.
  `static String`
  `toString(Object[] data, int offset, int length)`
  Converts a portion of an object array to a string representation.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    String manager for this class.

- ## Method Details

  - ### contains

    public static boolean contains(byte[] source, int srcoffset, byte[] key, int keyoffset, int length)
    Checks if a byte array contains a key at a given offset.
    Parameters:
      `source` - the source byte array
      `srcoffset` - the offset in the source array
      `key` - the key byte array to search for
      `keyoffset` - the offset in the key array
      `length` - the length of the data to compare
    Returns:
      `true` if the key is found at the given offset

  - ### toString

    public static String toString(byte[] data)
    Converts a byte array to a string representation.
    Parameters:
      `data` - the byte array
    Returns:
      the string representation

  - ### toString

    public static String toString(byte[] data, int offset, int length)
    Converts a portion of a byte array to a string representation.
    Parameters:
      `data` - the byte array
      `offset` - the starting offset
      `length` - the number of elements
    Returns:
      the string representation

  - ### toString

    public static String toString(byte[] data, int offset, int length, boolean unsigned)
    Converts a portion of a byte array to a string representation, optionally treating bytes as unsigned.
    Parameters:
      `data` - the byte array
      `offset` - the starting offset
      `length` - the number of elements
      `unsigned` - `true` to treat bytes as unsigned
    Returns:
      the string representation

  - ### toString

    public static String toString(Object[] data)
    Converts an object array to a string representation.
    Parameters:
      `data` - the object array
    Returns:
      the string representation

  - ### toString

    public static String toString(Object[] data, int offset, int length)
    Converts a portion of an object array to a string representation.
    Parameters:
      `data` - the object array
      `offset` - the starting offset
      `length` - the number of elements
    Returns:
      the string representation

  - ### toNameString

    public static String toNameString(Member[] data)
    Converts a member array to a string of member names.
    Parameters:
      `data` - the member array
    Returns:
      the string of member names

  - ### toNameString

    public static String toNameString(Member[] data, int offset, int length)
    Converts a portion of a member array to a string of member names.
    Parameters:
      `data` - the member array
      `offset` - the starting offset
      `length` - the number of elements
    Returns:
      the string of member names

  - ### add

    public static int add(int[] data)
    Sums all elements of an integer array.
    Parameters:
      `data` - the integer array
    Returns:
      the sum of all elements

  - ### getUniqudId

    public static UniqueId getUniqudId(ChannelMessage msg)
    Extracts a UniqueId from a ChannelMessage.
    Parameters:
      `msg` - the channel message
    Returns:
      the unique ID

  - ### getUniqudId

    public static UniqueId getUniqudId(byte[] data)
    Creates a UniqueId from a byte array.
    Parameters:
      `data` - the byte array
    Returns:
      the unique ID

  - ### equals

    public static boolean equals(byte[] o1, byte[] o2)
    Compares two byte arrays for equality.
    Parameters:
      `o1` - the first byte array
      `o2` - the second byte array
    Returns:
      `true` if the arrays are equal

  - ### equals

    public static boolean equals(Object[] o1, Object[] o2)
    Compares two object arrays for equality.
    Parameters:
      `o1` - the first object array
      `o2` - the second object array
    Returns:
      `true` if the arrays are equal

  - ### sameMembers

    public static boolean sameMembers(Member[] m1, Member[] m2)
    Checks if two member arrays contain the same members.
    Parameters:
      `m1` - the first member array
      `m2` - the second member array
    Returns:
      `true` if both arrays contain the same members

  - ### merge

    public static Member[] merge(Member[] m1, Member[] m2)
    Merges two member arrays, removing duplicates.
    Parameters:
      `m1` - the first member array
      `m2` - the second member array
    Returns:
      the merged member array

  - ### fill

    public static void fill(Membership mbrship, Member[] m)
    Adds all members from an array to a Membership.
    Parameters:
      `mbrship` - the membership to add members to
      `m` - the member array

  - ### diff

    public static Member[] diff(Membership complete, Membership local, Member ignore)
    Returns members in the complete set that are not in the local set.
    Parameters:
      `complete` - the complete membership
      `local` - the local membership
      `ignore` - the member to ignore
    Returns:
      the difference as a member array

  - ### remove

    public static Member[] remove(Member[] all, Member remove)
    Removes a single member from an array.
    Parameters:
      `all` - the member array
      `remove` - the member to remove
    Returns:
      the array with the member removed

  - ### extract

    public static Member[] extract(Member[] all, Member[] remove)
    Removes specified members from an array.
    Parameters:
      `all` - the member array
      `remove` - the members to remove
    Returns:
      the array with specified members removed

  - ### indexOf

    public static int indexOf(Member member, Member[] members)
    Finds the index of a member in an array.
    Parameters:
      `member` - the member to find
      `members` - the member array
    Returns:
      the index, or -1 if not found

  - ### nextIndex

    public static int nextIndex(Member member, Member[] members)
    Finds the index of the next member after the given one.
    Parameters:
      `member` - the current member
      `members` - the member array
    Returns:
      the next index, wrapping to 0 if at end, or -1 if empty

  - ### hashCode

    public static int hashCode(byte[] a)
    Computes a hash code for a byte array.
    Parameters:
      `a` - the byte array
    Returns:
      the hash code

  - ### fromString

    public static byte[] fromString(String value)
    Parses a byte array from its string representation.
    Parameters:
      `value` - the string representation
    Returns:
      the byte array

  - ### convert

    public static byte[] convert(String s)
    Converts a string to a byte array using ISO-8859-1 encoding.
    Parameters:
      `s` - the string to convert
    Returns:
      the byte array