com.flexive.shared
Class FxArrayUtils

java.lang.Object
  extended by com.flexive.shared.FxArrayUtils

public class FxArrayUtils
extends java.lang.Object

Utility functions for arrays.

Version:
$Rev: 2906 $
Author:
Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Constructor Summary
FxArrayUtils()
           
 
Method Summary
static int[] addElement(int[] list, int element)
          Adds a element to the end of the array, if it is not already contained.
static long[] addElement(long[] list, long element)
          Adds a element to the end of the array, if it is not already contained.
static
<T> T[]
addElement(T[] list, T element, boolean unique)
          Adds a element to the end of the array.
static boolean containsElement(java.lang.String[] list, java.lang.String element, boolean ignoreCase)
          Return true if the list contains the given element.
static java.lang.String createEmptyStringArray(int length, char separator)
          Create an empty array string containing only separators
static java.lang.Integer getHexIntElementAt(java.lang.String array, char separator, int index)
          Get an integer element from a string array containing hexadecimal values
static int getIntElementAt(java.lang.String array, char separator, int index)
          Get an integer element from a string array
static int indexOf(java.lang.String[] list, java.lang.String element, boolean ignoreCase)
          Returns the first occurence of the given element.
static int[] removeDuplicates(int[] list)
          Removes dupicated entries from the list.
static long[] removeDuplicates(long[] list)
          Removes dupicated entries from the list.
static java.lang.String replaceElement(java.lang.String array, char separator, int index, java.lang.String newValue)
          Replace an array element
static int[] toIntArray(java.lang.String list, char separator)
          Converts a list with integer items separated by a specific delimeter to a array.
static java.lang.Long[] toLongArray(java.util.List<java.lang.Long> items)
          Convert a Long list to a Long array
static long[] toLongArray(java.lang.String list, char separator)
          Converts a list with long items separated by a specific delimeter to a array.
static long[] toPrimitiveLongArray(java.util.List<java.lang.Long> items)
          Convert a Long list to a long array
static java.lang.String toStringArray(int[] elements, char separator)
          Convert an int array to a string array with the given separator
static java.lang.String toStringArray(long[] elements, char separator)
          Convert an int array to a string array with the given separator
static java.lang.String toStringArray(java.lang.Object[] elements, char separator)
          Convert an object array to a string array with the given separator
static java.lang.String toStringArray(java.lang.Object[] elements, java.lang.String separator)
          Convert an object array to a string array with the given separator String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FxArrayUtils

public FxArrayUtils()
Method Detail

toIntArray

public static int[] toIntArray(java.lang.String list,
                               char separator)
                        throws FxInvalidParameterException
Converts a list with integer items separated by a specific delimeter to a array.

A empty array will be returned if the list is null or a empty string.

Parameters:
list - the list
separator - the separator character
Returns:
the array
Throws:
FxInvalidParameterException - if the list can not be converted, the exception's getParameterName() function will return the token that caused the exception

toLongArray

public static long[] toLongArray(java.lang.String list,
                                 char separator)
                          throws FxInvalidParameterException
Converts a list with long items separated by a specific delimeter to a array.

A empty array will be returned if the list is null or a empty string.

Parameters:
list - the list
separator - the separator character
Returns:
the array
Throws:
FxInvalidParameterException - if the list can not be converted, the exception's getParameterName() function will return the token that caused the exception

toLongArray

public static java.lang.Long[] toLongArray(java.util.List<java.lang.Long> items)
Convert a Long list to a Long array

Parameters:
items - List
Returns:
Long[]

toPrimitiveLongArray

public static long[] toPrimitiveLongArray(java.util.List<java.lang.Long> items)
Convert a Long list to a long array

Parameters:
items - List
Returns:
long[]
Since:
3.1

removeDuplicates

public static int[] removeDuplicates(int[] list)
Removes dupicated entries from the list.

Parameters:
list - the list
Returns:
the list without any duplicated entries

removeDuplicates

public static long[] removeDuplicates(long[] list)
Removes dupicated entries from the list.

Parameters:
list - the list
Returns:
the list without any duplicated entries

addElement

public static int[] addElement(int[] list,
                               int element)
Adds a element to the end of the array, if it is not already contained.

Parameters:
list - original list
element - the element to add
Returns:
the new list

addElement

public static long[] addElement(long[] list,
                                long element)
Adds a element to the end of the array, if it is not already contained.

Parameters:
list - original list
element - the element to add
Returns:
the new list

addElement

public static <T> T[] addElement(T[] list,
                                 T element,
                                 boolean unique)
Adds a element to the end of the array.

Parameters:
list - original list
element - the element to add
unique - true if the element should only be added if it is not already contained
Returns:
the new list

containsElement

public static boolean containsElement(java.lang.String[] list,
                                      java.lang.String element,
                                      boolean ignoreCase)
Return true if the list contains the given element.

Parameters:
list - the list
element - the element to look for
ignoreCase - if set to false the compare is done case sensitive
Returns:
true if the list contains the given element

indexOf

public static int indexOf(java.lang.String[] list,
                          java.lang.String element,
                          boolean ignoreCase)
Returns the first occurence of the given element.

Parameters:
list - the list
element - the element to look for
ignoreCase - if set to false the compare is done case sensitive
Returns:
true the first position, or -1 if the element was not found

toStringArray

public static java.lang.String toStringArray(java.lang.Object[] elements,
                                             char separator)
Convert an object array to a string array with the given separator

Parameters:
elements - elements to convert to a String
separator - separator for the resulting String
Returns:
String representation of the array

toStringArray

public static java.lang.String toStringArray(int[] elements,
                                             char separator)
Convert an int array to a string array with the given separator

Parameters:
elements - elements to convert to a String
separator - separator for the resulting String
Returns:
String representation of the array

toStringArray

public static java.lang.String toStringArray(long[] elements,
                                             char separator)
Convert an int array to a string array with the given separator

Parameters:
elements - elements to convert to a String
separator - separator for the resulting String
Returns:
String representation of the array
Since:
3.2.0

toStringArray

public static java.lang.String toStringArray(java.lang.Object[] elements,
                                             java.lang.String separator)
Convert an object array to a string array with the given separator String

Parameters:
elements - elements to convert to a String
separator - separator for the resulting String
Returns:
String representation of the array

replaceElement

public static java.lang.String replaceElement(java.lang.String array,
                                              char separator,
                                              int index,
                                              java.lang.String newValue)
Replace an array element

Parameters:
array - array containing elements
separator - separator
index - index of the element to replace
newValue - replacement value
Returns:
array with the replaced value

createEmptyStringArray

public static java.lang.String createEmptyStringArray(int length,
                                                      char separator)
Create an empty array string containing only separators

Parameters:
length - desired array length
separator - separator to use
Returns:
String containing length-1 separators

getIntElementAt

public static int getIntElementAt(java.lang.String array,
                                  char separator,
                                  int index)
Get an integer element from a string array

Parameters:
array - the string array
separator - seperator character
index - index to get the element at
Returns:
element or Integer.MIN_VALUE if not set

getHexIntElementAt

public static java.lang.Integer getHexIntElementAt(java.lang.String array,
                                                   char separator,
                                                   int index)
Get an integer element from a string array containing hexadecimal values

Parameters:
array - the string array containing hexadecimal values
separator - seperator character
index - index to get the element at
Returns:
element or null if not set