Package org.apache.catalina.tribes.util
Class Arrays
- java.lang.Object
-
- org.apache.catalina.tribes.util.Arrays
-
public class Arrays extends java.lang.ObjectUtility class for array operations in the Tribes clustering framework.
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringManagersmString manager for this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intadd(int[] data)Sums all elements of an integer array.static booleancontains(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(java.lang.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 booleanequals(byte[] o1, byte[] o2)Compares two byte arrays for equality.static booleanequals(java.lang.Object[] o1, java.lang.Object[] o2)Compares two object arrays for equality.static Member[]extract(Member[] all, Member[] remove)Removes specified members from an array.static voidfill(Membership mbrship, Member[] m)Adds all members from an array to a Membership.static byte[]fromString(java.lang.String value)Parses a byte array from its string representation.static UniqueIdgetUniqudId(byte[] data)Creates a UniqueId from a byte array.static UniqueIdgetUniqudId(ChannelMessage msg)Extracts a UniqueId from a ChannelMessage.static inthashCode(byte[] a)Computes a hash code for a byte array.static intindexOf(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 intnextIndex(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 booleansameMembers(Member[] m1, Member[] m2)Checks if two member arrays contain the same members.static java.lang.StringtoNameString(Member[] data)Converts a member array to a string of member names.static java.lang.StringtoNameString(Member[] data, int offset, int length)Converts a portion of a member array to a string of member names.static java.lang.StringtoString(byte[] data)Converts a byte array to a string representation.static java.lang.StringtoString(byte[] data, int offset, int length)Converts a portion of a byte array to a string representation.static java.lang.StringtoString(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 java.lang.StringtoString(java.lang.Object[] data)Converts an object array to a string representation.static java.lang.StringtoString(java.lang.Object[] data, int offset, int length)Converts a portion of an object array to a string representation.
-
-
-
Field Detail
-
sm
protected static final StringManager sm
String manager for this class.
-
-
Method Detail
-
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 arraysrcoffset- the offset in the source arraykey- the key byte array to search forkeyoffset- the offset in the key arraylength- the length of the data to compare- Returns:
trueif the key is found at the given offset
-
toString
public static java.lang.String toString(byte[] data)
Converts a byte array to a string representation.- Parameters:
data- the byte array- Returns:
- the string representation
-
toString
public static java.lang.String toString(byte[] data, int offset, int length)Converts a portion of a byte array to a string representation.- Parameters:
data- the byte arrayoffset- the starting offsetlength- the number of elements- Returns:
- the string representation
-
toString
public static java.lang.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 arrayoffset- the starting offsetlength- the number of elementsunsigned-trueto treat bytes as unsigned- Returns:
- the string representation
-
toString
public static java.lang.String toString(java.lang.Object[] data)
Converts an object array to a string representation.- Parameters:
data- the object array- Returns:
- the string representation
-
toString
public static java.lang.String toString(java.lang.Object[] data, int offset, int length)Converts a portion of an object array to a string representation.- Parameters:
data- the object arrayoffset- the starting offsetlength- the number of elements- Returns:
- the string representation
-
toNameString
public static java.lang.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 java.lang.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 arrayoffset- the starting offsetlength- 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 arrayo2- the second byte array- Returns:
trueif the arrays are equal
-
equals
public static boolean equals(java.lang.Object[] o1, java.lang.Object[] o2)Compares two object arrays for equality.- Parameters:
o1- the first object arrayo2- the second object array- Returns:
trueif 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 arraym2- the second member array- Returns:
trueif 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 arraym2- 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 tom- 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 membershiplocal- the local membershipignore- 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 arrayremove- 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 arrayremove- 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 findmembers- 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 membermembers- 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(java.lang.String value)
Parses a byte array from its string representation.- Parameters:
value- the string representation- Returns:
- the byte array
-
convert
public static byte[] convert(java.lang.String s)
Converts a string to a byte array using ISO-8859-1 encoding.- Parameters:
s- the string to convert- Returns:
- the byte array
-
-