CostLineTemplateEvaluationPriorityComparator.java
package com.tradecloud.domain.costing.utils;
import com.tradecloud.domain.costing.CostLine;
import java.util.Comparator;
/**
* This comparator will get the evaluation priority field from the cost line template and sort it.
* If there is no evaluation priority, evaluationPriority = null, then it will be sorted to be at the end of the list.
*
* This was introduced as a solution to cost lines that rely on other cost lines' cost value.
*/
public class CostLineTemplateEvaluationPriorityComparator implements Comparator<CostLine> {
@Override
public int compare(CostLine o1, CostLine o2) {
// Want the nulls to be last
Integer i1 = o1.getCostLineTemplate().getEvaluationPriority();
Integer i2 = o2.getCostLineTemplate().getEvaluationPriority();
if (i1 != null && i2 != null) {
return i1.compareTo(i2);
} else if (i1 == null && i2 == null) {
return 0;
} else if (i1 != null) {
return -1;
} else if (i2 != null) {
return 1;
}
return 0;
}
}