feisty meow concerns codebase  2.140
ZSorter.java
Go to the documentation of this file.
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 
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 
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 }