class MyComparator implements Comparator<Object> {
public int compare(Object o1, Object o2)
{
Experiment c1 = (Experiment) o1;
Experiment c2 = (Experiment) o2;
if (column == null)
{
return 0;
}
if (column.equals("name"))
{
return ascending ? c1.getExperimentSetup().getBasicProperties().getExperimentName().compareToIgnoreCase(c2.getExperimentSetup().getBasicProperties().getExperimentName()) : c2.getExperimentSetup().getBasicProperties().getExperimentName()
.compareToIgnoreCase(c1.getExperimentSetup().getBasicProperties().getExperimentName());
}
if (column.equals("type"))
{
String c1_type = c1.getExperimentSetup().getExperimentTypeName();
String c2_type = c2.getExperimentSetup().getExperimentTypeName();
if (c1_type==null) c1_type="";
if (c2_type==null) c2_type="";
return ascending ? c1_type.compareTo(c2_type) : c2_type.compareTo(c1_type);
}
if (column.equals("experimenter"))
{
return ascending ? c1.getExperimentSetup().getBasicProperties().getExperimenter().compareTo(c2.getExperimentSetup().getBasicProperties().getExperimenter()) : c2.getExperimentSetup().getBasicProperties().getExperimenter()
.compareTo(c1.getExperimentSetup().getBasicProperties().getExperimenter());
}
if (column.equals("startDate"))
{
Date c1_startDate = null;
if( c1.getStartDate() != null )
c1_startDate = c1.getStartDate().getTime();
Date c2_startDate = null;
if( c2.getStartDate() != null )
c2_startDate = c2.getStartDate().getTime();
if (c1_startDate==null) c1_startDate=Calendar.getInstance().getTime();
if (c2_startDate==null) c2_startDate=Calendar.getInstance().getTime();
return ascending ? c1_startDate.compareTo(c2_startDate) : c2_startDate.compareTo(c1_startDate);
}
if (column.equals("exDate"))
{
Date c1_exDate = null;
if( c1.getExperimentExecutable().getExecutionEndDate() != null )
c1_exDate = c1.getExperimentExecutable().getExecutionEndDate().getTime();
Date c2_exDate = null;
if( c2.getExperimentExecutable().getExecutionEndDate() != null )
c2_exDate = c2.getExperimentExecutable().getExecutionEndDate().getTime();
if (c1_exDate==null) c1_exDate=Calendar.getInstance().getTime();
if (c2_exDate==null) c2_exDate=Calendar.getInstance().getTime();
return ascending ? c1_exDate.compareTo(c2_exDate) : c2_exDate.compareTo(c1_exDate);
}
if (column.equals("currentStage"))
{
if ((c1.getCurrentPhase() != null) && (c2.getCurrentPhase() != null)) {
return ascending ? new Integer(c1.getCurrentPhaseIndex()).compareTo(new Integer(c2.getCurrentPhaseIndex()))
: new Integer(c2.getCurrentPhaseIndex()).compareTo(new Integer(c1.getCurrentPhaseIndex()));
}
else
return 0;
}
if( column.equals("numOfInputs"))
{
if( c1.getExperimentExecutable() != null && c2.getExperimentExecutable() != null ) {
return ascending ? new Integer( c1.getExperimentExecutable().getNumberOfInputs()).compareTo(new Integer( c2.getExperimentExecutable().getNumberOfInputs()))
: new Integer( c2.getExperimentExecutable().getNumberOfInputs()).compareTo(new Integer( c1.getExperimentExecutable().getNumberOfInputs()));
}
else
return 0;
}
if (column.equals("relevance"))
{
return ascending ? new Integer( c2.getAverageUserExperimentRatings()).compareTo(new Integer( c1.getAverageUserExperimentRatings()))
: new Integer( c1.getAverageUserExperimentRatings()).compareTo(new Integer( c2.getAverageUserExperimentRatings()));
}
else
return 0;
}