Example usage for java.util Objects compare

List of usage examples for java.util Objects compare

Introduction

In this page you can find the example usage for java.util Objects compare.

Prototype

public static <T> int compare(T a, T b, Comparator<? super T> c) 

Source Link

Document

Returns 0 if the arguments are identical and c.compare(a, b) otherwise.

Usage

From source file:ch.algotrader.service.ManagementServiceImpl.java

/**
 * {@inheritDoc}//  w  ww .  ja v a 2 s .  co m
 */
@Override
@ManagedAttribute(description = "Gets current open Orders")
public Collection<OrderStatusVO> getDataOrders() {
    List<OrderDetailsVO> openOrders = this.orderService.getOpenOrderDetails();
    Collections.sort(openOrders, (o1, o2) -> Objects.compare(o1.getOrder().getDateTime(),
            o2.getOrder().getDateTime(), Date::compareTo));
    return convert(openOrders);
}

From source file:org.caleydo.datadomain.pathway.manager.EPathwayDatabaseType.java

@Override
public int compareTo(EPathwayDatabaseType o) {
    return Objects.compare(name, o.name, String.CASE_INSENSITIVE_ORDER);
}

From source file:org.caleydo.view.domino.internal.data.LabelDataValues.java

@Override
public int compare(EDimension dim, int a, int b, ITypedCollection otherData) {
    String av = get(a);/*from w w w. ja  v  a 2 s.c  o  m*/
    String bv = get(b);
    return Objects.compare(av, bv, String.CASE_INSENSITIVE_ORDER);
}

From source file:org.kuali.coeus.common.budget.impl.calculator.SalaryCalculator.java

private QueryList<BudgetRate> filterInflationRates() {
    if (personnelLineItem.getApplyInRateFlag()) {
        final CostElement costElement = getCostElement(personnelLineItem);
        final ValidCeRateType inflationRateType = costElement.getValidCeRateTypes().stream()
                .filter(t -> t.getRateClassType().equals(RateClassType.INFLATION.getRateClassType()))
                .findFirst().get();//  w w  w  . j  a  v a 2  s . co m

        final Predicate<BudgetRate> dateAndRateAndOnOffCampusFlag = budgetRate -> {
            final boolean iInflationRCEquals = StringUtils.equals(inflationRateType.getRateClassCode(),
                    budgetRate.getRateClassCode());
            final boolean iInflationRTEquals = StringUtils.equals(inflationRateType.getRateTypeCode(),
                    budgetRate.getRateTypeCode());
            final boolean startDateLtEqualsEndDate = Objects.compare(budgetRate.getStartDate(), this.endDate,
                    Comparator.<Date>naturalOrder()) <= 0;
            final boolean startDateGtEqualsStartDate = Objects.compare(budgetRate.getStartDate(),
                    this.startDate, Comparator.<Date>naturalOrder()) >= 0;
            final boolean onOffCampusEquals = Objects.equals(costElement.getOnOffCampusFlag(),
                    budgetRate.getOnOffCampusFlag());
            return iInflationRCEquals && iInflationRTEquals && startDateLtEqualsEndDate
                    && startDateGtEqualsStartDate && onOffCampusEquals;
        };

        return new QueryList<>(
                (getInflationRates() == null ? getBudgetRates().stream().filter(dateAndRateAndOnOffCampusFlag)
                        : getInflationRates().stream().filter(dateAndRateAndOnOffCampusFlag))
                                .collect(Collectors.toList()));
    } else {
        return new QueryList<>();
    }

}

From source file:org.kuali.coeus.common.budget.impl.calculator.SalaryCalculator.java

private QueryList<BudgetPerson> filterBudgetPersons() {

    final List<BudgetPerson> persons = budget.getBudgetPersons();
    if (persons.isEmpty()) {
        return new QueryList<>();
    }/*from   ww  w .  ja v  a2  s  .  co  m*/

    final Optional<BudgetPerson> first = persons.stream().filter(
            person -> person.getPersonSequenceNumber().equals(personnelLineItem.getPersonSequenceNumber()))
            .findFirst();
    if (!first.isPresent()) {
        return new QueryList<>();
    }

    final List<BudgetPerson> filteredPersons = persons.stream().filter(person -> {
        final boolean personIdEquals = StringUtils.equals(person.getPersonId(), first.get().getPersonId());
        final boolean jobCodeEquals = StringUtils.equals(person.getJobCode(), first.get().getJobCode());
        final boolean rolodexIdEquals = Objects.equals(person.getRolodexId(), first.get().getRolodexId());
        final boolean effectiveDateLtEqualsEndDate = Objects.compare(person.getEffectiveDate(), this.endDate,
                Comparator.<Date>naturalOrder()) <= 0;
        return personIdEquals && jobCodeEquals && rolodexIdEquals && effectiveDateLtEqualsEndDate;
    }).collect(Collectors.toList());

    final Optional<BudgetPerson> tmpFirst = filteredPersons.stream().filter(person -> {
        final boolean effectiveDateLtEqualsStartDate = Objects.compare(person.getEffectiveDate(),
                this.startDate, Comparator.<Date>naturalOrder()) <= 0;
        final boolean effectiveDateEquals = Objects.compare(person.getEffectiveDate(),
                first.get().getEffectiveDate(), Comparator.<java.sql.Date>naturalOrder()) == 0;
        final boolean seqNotEquals = person.getPersonSequenceNumber().intValue() != first.get()
                .getPersonSequenceNumber();
        return effectiveDateLtEqualsStartDate && !(effectiveDateEquals && seqNotEquals);
    }).sorted(Comparator.comparing(BudgetPerson::getEffectiveDate).reversed()).findFirst();

    if (tmpFirst.isPresent()) {
        filteredPersons.clear();
        filteredPersons.add(tmpFirst.get());
    } else {
        StringBuilder warningMsg = new StringBuilder(
                "Base salary information is not available for the person ");
        StringBuilder errMsg = new StringBuilder("Error finding the calculation base for the person ");
        errMsg.append(this.personnelLineItem.getPersonId());
        errMsg.append(" with Job Code ");
        errMsg.append(this.personnelLineItem.getJobCode());

        warningMsg.append(this.personnelLineItem.getPersonId());
        warningMsg.append(" with Job Code ");
        warningMsg.append(this.personnelLineItem.getJobCode());
        warningMsg.append(" for the period ");
        warningMsg.append(dateTimeService.toDateString(startDate));
        warningMsg.append(" to ");
        if (!filteredPersons.isEmpty()) {
            warningMsg.append(dateTimeService.toDateString(add(filteredPersons.get(0).getEffectiveDate(), -1)));
        } else {
            warningMsg.append(dateTimeService.toDateString(personnelLineItem.getEndDate()));
        }
        warningMsg.append("\n");
        warningMsg.append("Salary for this period will be set to 0\n");
        warningMsg.append("Please make changes to budget person details and recalculate the budget");
        warningList.add(warningMsg.toString());
        errorList.add(errMsg.toString());
    }

    return new QueryList<>(filteredPersons);
}

From source file:org.xlrnet.tibaija.util.ComplexComparator.java

@Override
public int compare(Complex o1, Complex o2) {
    boolean isNoneImaginary = o1.getImaginary() == 0 && o2.getImaginary() == 0;
    boolean isNoneReal = o1.getReal() == 0 && o2.getReal() == 0;

    if (isNoneImaginary && isNoneReal) // Comparison of zero and zero -> equal
        return 0;

    if (!isNoneImaginary && !isNoneReal) // Comparison of complex and imaginary 
        throw new UnsupportedOperationException(
                "Comparison of complex numbers with imaginary part is not allowed");
    if (isNoneImaginary)
        return Objects.compare(o1.getReal(), o2.getReal(), Comparator.naturalOrder());
    else// w  w  w .  j  a va2s .  c om
        return Objects.compare(o1.getImaginary(), o2.getImaginary(), Comparator.naturalOrder());
}