com.croftsoft.core.util
Class ArrayLib2

java.lang.Object
  extended by com.croftsoft.core.util.ArrayLib2

public final class ArrayLib2
extends Object

Array manipulation for Java 1.2+.

Java 1.2 compatible.

Since:
2001-05-25
Version:
2001-05-25
See Also:
ArrayLib
Author:
David W. Croft

Method Summary
static Comparable[] insertSorted(Comparable[] sortedComparableArray, Comparable comparable, boolean allowDuplicates)
          Inserts, in sort order, a Comparable into a presorted array.
static int[] insertSorted(int[] sortedIntArray, int i, boolean allowDuplicates)
          Inserts, in sort order, an integer into a presorted integer array.
static void main(String[] args)
           
static boolean test(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)

test

public static boolean test(String[] args)

insertSorted

public static int[] insertSorted(int[] sortedIntArray,
                                 int i,
                                 boolean allowDuplicates)
Inserts, in sort order, an integer into a presorted integer array.

As this function uses Arrays.binarySearch() and ArrayLib.insert(), it should be more efficient than growing a sorted array by appending an element and calling Arrays.sort() each time, especially as the array grows larger.

Parameters:
sortedIntArray - The array argument must be presorted. If the array was built up one element at a time using this method, the array will always be in a sorted state. If this parameter is null, a new integer array will be created.
comparable - The int value to be inserted.
allowDuplicates - If false, the original array argument may be returned unchanged.
Returns:
Returns a new sorted integer array with integer argument inserted.
See Also:
Arrays.binarySearch(int[],int)

insertSorted

public static Comparable[] insertSorted(Comparable[] sortedComparableArray,
                                        Comparable comparable,
                                        boolean allowDuplicates)
Inserts, in sort order, a Comparable into a presorted array.

As this function uses Arrays.binarySearch(), it should be more efficient than growing a sorted array by appending an element and calling Arrays.sort() each time, especially as the array grows larger.

Parameters:
sortedComparableArray - The array argument must be presorted. If the array was built up one element at a time using this method, the array will always be in a sorted state.
comparable - The Comparable object to be inserted.
allowDuplicates - If false, the original array argument may be returned unchanged.
Returns:
Returns an array with the same component type as the old array.
Throws:
NullArgumentException - If sortedComparableArray or comparable is null.
See Also:
Arrays.binarySearch(java.lang.Object[],java.lang.Object)

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)