edu.mayo.bsi.ngsportal.server
Class ArrayRoutines

java.lang.Object
  extended by edu.mayo.bsi.ngsportal.server.ArrayRoutines

public class ArrayRoutines
extends Object

Routines for manipulating arrays of Objects, since Java's class does a poor job of it.

@author Gregory Dougherty


Constructor Summary
ArrayRoutines()
           
 
Method Summary
static int binarySearch(HasValue[] theArray, int key)
          Performs a binary search of theArray for key.
static int binarySearch(String[] theArray, String key, boolean allowPartial)
          Performs a binary search of theArray for key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayRoutines

public ArrayRoutines()
Method Detail

binarySearch

public static final int binarySearch(HasValue[] theArray,
                                     int key)
Performs a binary search of theArray for key. The array must be in sorted order. If one or more elements of theArray has value key, the index of the first of those elements will be returned. If no element has the value key, then it returns the index where an object with key's value would be inserted, or -1 if it would be added to the end of the array. So any value >= 0 returned will be a valid index into theArray.

Parameters:
theArray - The array to search
key - The value to search for
Returns:
-1 if no element of the array has a value >= key, if theArray is null, or if theArray has a length of 0. Otherwise returns the index of the first element in theArray with a value >= key

binarySearch

public static final int binarySearch(String[] theArray,
                                     String key,
                                     boolean allowPartial)
Performs a binary search of theArray for key. The array must be in sorted order. If allowPartial is true, returns the first hit found where the string in the array is a complete match to the beginning of key. No guarantee is made that an exact match will be found if allowPartial is true and there is also a partial starting match. If there are multiple allowed matches, no guarantee is made as to which one will be returned.

Parameters:
theArray - The array to search
key - The value to search for
allowPartial - If true, will also find matches where the key starts with a value from the array
Returns:
-1 if no match is found, if theArray is null, or if theArray has a length of 0. Otherwise returns the index of an element in theArray that is a match