adapted to new storage location
[feisty_meow.git] / kona / src / org / feistymeow / example / ZSorter.java
1 package org.feistymeow.example;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.List;
7
8 public class ZSorter<T extends Comparable<? super T>> {
9
10         /**
11          * returns a new list which is the sorted version of the input
12          * list "toSort".
13          */
14         public List<T> sort(List<T> toSort) {
15                 List<T> toReturn = new ArrayList<T>(toSort);
16                 Collections.copy(toReturn, toSort);
17                 Collections.sort(toReturn);
18                 return toReturn;
19         }
20
21         /**
22          * simple console printer for list of T.
23          */
24         public void print(List<T> toPrint) {
25                 boolean first = true;
26                 for (T curr: toPrint) {
27                         if (!first) System.out.print(", ");
28                         first = false;
29                         System.out.print(curr);
30                 }
31                 System.out.println();
32         }
33         
34         public static void main(String[] args) {
35                 ZSorter<Integer> sorter = new ZSorter<Integer>();
36                 
37                 List<Integer> theList
38                         = new ArrayList<Integer>(Arrays.asList(101, 19, 86, 72, 56, 35, 47));
39                 System.out.println("prior to sorting:");
40                 sorter.print(theList);
41
42                 // test our sort method.
43                 List<Integer> newList = sorter.sort(theList);
44                 System.out.println("after sorting:");
45                 sorter.print(newList);
46         }
47 }