0.8
Sorting media using crowdsourcing.   
Doxygen
LIRIS

Comparator.java

Go to the documentation of this file.
00001 package sorter;
00002 
00003 import java.util.*;
00004 import myDataBases.MySQLbase;
00005 
00006 
00019 public class Comparator
00020 {
00021 
00022       00023       // Fields
00024       00025 
00030       private Map<String,SplitSort> sorters;
00034       private MySQLbase sqlBase;
00035       
00036       
00037       00038       // Constructors
00039       00040 
00051       public Comparator( Map<String,SplitSort> sorter, myDataBases.MySQLbase bdd )
00052       {
00053             this.sorters = sorter;
00054             this.sqlBase = bdd;
00055       }
00056 
00057 
00067       public Comparator( Map<String,SplitSort> sorter )
00068       {
00069             this.sorters = sorter;
00070       }     
00071       
00072       00073       // Methods
00074       00075       
00084       public Boolean notFinished()
00085       {
00086             Boolean result = false;
00087             for (Iterator<String> str = this.sorters.keySet().iterator(); str.hasNext();)
00088                   if (this.sorters.get(str.next()).notFinished() == true)
00089                   {
00090                         result = true;
00091                         break;
00092                   }
00093             return result;
00094       }
00095 
00096   
00103       public void sortIteration( )
00104       {
00105             for (Iterator<String> str = this.sorters.keySet().iterator(); str.hasNext();)
00106             {
00107                   String axis = str.next();
00108                   if (this.sorters.get(axis).notFinished())
00109                         this.sorters.get(axis).iteration();
00110             }
00111       }
00112 
00113 
00120       public void endIteration(  )
00121       {
00122             List<Boolean> comparisons = new ArrayList<Boolean>();
00123             List<Integer> greater = new ArrayList<Integer>();
00124             List<Integer> smaller = new ArrayList<Integer>();  
00125             for (String axis : this.sorters.keySet() )
00126             {
00127                   comparisons.clear();
00128                   greater = this.sorters.get(axis).getGreater();
00129                   smaller = this.sorters.get(axis).getSmaller();
00130                   for (int i=0; i<greater.size(); i++)
00131                         if (greater.get(i) == smaller.get(i))
00132                               comparisons.add(false);
00133                         else
00134                               comparisons.add( this.sqlBase.comparisonResult(greater.get(i),smaller.get(i),axis) );
00135                   this.sorters.get(axis).endIteration(comparisons);
00136             }
00137       }
00138 
00139 
00140 
00153       public void demandNewComparisons( List<Integer> greater, List<Integer> smaller, List<String> axes)
00154       {
00155             List<Integer> sortGreater = new ArrayList<Integer>();
00156             List<Integer> sortSmaller = new ArrayList<Integer>();
00157             greater.clear();
00158             smaller.clear();
00159             axes.clear();
00160             
00161             for (Iterator<String> str = this.sorters.keySet().iterator(); str.hasNext();)
00162             {
00163                   String emotion = str.next();
00164                   sortGreater = this.sorters.get(emotion).getGreater();
00165                   sortSmaller = this.sorters.get(emotion).getSmaller();
00166                   for (int i=0; i<sortGreater.size(); i++)
00167                         if ( sortGreater.get(i) != sortSmaller.get(i) )
00168                               if (this.sqlBase.alreadyDone(sortGreater.get(i), sortSmaller.get(i),emotion) == false)
00169                               {
00170                                     greater.add(sortGreater.get(i));
00171                                     smaller.add(sortSmaller.get(i));
00172                                     axes.add(emotion);
00173                               }
00174             }
00175       }
00176       
00177 
00181       public void display()
00182       {
00183             for (String axis : this.sorters.keySet())
00184             {
00185                   System.out.println("\n"+axis);
00186                   this.sorters.get(axis).display();
00187             }
00188       }
00189       00190       // Accessor methods
00191       00192 
00199       public Map<String,SplitSort> getSplitSorts()
00200       {  return this.sorters;  }
00201 
00202       
00209       public Map<String, List<Integer[]> > getCurrentState()
00210       {
00211             Map<String, List<Integer[]>> state = new Hashtable<String, List<Integer[]>>() ;
00212             for(String axis : this.sorters.keySet())
00213                   state.put(axis, this.sorters.get(axis).getSorted());
00214             return state;
00215       }
00216 }
00217       
 All Classes Namespaces Files Functions Variables