
/*
  A wrapper for some common sorting/filtering methods etc, mostly using java.util.Collections
 */

public static class TransactionUtils
{

  //sort a List of transactions by the title
  public static void sortTransactionsByTitle(ArrayList transactions)
  {
    Collections.sort(transactions, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        Transaction t1 = (Transaction) o1;
        Transaction t2 = (Transaction) o2;

        return t1.title.compareToIgnoreCase(t2.title);
      }
    }
    );
  }


  public static void sortWords(HashMap words)
  {
    Iterator it,rit;
    Map.Entry me;
    Word w, rwo;
    String rw;
    float x, y, z, ztheta, ytheta, xint, zint;
    float rx,ry,rz; 
    int r;
    sortedWords.clear();
    r = 10;
    x = 0.0;
    y = 0.0;
    z = 0.0;
    ztheta = 16*PI/count;
    ytheta = PI/8;
    xint = 0;
    zint = 0;
    int rounds = 0;
    it = words.entrySet().iterator();  // Get an iterator
    //skim through the word set and add it to an array list
    Random rand = new Random();
    while(it.hasNext()){
      rounds++;
      me = (Map.Entry)it.next();
      w = (Word) me.getValue();
      if(w.totFreq > MINVALUE){
        sortedWords.add(w); 



        //      rx = rand.nextFloat()*2 - 1.0;
        //      ry = rand.nextFloat()*2 - 1.0;
        //      rz = rand.nextFloat()*2 - 1.0;
        //
        //      PVector k = new PVector(rx,ry,rz);
        //      k.normalize(); 
        //      k.mult(r*w.nConnects); 
        //
        //      xint = PI*rand.nextFloat();
        //      zint = 2*PI*rand.nextFloat();
        //
        //      w.p.x = k.x;
        //      w.p.y = k.y;
        //      w.p.z = k.z;

        rx = rand.nextFloat()*1600-800;
        ry = rand.nextFloat()*1200-600;
        rz = rand.nextFloat()*1200-600;

        //PVector k = new PVector(rx,ry,rz);
        w.x = rx;
        w.y = ry;
        w.z = rz;




      }
    }


    Collections.sort(sortedWords, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        Word t1 = (Word) o1;
        Word t2 = (Word) o2;

        return t1.word.compareToIgnoreCase(t2.word);
      }
    }
    );
  }

  //called when sorting by most popular
  public static void sortValues(HashMap words)
  {
    int rTemp = 0;
    Iterator it;
    Map.Entry me;
    Word w;

    //skim through the word set and add it to an array list
    float x, y, z, ztheta, ytheta, xint, zint;
    int r;
    r = 300;
    x = 0.0;
    y = 0.0;
    z = 0.0;
    xint = 20;

    sortedWords.clear();
    it = words.entrySet().iterator();  // Get an iterator

      while(it.hasNext()){
      me = (Map.Entry)it.next();
      w = (Word) me.getValue();
      if(w.totFreq > MINVALUE){
        sortedWords.add(w); 
        w.x = xint%8;
        w.y = xint%4;
        w.z = 0;
        xint += 20;
      }
    }


    Collections.sort(sortedWords, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        Word t1 = (Word) o1;
        Word t2 = (Word) o2;
        return t2.totFreq - t1.totFreq;
      }
    }
    );
  }


}



