FileDocCategorySizeDatePackage
Sorter.javaAPI DocJBoss 4.2.12837Fri Jul 13 21:02:22 BST 2007test.dbc.java

Sorter

public class Sorter extends Object
author
Kabir Khan
version
$Revision: 57186 $
@org.jboss.aspects.dbc.Dbc

Fields Summary
Constructors Summary
Methods Summary
public static int[]brokenSort(int[] unsorted)
This will break the post condition

@org.jboss.aspects.dbc.PostCond
({"java: for (int i = 0 ; i < $rtn.length ; i++){if (i > 0){if ($rtn[i] < $rtn[i - 1])return false;}}return true;"})

      return unsorted;
   
public static int[]sort(int[] unsorted)
Returns the original array with all the elements sorted incrementally

@org.jboss.aspects.dbc.PostCond
({"$rtn.length == $0.length", "java: for (int i = 0 ; i < $rtn.length ; i++){if (i > 0){if ($rtn[i] < $rtn[i - 1])return false;}}return true;"})

      //Not the most efficient sorting algorithm in the world, but hey
      ArrayList list = new ArrayList();
      
      for (int i = 0 ; i < unsorted.length ; i++)
      {
         list.add(new Integer(unsorted[i]));
      }
      
      Collections.sort(list, 
            new Comparator()
            {
         		public boolean equals(Object obj)
         		{
         		   return false;
         		}

         		public int compare(Object o1, Object o2)
         		{
         		   int i1 = ((Integer)o1).intValue();
         		   int i2 = ((Integer)o2).intValue();
         		   
         		   if (i1 < i2)return -1;
         		   if (i1 == i2)return 0;
         		   return 1;
         		}
            });
      
      int[] sorted = new int[unsorted.length];
      for (int i = 0 ; i < list.size() ; i++)
      {
         sorted[i] = ((Integer)list.get(i)).intValue();
      }
      return sorted;