Example usage for com.google.common.collect Ordering immutableSortedCopy

List of usage examples for com.google.common.collect Ordering immutableSortedCopy

Introduction

In this page you can find the example usage for com.google.common.collect Ordering immutableSortedCopy.

Prototype

public <E extends T> ImmutableList<E> immutableSortedCopy(Iterable<E> elements) 

Source Link

Document

Returns an immutable list containing elements sorted by this ordering.

Usage

From source file:org.killbill.billing.payment.core.DirectPaymentProcessor.java

private DirectPayment toDirectPayment(final DirectPaymentModelDao curDirectPaymentModelDao,
        final Iterable<DirectPaymentTransactionModelDao> transactionsModelDao,
        @Nullable final PaymentInfoPlugin pluginInfo) {
    final Ordering<DirectPaymentTransaction> perPaymentTransactionOrdering = Ordering
            .<DirectPaymentTransaction>from(new Comparator<DirectPaymentTransaction>() {
                @Override//from  w ww  .  j a  v  a2s. co m
                public int compare(final DirectPaymentTransaction o1, final DirectPaymentTransaction o2) {
                    return o1.getEffectiveDate().compareTo(o2.getEffectiveDate());
                }
            });

    final Iterable<DirectPaymentTransactionModelDao> filteredTransactions = Iterables
            .filter(transactionsModelDao, new Predicate<DirectPaymentTransactionModelDao>() {
                @Override
                public boolean apply(
                        final DirectPaymentTransactionModelDao curDirectPaymentTransactionModelDao) {
                    return curDirectPaymentTransactionModelDao.getDirectPaymentId()
                            .equals(curDirectPaymentModelDao.getId());
                }
            });

    final Iterable<DirectPaymentTransaction> transactions = Iterables.transform(filteredTransactions,
            new Function<DirectPaymentTransactionModelDao, DirectPaymentTransaction>() {
                @Override
                public DirectPaymentTransaction apply(final DirectPaymentTransactionModelDao input) {
                    return new DefaultDirectPaymentTransaction(input.getId(), input.getCreatedDate(),
                            input.getUpdatedDate(), input.getDirectPaymentId(), input.getTransactionType(),
                            input.getEffectiveDate(), 0, input.getPaymentStatus(), input.getAmount(),
                            input.getCurrency(), input.getGatewayErrorCode(), input.getGatewayErrorMsg(),
                            pluginInfo);
                }
            });

    final List<DirectPaymentTransaction> sortedTransactions = perPaymentTransactionOrdering
            .immutableSortedCopy(transactions);
    return new DefaultDirectPayment(curDirectPaymentModelDao.getId(), curDirectPaymentModelDao.getCreatedDate(),
            curDirectPaymentModelDao.getUpdatedDate(), curDirectPaymentModelDao.getAccountId(),
            curDirectPaymentModelDao.getPaymentMethodId(), curDirectPaymentModelDao.getPaymentNumber(),
            curDirectPaymentModelDao.getExternalKey(), sortedTransactions);
}