danger.util
Class Collections

java.lang.Object
  |
  +--danger.util.Collections

public final class Collections
extends java.lang.Object

Collection utilities.


Method Summary
static int binarySearch(java.util.Vector vec, java.lang.Object key)
          Search the given presumed-sorted Vector for the given key, using Comparable.compareTo() with the key as an argument, as needed to perform a binary search.
static int binarySearch(java.util.Vector vec, java.lang.Object key, java.util.Comparator comp)
          Search the given presumed-sorted Vector for the given key, using the given Comparator with the key as an argument, as needed to perform a binary search.
static void sort(java.util.Vector vec)
          Sort the given Vector using Comparable.compareTo() on elements as needed.
static void sort(java.util.Vector vec, java.util.Comparator comp)
          Sort the given Vector using the given Comparator on elements as needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sort

public static void sort(java.util.Vector vec)
Sort the given Vector using Comparable.compareTo() on elements as needed. This method uses the merge sort algorithm except on small arrays (for which it uses insertion sort), enhanced to provide near-O(N) performance on mostly-presorted data. The algorithm is stable, that is, equal elements will appear in the result in the same order that they appeared originally.
Parameters:
vec - non-null; the Vector to sort

sort

public static void sort(java.util.Vector vec,
                        java.util.Comparator comp)
Sort the given Vector using the given Comparator on elements as needed. This method uses the merge sort algorithm except on small arrays (for which it uses insertion sort), enhanced to provide near-O(N) performance on mostly-presorted data. The algorithm is stable, that is, equal elements will appear in the result in the same order that they appeared originally.
Parameters:
vec - non-null; the Vector to sort
comp - null-ok; the comparator to use, or null to use Comparable.compareTo() instead of an explicit comparator

binarySearch

public static int binarySearch(java.util.Vector vec,
                               java.lang.Object key)
Search the given presumed-sorted Vector for the given key, using Comparable.compareTo() with the key as an argument, as needed to perform a binary search. Return the index where the key was found if it is found, or return ~indexToInsertAt if it was not found. If there is more than one element equal to the given key, then any such element may be indicated.
Parameters:
vec - non-null; the Vector to search through
key - null-ok; the key to look for, which is always passed in as an argument to Comparable.compareTo()
Returns:
the index where the key is found if it is found, or ~insertionPoint if it was not found

binarySearch

public static int binarySearch(java.util.Vector vec,
                               java.lang.Object key,
                               java.util.Comparator comp)
Search the given presumed-sorted Vector for the given key, using the given Comparator with the key as an argument, as needed to perform a binary search. Return the index where the key was found if it is found, or return ~indexToInsertAt if it was not found. If there is more than one element equal to the given key, then any such element may be indicated.
Parameters:
vec - non-null; the Vector to search through
key - null-ok; the key to look for, which is always passed in as the second argument to Comparator.compare()
comp - null-ok; the comparator to use, or null to use Comparable.compareTo() instead of an explicit comparator
Returns:
the index where the key is found if it is found, or ~insertionPoint if it was not found


Danger Confidential. Copyright © 2000-2003, Danger Inc.