org.amino.alg.sort
Class AbstractSorter

java.lang.Object
  extended by org.amino.alg.sort.AbstractSorter
All Implemented Interfaces:
Sorter
Direct Known Subclasses:
DefaultSorter

public abstract class AbstractSorter
extends java.lang.Object
implements Sorter

This is the abstract sorting class that implements the Sorter interface. The subclasses will provide the sort and reverse methods.


Constructor Summary
AbstractSorter()
           
 
Method Summary
 void reverse(byte[] a)
          Sort array using reverse natural (descending) order.
 void reverse(char[] a)
          Sort array using reverse natural (descending) order.
 void reverse(double[] a)
          Sort array using reverse natural (descending) order.
 void reverse(float[] a)
          Sort array using reverse natural (descending) order.
 void reverse(int[] a)
          Sort array using reverse natural (descending) order.
<T extends java.lang.Comparable<T>>
void
reverse(java.util.List<T> a)
          Sort List using reverse natural (descending) order.
 void reverse(long[] a)
          Sort array using reverse natural (descending) order.
 void reverse(short[] a)
          Sort array using reverse natural (descending) order.
<T extends java.lang.Comparable<T>>
void
reverse(T[] a)
          Sort array using reverse natural (descending) order.
 void sort(byte[] a)
           
 void sort(char[] a)
           
 void sort(double[] a)
           
 void sort(float[] a)
           
 void sort(int[] a)
           
<T extends java.lang.Comparable<T>>
void
sort(java.util.List<T> a)
          
<T extends java.lang.Comparable<T>>
void
sort(java.util.List<T> a, java.util.Comparator<T> c)
          
 void sort(long[] a)
           
 void sort(short[] a)
           
<T extends java.lang.Comparable<T>>
void
sort(T[] a)
          
<T extends java.lang.Comparable<T>>
void
sort(T[] a, java.util.Comparator<T> c)
          
protected static void swap(byte[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(char[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(double[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(float[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(int[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(long[] a, int i, int j)
          swap two specified positions in the array.
protected static void swap(short[] a, int i, int j)
          swap two specified positions in the array.
protected static
<T> void
swap(T[] a, int i, int j)
          swap two specified positions in the array.
protected static void swapIfGreater(byte[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(char[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(double[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(float[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(int[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(long[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfGreater(short[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static
<T extends java.lang.Comparable<T>>
void
swapIfGreater(T[] a, int i, int j)
          swap two specified positions in the array, if the first value is greater than the second one.
protected static void swapIfLess(byte[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(char[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(double[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(float[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(int[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(long[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static void swapIfLess(short[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
protected static
<T extends java.lang.Comparable<T>>
void
swapIfLess(T[] a, int i, int j)
          swap two specified positions in the array, if the first value is less than the second one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.amino.alg.sort.Sorter
reverse, reverse, reverse, reverse, reverse, reverse, reverse, reverse, reverse, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, sortp
 

Constructor Detail

AbstractSorter

public AbstractSorter()
Method Detail

sort

public void sort(byte[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the byte array to be sorted in an ascending order
See Also:
Arrays.sort(byte[])

sort

public void sort(char[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the character array to be sorted in an ascending order
See Also:
Arrays.sort(byte[])

sort

public void sort(short[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the short array to be sorted in an ascending order
See Also:
Arrays.sort(short[])

sort

public void sort(int[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the int array to be sorted in an ascending order
See Also:
Arrays.sort(short[])

sort

public void sort(long[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the long array to be sorted in an ascending order
See Also:
Arrays.sort(short[])

sort

public void sort(float[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the float array to be sorted in an ascending order
See Also:
Arrays.sort(short[])

sort

public void sort(double[] a)
Specified by:
sort in interface Sorter
Parameters:
a - is the double array to be sorted in an ascending order
See Also:
Arrays.sort(short[])

reverse

public void reverse(byte[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the byte array to be sorted in a descending order

reverse

public void reverse(char[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the character array to be sorted in a descending order

reverse

public void reverse(short[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the short array to be sorted in a descending order

reverse

public void reverse(int[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the int array to be sorted in a descending order

reverse

public void reverse(long[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the long array to be sorted in a descending order

reverse

public void reverse(float[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the float array to be sorted in a descending order

reverse

public void reverse(double[] a)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Parameters:
a - is the double array to be sorted in a descending order

sort

public <T extends java.lang.Comparable<T>> void sort(T[] a)

Specified by:
sort in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.
See Also:
Arrays.sort(Object[])

sort

public <T extends java.lang.Comparable<T>> void sort(T[] a,
                                                     java.util.Comparator<T> c)

Specified by:
sort in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.
c - comparator used to do comparison
See Also:
Arrays.sort(Object[], Comparator)

reverse

public <T extends java.lang.Comparable<T>> void reverse(T[] a)
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.

sort

public <T extends java.lang.Comparable<T>> void sort(java.util.List<T> a)

Specified by:
sort in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.
See Also:
Collections.sort(List)

sort

public <T extends java.lang.Comparable<T>> void sort(java.util.List<T> a,
                                                     java.util.Comparator<T> c)

Specified by:
sort in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.
c - comparator used to do comparison
See Also:
Collections.sort(List, Comparator)

reverse

public <T extends java.lang.Comparable<T>> void reverse(java.util.List<T> a)
Sort List using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Type Parameters:
T - data type
Parameters:
a - array upon which to operate.

swap

protected static void swap(byte[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(byte[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(byte[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(char[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(char[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(char[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(short[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(short[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(short[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(int[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(int[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(int[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(long[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(long[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(long[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(float[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(float[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(float[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static void swap(double[] a,
                           int i,
                           int j)
swap two specified positions in the array.

Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static void swapIfGreater(double[] a,
                                    int i,
                                    int j)
swap two specified positions in the array, if the first value is greater than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static void swapIfLess(double[] a,
                                 int i,
                                 int j)
swap two specified positions in the array, if the first value is less than the second one.

Parameters:
a - the array
i - the first position
j - the second position

swap

protected static <T> void swap(T[] a,
                               int i,
                               int j)
swap two specified positions in the array.

Type Parameters:
T - data type
Parameters:
a - the array
i - the first position
j - the second position

swapIfGreater

protected static <T extends java.lang.Comparable<T>> void swapIfGreater(T[] a,
                                                                        int i,
                                                                        int j)
swap two specified positions in the array, if the first value is greater than the second one.

Type Parameters:
T - data type
Parameters:
a - the array
i - the first position
j - the second position

swapIfLess

protected static <T extends java.lang.Comparable<T>> void swapIfLess(T[] a,
                                                                     int i,
                                                                     int j)
swap two specified positions in the array, if the first value is less than the second one.

Type Parameters:
T - data type
Parameters:
a - the array
i - the first position
j - the second position


Copyright © 2008. All Rights Reserved.