FileDocCategorySizeDatePackage
KeySortUtility.javaAPI DocphoneME MR2 API (J2ME)3391Wed May 02 18:00:28 BST 2007com.sun.kvem.midp.pim

KeySortUtility

public class KeySortUtility extends Object
Class KeySortUtility contains static method "store" only.
see
store

Fields Summary
Constructors Summary
Methods Summary
static voidstore(java.util.Vector keyList, java.util.Vector valueList, long key, java.lang.Object value)
Support method. Maintains a list, valueList, where each element in the list has a corresponding key (of type Long) stored in keyList. This method inserts "value" into "valueList" with the following postconditions:
  • keyList.size() == valueList.size()
  • keyList[i] corresponds to valueList[i] (0 <= i < keyList.size())
  • keyList is in ascending order of keys
  • keyList contains key
  • valueList contains value
  • key corresponds to value
The following are preconditions:
  • keyList.size() == valueList.size()
  • keyList[i] corresponds to valueList[i] (0 <= i < keyList.size())
  • keyList is in ascending order of keys
In order to maintain the arrays correctly, the objects passed as keyList and valueList should only be modified by this method.

Preconditions are not verified by this method.

param
keyList array or property names
param
valueList array of property values
param
key identifier for this list
param
value target object to store the list

        // do a binary chop search for the index before which to
        // insert value
        int lowerBound = 0;
        int upperBound = keyList.size();
        while (lowerBound != upperBound) {
            int index = lowerBound + (upperBound - lowerBound) / 2;
            long indexKey =
                ((Long) keyList.elementAt(index)).longValue();
            if (indexKey > key) {
                if (index == upperBound) {
                    upperBound --;
                } else {
                    upperBound = index;
                }
            } else {
                if (index == lowerBound) {
                    lowerBound ++;
                } else {
                    lowerBound = index;
                }
            }
        }
        keyList.insertElementAt(new Long(key), lowerBound);
        valueList.insertElementAt(value, lowerBound);