02/28/2005
 

com.vignette.portal.util
Class ArrayUtils

java.lang.Object
  |
  +--com.vignette.portal.util.ArrayUtils

public final class ArrayUtils
extends Object

Utility class providing a set of static methods to manipulate arrays.


Constructor Summary
ArrayUtils()
           
 
Method Summary
static int[] addElement(int[] array, int value)
          Returns a new array consisting of the new element added to the end of the original array.
static int[] addElement(int[] array, int value, int position)
          Returns a new array consisting of the supplied element inserted at the specified position in the integer array.
static String[] addElement(String[] array, String value)
          Adds an element to the end of a String array.
static boolean contains(int[] array, int value)
          Tests whether an integer array contains the given element.
static boolean contains(Object[] array, Object value)
          Tests whether an array contains the given element, using Object.equals()
static int[] intersectedArray(int[] a, int[] b)
          Return the intersection of two integer arrays, if they have any matching elements.
static boolean intersects(int[] a, int[] b)
          Tests whether two integer arrays have any matching elements.
static boolean isEmpty(int[] array)
          Tests whether an integer array is empty.
static boolean isEmpty(Object[] array)
          Tests whether an Object array is empty.
static int[] setToIntArray(Set set)
          Converts a Set of Integer objects into an array of ints - the order returned by the set's iterator() method is used - meaning the order is dependent on the implementation of set.
 
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

contains

public static boolean contains(int[] array,
                               int value)
Tests whether an integer array contains the given element.
Parameters:
array - Name of the integer array
value - Array element to test for
Returns:
true if the array contains the element, or false if the array is null

contains

public static boolean contains(Object[] array,
                               Object value)
Tests whether an array contains the given element, using Object.equals()
Parameters:
array - Name of the Object array
value - Array element to test for
Returns:
true if the array contains the element, or false if the array is null or not comparable

addElement

public static int[] addElement(int[] array,
                               int value)
Returns a new array consisting of the new element added to the end of the original array. This operation does not modify the original array.
Parameters:
array - Name of the integer array
value - Element to be added to the array
Returns:
Array with the new element, or if the array is null a new one-element array with the given value

addElement

public static int[] addElement(int[] array,
                               int value,
                               int position)
Returns a new array consisting of the supplied element inserted at the specified position in the integer array. If the position is greater than the length of the array, "appends" the element to the end of the array. This operation does not modify the original array.
Parameters:
array - Name of the integer array
value - Element to be added to the array
position - New element's index
Returns:
Array with the new element, or if the array is null a new one-element array with the given value

addElement

public static String[] addElement(String[] array,
                                  String value)
Adds an element to the end of a String array.
Parameters:
array - Name of the String array
value - Element to be added to the array
Returns:
Array with the new element, or if the array is null a new one-element array with the given value.

isEmpty

public static boolean isEmpty(Object[] array)
Tests whether an Object array is empty.
Parameters:
array - Name of the Object array
Returns:
true if the array is null or has 0 members

isEmpty

public static boolean isEmpty(int[] array)
Tests whether an integer array is empty.
Parameters:
array - Name of the integer array
Returns:
true if the array is null or has 0 members

intersects

public static boolean intersects(int[] a,
                                 int[] b)
Tests whether two integer arrays have any matching elements. Assumes the arrays are sorted in ascending order.
Parameters:
a - First integer array
b - Second integer array
Returns:
true if there is at least one matching element

intersectedArray

public static int[] intersectedArray(int[] a,
                                     int[] b)
Return the intersection of two integer arrays, if they have any matching elements. The arrays MUST BE sorted in ascending order. Sorting can easily be accomplished using Arrays.sort(int[]).
Parameters:
a - First integer array
b - Second integer array
Returns:
a new int array for the intersection

setToIntArray

public static int[] setToIntArray(Set set)
Converts a Set of Integer objects into an array of ints - the order returned by the set's iterator() method is used - meaning the order is dependent on the implementation of set. Returns null if the input set was null or if it contained any non-Integer objects.
Parameters:
set - The Set from which to derive an array of int.
Returns:
An int[] containing all int values contained in the supplied set of Integer Objects.

02/28/2005
 

Copyright and Trademark Notices