com.adventnet.utilities.sort
Class Sorter

java.lang.Object
  extended by com.adventnet.utilities.sort.Sorter

public class Sorter
extends java.lang.Object

This is a utility class which sorts a objectID array using quick sort mechanism .By default the compareTo method compares two strings str1 & str2 considering it to be a OID string. API users may override this method inorder to have their own compareTo method incase of different type of string.

Usage is :

  • sorter = new Sorter();
  • toSort = new String[2]{".1.3.6.1.3.2", ".1.3.6.1.3.12",};
  • sorter.sort(toSort, null);


    Field Summary
    (package private) static boolean flag
               
    (package private)  java.lang.Object[][] obj
               
     
    Constructor Summary
    Sorter()
              The Default Constructor for Sorter.
     
    Method Summary
    (package private) static int[] addIntArrays(int[] first, int[] second)
               
    static int compareTo(int[] oid1, int[] oid2)
              Compares two Integer arrays
    static int compareTo(java.lang.String str1, java.lang.String str2)
              This method compares two string considering it be OID string.
    (package private) static int getMinSize(int[] oid1, int[] oid2)
               
    (package private) static java.lang.String intArrayToString(int[] arr)
               
    (package private) static java.lang.String intArrayToStringWithSpace(int[] arr)
               
    (package private) static java.lang.String LongArrayToStringWithSpace(java.lang.Long[] arr)
               
    static void main(java.lang.String[] args)
               
    (package private)  void QuickSort(int[] a, int lo0, int hi0)
              This is a generic version of C.A.R Hoare's Quick Sort algorithm.
    (package private)  void QuickSort(java.lang.Long[] a, int lo0, int hi0)
              This is a generic version of C.A.R Hoare's Quick Sort algorithm.
    (package private)  void QuickSort(java.lang.String[] a, int lo0, int hi0)
              This is a generic version of C.A.R Hoare's Quick Sort algorithm.
     void setAscending(boolean flag)
              This method is used to define the nature of sorting - either ascending or descending.
     void setFirstValueInt(boolean flag)
              This method is used to define the nature of sorting - either firstValue of the String is int
     void sort(int[] a)
              This method will sort the given int array.
     void sort(java.lang.Long[] a)
              This method will sort the given Long array.
     void sort(java.lang.String[] a, java.lang.Object[][] obj)
              This method sorts the OID string array in ascending order.
     void sort(java.lang.String[] a, java.lang.Object[][] obj, boolean endValueInt)
              This method sorts the OID string array in ascending order.
    (package private) static java.lang.String StringArrayToStringWithSpace(java.lang.String[] arr)
               
    static int[] stringToIntArray(java.lang.String str)
              converts string OID to array of int datatype
    static int[] stringToIntegerArray(java.lang.String str)
              converts string OID to array of int datatype
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    obj

    java.lang.Object[][] obj

    flag

    static boolean flag
    Constructor Detail

    Sorter

    public Sorter()
    The Default Constructor for Sorter.

    Method Detail

    QuickSort

    void QuickSort(java.lang.String[] a,
                   int lo0,
                   int hi0)
             throws java.lang.Exception
    This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.
    If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

    Parameters:
    a - an integer array
    lo0 - left boundary of array partition
    hi0 - right boundary of array partition
    Throws:
    java.lang.Exception

    QuickSort

    void QuickSort(java.lang.Long[] a,
                   int lo0,
                   int hi0)
             throws java.lang.Exception
    This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.
    If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

    Parameters:
    a - an Long array
    lo0 - left boundary of array partition
    hi0 - right boundary of array partition
    Throws:
    java.lang.Exception

    setAscending

    public void setAscending(boolean flag)
    This method is used to define the nature of sorting - either ascending or descending.

    Parameters:
    Flag - True for Sorting in ascending orderm, False for Sorting in Descending order.

    setFirstValueInt

    public void setFirstValueInt(boolean flag)
    This method is used to define the nature of sorting - either firstValue of the String is int

    Parameters:
    Flag - True for the first value as int

    compareTo

    public static int compareTo(java.lang.String str1,
                                java.lang.String str2)
    This method compares two string considering it be OID string. API users may override this method incase if they want to have different compareTo method.

    Parameters:
    str1 - The First String representation of the OID.
    str2 - The Second String representation of the OID.
    Returns:
    -1 If str1 < str2(ascending flag), If str1 > str2(Desending flag). 0 If both the Strings are Equal. 1 If str1 > str2(ascending flag), If str1 < str2(Desending flag).

    sort

    public void sort(java.lang.String[] a,
                     java.lang.Object[][] obj)
              throws java.lang.Exception
    This method sorts the OID string array in ascending order. Also it sorts multi array objects in "obj" according to the key OID string array "a".

    Parameters:
    a - the key string array to be sorted.
    obj - the multiarray objects which are sorted according to the key oid.
    Throws:
    java.lang.Exception - This Wraps all the Exceptions thron while Processing this Event.

    sort

    public void sort(java.lang.String[] a,
                     java.lang.Object[][] obj,
                     boolean endValueInt)
              throws java.lang.Exception
    This method sorts the OID string array in ascending order. Also it sorts multi array objects in "obj" according to the key OID string array "a".

    Parameters:
    a - the key string array to be sorted.
    obj - the multiarray objects which are sorted according to the key oid.
    Throws:
    java.lang.Exception - This Wraps all the Exceptions thron while Processing this Event.

    QuickSort

    void QuickSort(int[] a,
                   int lo0,
                   int hi0)
             throws java.lang.Exception
    This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.
    If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.

    Parameters:
    a - an integer array
    lo0 - left boundary of array partition
    hi0 - right boundary of array partition
    Throws:
    java.lang.Exception

    sort

    public void sort(int[] a)
              throws java.lang.Exception
    This method will sort the given int array.

    Parameters:
    a - The Integer array to be sorted.
    Throws:
    java.lang.Exception - This Wraps all the Exceptions thron while Processing this Event.

    sort

    public void sort(java.lang.Long[] a)
              throws java.lang.Exception
    This method will sort the given Long array.

    Parameters:
    a - The Long array to be sorted.
    Throws:
    java.lang.Exception - This Wraps all the Exceptions thron while Processing this Event.

    stringToIntArray

    public static int[] stringToIntArray(java.lang.String str)
    converts string OID to array of int datatype

    Returns:
    The int array representation of the OID

    stringToIntegerArray

    public static int[] stringToIntegerArray(java.lang.String str)
    converts string OID to array of int datatype

    Returns:
    The int array representation of the OID

    compareTo

    public static int compareTo(int[] oid1,
                                int[] oid2)
    Compares two Integer arrays

    Parameters:
    oid1 - array of integer of oid
    oid2 - array of integer of oid
    Returns:
  • -1 if first param is lesser than second
  • 0 if equal
  • 1 if first param is greater than the second param

  • getMinSize

    static int getMinSize(int[] oid1,
                          int[] oid2)

    addIntArrays

    static int[] addIntArrays(int[] first,
                              int[] second)

    intArrayToString

    static java.lang.String intArrayToString(int[] arr)

    intArrayToStringWithSpace

    static java.lang.String intArrayToStringWithSpace(int[] arr)

    LongArrayToStringWithSpace

    static java.lang.String LongArrayToStringWithSpace(java.lang.Long[] arr)

    StringArrayToStringWithSpace

    static java.lang.String StringArrayToStringWithSpace(java.lang.String[] arr)

    main

    public static void main(java.lang.String[] args)
                     throws java.lang.Exception
    Throws:
    java.lang.Exception