|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.aliasi.util.Arrays
public class Arrays
Static utility methods for processing arrays.
| Field Summary | |
|---|---|
static char[] |
EMPTY_CHAR_ARRAY
A length 0 array of characters. |
static int[] |
EMPTY_INT_ARRAY
A length 0 array of integers. |
| Method Summary | ||
|---|---|---|
static char[] |
add(char c,
char[] cs)
Return the result of adding the specified character to the specified sorted character array. |
|
static String |
arrayToCSV(Object[] xs)
Converts an array of objects to comma-separated values notation. |
|
static String |
arrayToCSV(String[][] elts)
Converts the two-dimensional array of strings to comma-separated value notaiton. |
|
static String |
arrayToString(Object[] xs)
Returns the concatenation of the string representations of the specified objects separated by commas, with the whole surrounded by square brackets and separated by a comma. |
|
static void |
arrayToStringBuffer(StringBuffer sb,
Object[] xs)
Appends to the string buffer the concatenation of the string representations of the specified objects separated by commas, with the whole surrounded by square brackets and separated by a comma. |
|
static char[] |
concatenate(char[] cs,
char c)
Returns the array of characters consisting of the members of the first specified array followed by the specified character. |
|
static String[] |
concatenate(String[] xs,
String[] ys)
Returns a new array of strings containing the elements of the first array of strings specified followed by the elements of the second array of strings specified. |
|
static char[] |
copy(char[] cs)
Return a shallow copy of the specified array that contains the same elements as the specified array. |
|
static String[] |
csvToArray(String csvs)
Converts a string of comma-separated values into an array of strings. |
|
static String[][] |
csvToArray2D(String csvs)
Converts a comma-separated values string to a two-dimensional array of strings. |
|
static boolean |
equals(Object[] xs,
Object[] ys)
Return true if the specified arrays are
the same length and contain the same elements. |
|
static boolean |
member(char c,
char[] cs)
Returns true if the specified character is a member of the specified array. |
|
static boolean |
member(Object x,
Object[] xs)
Returns true if the specified object is an element of the specified array. |
|
static
|
permute(E[] xs)
Randomly permutes the elements of the specified array using a freshly generated randomizer. |
|
static
|
permute(E[] xs,
Random random)
Randomly permutes the elements of the specified array using the specified randomizer. |
|
static void |
permute(int[] xs)
Randomly permutes the elements of the specified integer array using a newly created randomizer. |
|
static void |
permute(int[] xs,
Random random)
Randomly permutes the elements of the specified integer array using the specified randomizer. |
|
static int[] |
reallocate(int[] xs)
Reallocates the specified integer array to be 50 percent longer, with a minimum growth in length of one element. |
|
static int[] |
reallocate(int[] xs,
int newSize)
Returns a copy of the specified array of integers of the specified size. |
|
static int |
sum(int[] xs)
Returns the sum of the specified integer array. |
|
static char[] |
toArray(CharSequence cSeq)
Converts the specified character sequence to an array of characters. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int[] EMPTY_INT_ARRAY
0 array of integers.
public static final char[] EMPTY_CHAR_ARRAY
0 array of characters.
| Method Detail |
|---|
public static int[] reallocate(int[] xs,
int newSize)
xs - Original array.newSize - Length of returned array.
public static int[] reallocate(int[] xs)
0).
xs - Array to reallocate.
public static char[] add(char c,
char[] cs)
Warning: No check is done that the incoming character array is in order.
c - Character to add.cs - Array of characters in sorted order.
public static char[] copy(char[] cs)
null, then null
is returned.
cs - Array to copy.
public static char[] toArray(CharSequence cSeq)
cSeq - Character sequence to convert.
public static String[] csvToArray(String csvs)
Any comma (,), backslash (\) or
newline (\n) that appears in a value is escaped
with a backslash (\). No other use of backslash
or comma in values is permitted. An attempt to decode an
ill-formed input will throw an exception.
Some examples of strings and arrays they return, using Java's string-literal escapes, are:
| CSV | String |
"" |
{ "" } |
"a" |
{ "a" } |
"a,b" |
{ "a", "b" } |
"abc,def,g" |
{ "abc", "def", "g" } |
"," |
{ "", "" } |
",,,b" |
{ "", "", "", "b" } |
"a\,b" |
{ "a,b" } |
"\\\\" |
{ "\\" } |
"ab\\\\" |
{ "ab\\" } |
"\\\n" |
{ "\n" } |
"a\\,bc,d\\,e,,f" |
{ "a,bc", "d\", "e", "", "f" } |
"ab\\" |
IllegalArgumentException |
"a\\bc" |
IllegalArgumentException |
"\" |
IllegalArgumentException |
"\\\" |
IllegalArgumentException |
Given the use of java escapes, "ab\\" is
the three character sequence a, b and backslash, with the
backslash escaped as \\. Similarly, "\\\n"
is the two character string composed of a backslash followed
by a newline character.
csvs - Comma-separated values to separate.
IllegalArgumentException - if the input is not well formed.public static String[][] csvToArray2D(String csvs)
\n<\code>) are used to
separate rows, and each row is in CSV notation, as defined in
csvToArray(String) for more information on the row
encoding.
Here are some examples:
CSV
Array
""
{ { "" } }
"a"
{ { "a" } }
"a,b"
{ { "a", "b" } }
"\n"
{ { "" }, { "" } }
"\n\n"
{ { "" }, { "" }, { "" } }
"\\\n"
{ { "\n" } }
Any illegal argument for csvToArray(String) is also an
illegal argument for this method.
- Parameters:
csvs - Input comma-separated values.
- Returns:
- Array of arrays of strings derived from CSVs.
- Throws:
IllegalArgumentException - If the CVSs are not well formed.
public static String arrayToCSV(String[][] elts)
csvToArray2D(String) for more
information on the encoding. The input may be a ragged array.
elts - Array of arrays to encode.
public static String arrayToCSV(Object[] xs)
toString() method.
See csvToArray(String) for information on
the encoding and the reverse mapping.
xs - Array of strings to encode.
public static boolean member(Object x,
Object[] xs)
false if the specified
array is null.
x - Object to test for membership.xs - Array to test for object.
true if the specified object is an element
of the specified array.
public static boolean member(char c,
char[] cs)
false if the specified
array is null.
c - Character to test for membership.cs - Array to test for character.
true if the specified character is an
element of the specified array.public static String arrayToString(Object[] xs)
xs - Array of which to return a string representation.
public static void arrayToStringBuffer(StringBuffer sb,
Object[] xs)
sb - String buffer to which string representation is
appended.xs - Array of which to return a string representation.
public static char[] concatenate(char[] cs,
char c)
cs - Characters to start resulting array.c - Last character in resulting array.
NullPointerException - If the array of characters is
null.
public static String[] concatenate(String[] xs,
String[] ys)
xs - First array of strings.ys - Second array of strings.
public static int sum(int[] xs)
xs - Array of integers to sum.
public static boolean equals(Object[] xs,
Object[] ys)
true if the specified arrays are
the same length and contain the same elements.
xs - First array.ys - Second array.
true if the specified arrays are the same
length and contain the same elements.public static <E> void permute(E[] xs)
xs - Array to permute.
public static <E> void permute(E[] xs,
Random random)
xs - Array to permute.random - Randomizer to use for permuation.public static void permute(int[] xs)
Random.Random().
xs - Array to permute.
public static void permute(int[] xs,
Random random)
xs - Array to permute.random - Randomizer to use for permutations.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||