org.olat.core.util
Class ArrayHelper

java.lang.Object
  extended by org.olat.core.util.ArrayHelper

public class ArrayHelper
extends java.lang.Object

Description:

Some helper method to deal with arrays

Initial Date: 22.05.2008

Author:
Florian Gnaegi, frentix GmbH, http://www.frentix.com

Constructor Summary
ArrayHelper()
           
 
Method Summary
static java.lang.String[] addToArray(java.lang.String[] oldArray, java.lang.String doBeAddedValue, boolean addAtTheEnd)
          Helper method to add a value to an existing string array.
static void sort(java.lang.String[] first, java.lang.String[] second, boolean afterFirstArray, boolean sortAscending, boolean caseSensitive)
          Helper to sort two string arrays.
static java.lang.String[] toArray(java.util.Collection<java.lang.String> list)
          Shortcut to create a string array from a collection of strings
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayHelper

public ArrayHelper()
Method Detail

sort

public static void sort(java.lang.String[] first,
                        java.lang.String[] second,
                        boolean afterFirstArray,
                        boolean sortAscending,
                        boolean caseSensitive)
Helper to sort two string arrays. The arrays must have the same length and correspond to each other. Use sortAscending to indicate that sorting should be done on the values of the first array or the second one. Use sortAscending to indicate the sort order.
Internally, when comparing the two stings, the string.compareTo() method is used.
After sorting both arrays have a new order based on the given criterias.

Parameters:
first - The first array to be sorted
second - The second array to be sorted
afterFirstArray - true: use first array to define sorting; false: use second one
sortAscending - true: sort ascending; false: sort descending
caseSensitive - true: sort case sensitive; false: sort case insensitive

toArray

public static java.lang.String[] toArray(java.util.Collection<java.lang.String> list)
Shortcut to create a string array from a collection of strings

Parameters:
list -
Returns:

addToArray

public static java.lang.String[] addToArray(java.lang.String[] oldArray,
                                            java.lang.String doBeAddedValue,
                                            boolean addAtTheEnd)
Helper method to add a value to an existing string array. Note that the result will be a reference to a new array

Parameters:
oldArray -
doBeAddedValue -
addAtTheEnd - true: add new value at last possition of array; false: add new value at first position of array.
Returns:
The new array containing the values from the old array and the new array