com.jstatcom.util
Class UStringArray
- java.lang.Object
-
- com.jstatcom.util.UStringArray
-
public final class UStringArray extends java.lang.ObjectA collection of static methods that are related to arrays of strings.All methods implemented do not modify the original input. Results are always newly created arrays. If the input is somehow wrong an appropriate exception is thrown. All methods require that the input arrays have the same number of elements in each row.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.String[][]appendStringCols(java.lang.String[][] orig, java.lang.String[][] toAppend)AppendstoAppendto the columns oforigand returns the new merged array.static java.lang.String[][]appendStringRows(java.lang.String[][] orig, java.lang.String[][] toAppend)AppendstoAppendto the rows oforigand returns the new merged array.static java.lang.String[][]appendSuffix(java.lang.String[][] orig, java.lang.String suffix)Appendssuffixto the elements oforigand returns the new string array.static java.lang.String[]appendSuffix(java.lang.String[] orig, java.lang.String suffix)Appendssuffixto the elements oforigand returns the new string array.static voidcheckRowLengths(java.lang.String[][] arg)Checks whether all rows ofarghave the same number of columns.static java.lang.String[][]cloneStringArray(java.lang.String[][] x)Gets an identical copy ofx.static booleancompareStringArrays(java.lang.String[][] arg1, java.lang.String[][] arg2)Compares two string arrays and returnstrue.static java.lang.String[]createNamedIndex(java.lang.String name, double[] idx)Creates an index with its elements starting withnamefollowed by the integer part of the respective element ofidx.static java.lang.String[][]delCol(java.lang.String[][] arg, int colIndex)Deletes the columncolIndexfromarg.static java.lang.String[][]delif(java.lang.String[][] arg, int[] index)Deletes columns ofargthat have been selected byindexand returns a new array with the remaining columns.static java.lang.String[][]delRow(java.lang.String[][] arg, int rowIndex)Deletes the rowrowIndexfromarg.static java.lang.String[][]delRowsIf(java.lang.String[][] arg, int[] index)Deletes rows ofargthat have been selected byindexand returns a new array with the remaining rows.static java.lang.String[]delRowsIf(java.lang.String[] arg, int[] rowIndex)Deletes rows ofargthat have been selected byindexand returns a new array with the remaining rows.static java.lang.String[]getStringCol(java.lang.String[][] arg, int colIndex)Gets the column of the arrayargspecified withcolIndex.static java.lang.String[]getStringDiff(java.lang.String[] arg1, java.lang.String[] arg2)Gets a new string array with only the rows ofarg1that do not appear inarg2.static java.lang.String[][]getStringRows(java.lang.String[][] arg, int startRow, int endRow)Gets all rows of the arrayargdefined bystartRow:endRow.static java.lang.String[][]selif(java.lang.String[][] arg, int[] index)Gets all columns of the arrayargthat have a nonzero corresponding element inindex.static java.lang.String[][]selRowsIf(java.lang.String[][] arg, int[] index)Gets all rows of the arrayargthat have a nonzero corresponding element inindex.static java.lang.String[]selRowsIf(java.lang.String[] arg, int[] rowIndex)Gets a new string array with all elementsargthat have a corresponding value inrowIndexthat is != 0.static java.lang.String[][]toStringMatrix(java.lang.String[] arg)Transforms a one-dimensional array into a K x 1 pseudo-two-dimensional array.
-
-
-
Method Detail
-
appendStringCols
public static java.lang.String[][] appendStringCols(java.lang.String[][] orig, java.lang.String[][] toAppend)AppendstoAppendto the columns oforigand returns the new merged array. This only works, iforigandtoAppendhave the same number of rows.- Parameters:
orig- the array to append the columns oftoAppendtotoAppend- the arrays to be appended toorig- Returns:
- a new array orig~toAppend
- Throws:
java.lang.IllegalArgumentException-if (orig.length != toAppend.length)orif (orig == null || toAppend == null)or if rows of an argument have different lengths
-
appendStringRows
public static java.lang.String[][] appendStringRows(java.lang.String[][] orig, java.lang.String[][] toAppend)AppendstoAppendto the rows oforigand returns the new merged array. This only works, iforigandtoAppendhave the same number of columns.- Parameters:
orig- the array to append the rows oftoAppendtotoAppend- the arrays to be appended toorig- Returns:
- a new array orig|toAppend
- Throws:
java.lang.IllegalArgumentException-if (orig[0].length != toAppend[0].length)orif (orig == null || toAppend == null)or if rows of an argument have different lengths
-
appendSuffix
public static java.lang.String[][] appendSuffix(java.lang.String[][] orig, java.lang.String suffix)Appendssuffixto the elements oforigand returns the new string array.- Parameters:
orig- the original string arraysuffix- the suffix to be appended to all elements oforig- Returns:
- a new string array
- Throws:
java.lang.IllegalArgumentException-if (orig == null || suffix == null)or if rows of argument have different lengths
-
appendSuffix
public static java.lang.String[] appendSuffix(java.lang.String[] orig, java.lang.String suffix)Appendssuffixto the elements oforigand returns the new string array.- Parameters:
orig- the original string arraysuffix- the suffix to be appended to all elements oforig- Returns:
- a new string array
- Throws:
java.lang.IllegalArgumentException-if (orig == null || suffix == null)
-
checkRowLengths
public static void checkRowLengths(java.lang.String[][] arg)
Checks whether all rows ofarghave the same number of columns. If the check fails, an exception is thrown.- Parameters:
arg- theString[][]to check- Throws:
java.lang.IllegalArgumentException- if the rows ofarghave different lengths
-
cloneStringArray
public static java.lang.String[][] cloneStringArray(java.lang.String[][] x)
Gets an identical copy ofx.- Returns:
- the cloned array or
null if (x == null)-
new String[0][0] if (x.length == 0 || x[0].length == 0)
- Throws:
java.lang.IllegalArgumentException- if rows of argument have different lengths
-
compareStringArrays
public static boolean compareStringArrays(java.lang.String[][] arg1, java.lang.String[][] arg2)Compares two string arrays and returnstrue. if the dimensions are the same and all elements are equal. If two elements ofarg1andarg2arenull, they are considered to be equal. The comparison is case sensitive.- Parameters:
arg1- string array to comparearg2- string array to compare- Returns:
trueif dimensions and all elements are equal or ifarg1, arg2have both at least one dimension of zero,
falseotherwise- Throws:
java.lang.IllegalArgumentException- if rows of an argument have different lengths
-
createNamedIndex
public static java.lang.String[] createNamedIndex(java.lang.String name, double[] idx)Creates an index with its elements starting withnamefollowed by the integer part of the respective element ofidx. The resulting string array has lengthidx.length.- Parameters:
name- the string with the prefix for the indexidx- the array containing the indices to be appended toname- Returns:
- a
idx.lengthstring array - Throws:
java.lang.IllegalArgumentException-if (name == null || idx == null)
-
delCol
public static java.lang.String[][] delCol(java.lang.String[][] arg, int colIndex)Deletes the columncolIndexfromarg.- Parameters:
arg- the string array to delete the column fromcolIndex- index of the column- Returns:
- new string array with the deleted column
- Throws:
java.lang.IllegalArgumentException-if (arg == null)orif (colIndex < 0 || arg[0].length < colIndex)orif (arg.length == 0 || arg[0].length == 0)or if rows of argument have different lengths
-
delif
public static java.lang.String[][] delif(java.lang.String[][] arg, int[] index)Deletes columns ofargthat have been selected byindexand returns a new array with the remaining columns. A column is selected for deletion if the corresponding index entry is nonzero.- Parameters:
arg- the array to delete columns fromindex- thearg[0].length x 1 intarray- Returns:
- a new array with the selected columns deleted or
new String[0][0]if all columns where selected for deletion or ifarg.length == 0 - Throws:
java.lang.IllegalArgumentException-if (arg == null || index == null)orif (arg[0].length != index.length)orif ((arg.length == 0 || arg[0].length == 0) && index.length > 0)or if rows of argument have different lengths
-
delRow
public static java.lang.String[][] delRow(java.lang.String[][] arg, int rowIndex)Deletes the rowrowIndexfromarg.- Parameters:
arg- the string array to delete the row fromrowIndex- index of the row- Returns:
- new string array with the deleted row
- Throws:
java.lang.IllegalArgumentException-if (arg == null)orif (rowIndex < 0 || arg.length < rowIndex)orif (arg.length == 0 || arg[0].length == 0)or if rows of argument have different lengths
-
delRowsIf
public static java.lang.String[][] delRowsIf(java.lang.String[][] arg, int[] index)Deletes rows ofargthat have been selected byindexand returns a new array with the remaining rows. A row is selected for deletion if the corresponding index entry is nonzero.- Parameters:
arg- the array to delete rows fromindex- thearg[0].length x 1 intarray- Returns:
- a new array with the selected rows deleted or
new String[0][0]if all rows where selected for deletion or ifarg.length == 0 - Throws:
java.lang.IllegalArgumentException-if (arg == null || index == null)orif (arg.length != index.length)orif ((arg.length == 0 || arg[0].length == 0) && index.length > 0)or if rows ofarghave different lengths
-
delRowsIf
public static java.lang.String[] delRowsIf(java.lang.String[] arg, int[] rowIndex)Deletes rows ofargthat have been selected byindexand returns a new array with the remaining rows. A row is selected for deletion if the corresponding index entry is set to 1 (or != 0).- Parameters:
arg- the array to delete rows fromrowIndex- thearg.length x 1 intarray with 1's and 0's (all values different from 0 select a row, but usually 1)- Returns:
- a new array with the selected rows deleted or
new String[0][0]if all rows where selected for deletion or ifarg.length == 0 - Throws:
java.lang.IllegalArgumentException-if (arg == null || index == null)orif (arg.length != index.length)
-
getStringCol
public static java.lang.String[] getStringCol(java.lang.String[][] arg, int colIndex)Gets the column of the arrayargspecified withcolIndex. The index starts with 0 as usual.- Parameters:
arg- the array to extract a column fromcolIndex- the index of the column to extract (starting from 0)- Returns:
- a one dimensional string array with the column data
- Throws:
java.lang.IllegalArgumentException-if (arg == null)orif (arg.length == 0)or if the index is outside the valid array bounds or if rows of argument have different lengths
-
getStringDiff
public static java.lang.String[] getStringDiff(java.lang.String[] arg1, java.lang.String[] arg2)Gets a new string array with only the rows ofarg1that do not appear inarg2.- Parameters:
arg1- the string array to delete rows from that also appear inarg2arg2- contains strings that are deleted fromarg1- Returns:
- a new string array object with deleted rows
- Throws:
java.lang.IllegalArgumentException-if (arg1 == null || arg2 == null)
-
getStringRows
public static java.lang.String[][] getStringRows(java.lang.String[][] arg, int startRow, int endRow)Gets all rows of the arrayargdefined bystartRow:endRow. The indices start with 0 as usual.- Parameters:
arg- the array to extract rows fromstartRow- the index of the first row to extract (starting from 0)endRow- the index of the last row to extract (starting from 0)- Returns:
- a one dimensional string array with the row data
- Throws:
java.lang.IllegalArgumentException-if (arg == null)orif (arg.length == 0)orif (startRow > endRow)or if the indices are outside the valid array bounds or if rows of argument have different lengths
-
selif
public static java.lang.String[][] selif(java.lang.String[][] arg, int[] index)Gets all columns of the arrayargthat have a nonzero corresponding element inindex.- Parameters:
arg- the array to extract columns fromindex-arg[0].length x 1vector selecting columns fromarg- Returns:
- new array with the extracted columns,
new String[0][0]if index contains only 0's, a copy ofargifindexcontains only nonzero elements - Throws:
java.lang.IllegalArgumentException-if (arg == null || index == null)orif ((arg.length == 0 || arg[0].length == 0) && index.length > 0)orif (arg[0].length != index.length)or if rows of argument have different lengths
-
selRowsIf
public static java.lang.String[][] selRowsIf(java.lang.String[][] arg, int[] index)Gets all rows of the arrayargthat have a nonzero corresponding element inindex.- Parameters:
arg- the array to extract rows fromindex-arg[0].length x 1vector selecting rows fromarg- Returns:
- new array with the extracted rows,
new String[0][0]if index contains only 0's, a copy ofargifindexcontains only nonzero elements - Throws:
java.lang.IllegalArgumentException-if (arg == null || index == null)orif (arg.length == 0 || arg[0].length == 0) && index.length > 0)orif (arg.length != index.length)or if rows of argument have different lengths
-
selRowsIf
public static java.lang.String[] selRowsIf(java.lang.String[] arg, int[] rowIndex)Gets a new string array with all elementsargthat have a corresponding value inrowIndexthat is != 0.argandrowIndexmust have the same dimension.- Parameters:
arg- the array to extract elements fromrowIndex- the index selecting elements fromargifrowIndex[i] != 0- Returns:
- a one dimensional string array with the selected elements
- Throws:
java.lang.IllegalArgumentException-if (arg == null || rowIndex == null)orif (arg.length != rowIndex.length)
-
toStringMatrix
public static java.lang.String[][] toStringMatrix(java.lang.String[] arg)
Transforms a one-dimensional array into a K x 1 pseudo-two-dimensional array. This is sometimes needed to prepare arguments for methods that takeString[][]instead ofString[].- Parameters:
arg- the vector-like array to transform- Returns:
- two-dimensional array with dimensions
arg.length x 1ornull if (arg == null)new String[0][0] if (arg.length == 0)
-
-
DMelt 3.0 © DataMelt by jWork.ORG