Search in sources :

Example 1 with ComparisonChain

use of com.google.common.collect.ComparisonChain in project kylo by Teradata.

the class JpaServiceLevelAssessment method compareTo.

@Override
public int compareTo(ServiceLevelAssessment sla) {
    ComparisonChain chain = ComparisonChain.start().compare(this.getResult(), sla.getResult()).compare(this.getAgreement().getName(), sla.getAgreement().getName());
    if (chain.result() != 0) {
        return chain.result();
    }
    List<ObligationAssessment> list1 = new ArrayList<>(this.getObligationAssessments());
    List<ObligationAssessment> list2 = new ArrayList<>(sla.getObligationAssessments());
    chain = chain.compare(list1.size(), list2.size());
    Collections.sort(list1);
    Collections.sort(list2);
    for (int idx = 0; idx < list1.size(); idx++) {
        chain = chain.compare(list1.get(idx), list2.get(idx));
    }
    return chain.result();
}
Also used : ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) ArrayList(java.util.ArrayList) ComparisonChain(com.google.common.collect.ComparisonChain)

Example 2 with ComparisonChain

use of com.google.common.collect.ComparisonChain in project kylo by Teradata.

the class SimpleServiceLevelAssessment method compareTo.

@Override
public int compareTo(ServiceLevelAssessment sla) {
    ComparisonChain chain = ComparisonChain.start().compare(this.getResult(), sla.getResult()).compare(this.getAgreement().getName(), sla.getAgreement().getName());
    if (chain.result() != 0) {
        return chain.result();
    }
    List<ObligationAssessment> list1 = new ArrayList<>(this.getObligationAssessments());
    List<ObligationAssessment> list2 = new ArrayList<>(sla.getObligationAssessments());
    chain = chain.compare(list1.size(), list2.size());
    Collections.sort(list1);
    Collections.sort(list2);
    for (int idx = 0; idx < list1.size(); idx++) {
        chain = chain.compare(list1.get(idx), list2.get(idx));
    }
    return chain.result();
}
Also used : ObligationAssessment(com.thinkbiganalytics.metadata.sla.api.ObligationAssessment) ArrayList(java.util.ArrayList) ComparisonChain(com.google.common.collect.ComparisonChain)

Example 3 with ComparisonChain

use of com.google.common.collect.ComparisonChain in project buck by facebook.

the class RDotTxtEntry method compareTo.

/**
   * A collection of Resources should be sorted such that Resources of the same type should be
   * grouped together, and should be alphabetized within that group.
   */
@Override
public int compareTo(RDotTxtEntry that) {
    if (this == that) {
        return 0;
    }
    ComparisonChain comparisonChain = ComparisonChain.start().compare(this.type, that.type);
    String[] thisNameParts = this.name.split("_");
    String[] thatNameParts = that.name.split("_");
    int index = 0;
    while (index < thisNameParts.length && index < thatNameParts.length) {
        comparisonChain = comparisonChain.compare(thisNameParts[index], thatNameParts[index]);
        index++;
    }
    if (index < thisNameParts.length || index < thatNameParts.length) {
        comparisonChain = comparisonChain.compare(thisNameParts.length, thatNameParts.length);
    }
    return comparisonChain.result();
}
Also used : ComparisonChain(com.google.common.collect.ComparisonChain)

Aggregations

ComparisonChain (com.google.common.collect.ComparisonChain)3 ObligationAssessment (com.thinkbiganalytics.metadata.sla.api.ObligationAssessment)2 ArrayList (java.util.ArrayList)2