org.deegree.commons.utils
Class ArrayUtils

java.lang.Object
  extended by org.deegree.commons.utils.ArrayUtils

public class ArrayUtils
extends Object

This is a collection of some methods that work with arrays and lists, like join or removeAll. It is complementary to the StringTools.

Version:
$Revision: 30171 $, $Date: 2011-03-25 12:23:30 +0100 (Fri, 25 Mar 2011) $
Author:
Oliver Tonnhofer, last edited by: $Author: aschmitz $

Constructor Summary
ArrayUtils()
           
 
Method Summary
static boolean contains(String[] target, String value)
          Checks if the array contains the string value.
static boolean contains(String[] target, String value, boolean caseSensitive, boolean exact)
          Checks if the array contains the string value.
static String[] deleteDoubles(String[] s)
          deletes all double entries from the submitted array
static String join(String delimiter, Collection<?> objects)
          Joins a collection of objects with given delimiter.
static String join(String delimiter, double[] values)
          Joins a list of doubles.
static String join(String delimiter, int[] values)
          Joins a list of ints.
static String join(String delimiter, Object... objects)
          Joins a list of objects with given delimiter.
static String join(String delimiter, String... strings)
          Joins a list of strings with given delimiter.
static String[] removeAll(String[] array, String token)
          Removes all occurrences of token in array
static double[] splitAsDoubles(String str, String delim)
           
static float[] splitAsFloats(String str, String delim)
           
static ArrayList<Integer> splitAsIntList(String str, String delim)
           
static String[] toArray(String s, String delimiter, boolean deleteDoubles)
          parse a string and return its tokens as array
static List<String> toList(String s, String delimiter, boolean deleteDoubles)
          parse a string and return its tokens as typed List. empty fields will be removed from the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

removeAll

public static String[] removeAll(String[] array,
                                 String token)
Removes all occurrences of token in array

Parameters:
array -
token - the obj to remove
Returns:
the array without all occurrences of obj

join

public static String join(String delimiter,
                          String... strings)
Joins a list of strings with given delimiter.

Parameters:
delimiter - the delimiter to put between every string.
strings -
Returns:
the joined string

join

public static String join(String delimiter,
                          Object... objects)
Joins a list of objects with given delimiter.

Parameters:
delimiter - the delimiter to put between every string.
objects -
Returns:
the joined string

join

public static String join(String delimiter,
                          Collection<?> objects)
Joins a collection of objects with given delimiter.

Parameters:
delimiter - the delimiter to put between every string.
objects -
Returns:
the joined string

join

public static String join(String delimiter,
                          int[] values)
Joins a list of ints.

Parameters:
delimiter -
values -
Returns:
the joined string

join

public static String join(String delimiter,
                          double[] values)
Joins a list of doubles.

Parameters:
delimiter -
values -
Returns:
the joined string

contains

public static boolean contains(String[] target,
                               String value,
                               boolean caseSensitive,
                               boolean exact)
Checks if the array contains the string value.

Parameters:
target - array to check if it contains value
value - string to check if it within the array
caseSensitive - true if the search should be case sensitive
exact - if the equals test should return true if one of the target strings contains a part of the value.
Returns:
true if passed array contains value

contains

public static boolean contains(String[] target,
                               String value)
Checks if the array contains the string value. This method is case insensitive.

Parameters:
target - array to check if it contains value
value - string to check if it within the array
Returns:
true if passed array contains value

toArray

public static String[] toArray(String s,
                               String delimiter,
                               boolean deleteDoubles)
parse a string and return its tokens as array

Parameters:
s - string to parse
delimiter - delimiter that marks the end of a token
deleteDoubles - if it's true all string that are already within the resulting array will be deleted, so that there will only be one copy of them.
Returns:
an Array of Strings

toList

public static List<String> toList(String s,
                                  String delimiter,
                                  boolean deleteDoubles)
parse a string and return its tokens as typed List. empty fields will be removed from the list.

Parameters:
s - string to parse
delimiter - delimiter that marks the end of a token
deleteDoubles - if it's true all string that are already within the resulting array will be deleted, so that there will only be one copy of them.
Returns:
a list of Strings

deleteDoubles

public static String[] deleteDoubles(String[] s)
deletes all double entries from the submitted array

Parameters:
s - to remove the doubles from
Returns:
The string array without all doubled values

splitAsIntList

public static ArrayList<Integer> splitAsIntList(String str,
                                                String delim)
Parameters:
str -
delim -
Returns:
str.split(delim) values parsed as ints

splitAsDoubles

public static double[] splitAsDoubles(String str,
                                      String delim)
Parameters:
str -
delim -
Returns:
str.split(delim) values parsed as doubles

splitAsFloats

public static float[] splitAsFloats(String str,
                                    String delim)
                             throws NumberFormatException
Parameters:
str -
delim -
Returns:
str.split(delim) values parsed as floats
Throws:
NumberFormatException - if one of the values could not be read.


Copyright © 2011. All Rights Reserved.