Search in sources :

Example 36 with Comparator

use of java.util.Comparator in project head by mifos.

the class CollectionSheetDaoHibernate method findAllLoanRepaymentsForCustomerHierarchy.

/*
     *
     */
@Override
@SuppressWarnings("unchecked")
public Map<Integer, List<CollectionSheetCustomerLoanDto>> findAllLoanRepaymentsForCustomerHierarchy(final Short branchId, final String searchId, final LocalDate transactionDate, final Integer customerAtTopOfHierarchyId) {
    final Map<Integer, List<CollectionSheetCustomerLoanDto>> allLoanRepaymentsGroupedByCustomerId = new HashMap<Integer, List<CollectionSheetCustomerLoanDto>>();
    final Map<String, Object> topOfHierarchyParameters = new HashMap<String, Object>();
    topOfHierarchyParameters.put("BRANCH_ID", branchId);
    topOfHierarchyParameters.put("CUSTOMER_ID", customerAtTopOfHierarchyId);
    topOfHierarchyParameters.put("TRANSACTION_DATE", transactionDate.toString());
    final List<CollectionSheetCustomerLoanDto> loanRepaymentsForCustomerAtTopOfHierarchy = executeNamedQueryWithResultTransformer("findLoanRepaymentsforCustomerAtTopOfHierarchyAsDto", topOfHierarchyParameters, CollectionSheetCustomerLoanDto.class);
    if (loanRepaymentsForCustomerAtTopOfHierarchy != null) {
        allLoanRepaymentsGroupedByCustomerId.put(customerAtTopOfHierarchyId, loanRepaymentsForCustomerAtTopOfHierarchy);
    }
    final Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("BRANCH_ID", branchId);
    queryParameters.put("SEARCH_ID", searchId);
    queryParameters.put("TRANSACTION_DATE", transactionDate.toString());
    final List<CollectionSheetCustomerLoanDto> loanRepayments = executeNamedQueryWithResultTransformer("findLoanRepaymentsforCustomerHierarchyAsDto", queryParameters, CollectionSheetCustomerLoanDto.class);
    for (CollectionSheetCustomerLoanDto customerLoan : loanRepayments) {
        final Integer customerId = customerLoan.getCustomerId();
        if (allLoanRepaymentsGroupedByCustomerId.containsKey(customerId)) {
            final List<CollectionSheetCustomerLoanDto> loansForCustomer = allLoanRepaymentsGroupedByCustomerId.get(customerId);
            Comparator<CollectionSheetCustomerLoanDto> comparator = new Comparator<CollectionSheetCustomerLoanDto>() {

                @Override
                public int compare(CollectionSheetCustomerLoanDto cseDto1, CollectionSheetCustomerLoanDto cseDto2) {
                    return cseDto1.getAccountId().compareTo(cseDto2.getAccountId());
                }
            };
            Collections.sort(loansForCustomer, comparator);
            if (Collections.binarySearch(loansForCustomer, customerLoan, comparator) < 0) {
                loansForCustomer.add(customerLoan);
            }
        } else {
            final List<CollectionSheetCustomerLoanDto> customerLoansForCustomer = new ArrayList<CollectionSheetCustomerLoanDto>();
            customerLoansForCustomer.add(customerLoan);
            allLoanRepaymentsGroupedByCustomerId.put(customerId, customerLoansForCustomer);
        }
    }
    addInformationAboutActiveLoans(allLoanRepaymentsGroupedByCustomerId, queryParameters);
    return allLoanRepaymentsGroupedByCustomerId;
}
Also used : HashMap(java.util.HashMap) CollectionSheetCustomerLoanDto(org.mifos.application.servicefacade.CollectionSheetCustomerLoanDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Comparator(java.util.Comparator)

Example 37 with Comparator

use of java.util.Comparator in project head by mifos.

the class CollectionSheetDaoHibernate method findAccountCollectionsOnCustomerAccount.

@Override
@SuppressWarnings("unchecked")
public Map<Integer, List<CollectionSheetCustomerAccountCollectionDto>> findAccountCollectionsOnCustomerAccount(final Short branchId, final String searchId, final LocalDate transactionDate, final Integer customerAtTopOfHierarchyId) {
    final Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("CUSTOMER_ID", customerAtTopOfHierarchyId);
    queryParameters.put("TRANSACTION_DATE", transactionDate.toString());
    final Map<Integer, List<CollectionSheetCustomerAccountCollectionDto>> accountCollectionsOnCustomerAccountGroupedByCustomerId = new HashMap<Integer, List<CollectionSheetCustomerAccountCollectionDto>>();
    CollectionSheetCustomerAccountCollectionDto accountCollectionFeeForHierarchyCustomer = execUniqueResultNamedQueryWithResultTransformer("findAccountCollectionsOnCustomerAccountForTopCustomerOfHierarchy", queryParameters, CollectionSheetCustomerAccountCollectionDto.class);
    if (accountCollectionFeeForHierarchyCustomer != null) {
        accountCollectionsOnCustomerAccountGroupedByCustomerId.put(customerAtTopOfHierarchyId, Arrays.asList(accountCollectionFeeForHierarchyCustomer));
    }
    final Map<String, Object> withinHierarchyQueryParameters = new HashMap<String, Object>();
    withinHierarchyQueryParameters.put("BRANCH_ID", branchId);
    withinHierarchyQueryParameters.put("SEARCH_ID", searchId);
    withinHierarchyQueryParameters.put("TRANSACTION_DATE", transactionDate.toString());
    final List<CollectionSheetCustomerAccountCollectionDto> customerAccountFees = executeNamedQueryWithResultTransformer("findAccountCollectionsOnCustomerAccountForCustomerHierarchyAsDto", withinHierarchyQueryParameters, CollectionSheetCustomerAccountCollectionDto.class);
    for (CollectionSheetCustomerAccountCollectionDto accountCollectionFee : customerAccountFees) {
        final Integer customerId = accountCollectionFee.getCustomerId();
        if (accountCollectionsOnCustomerAccountGroupedByCustomerId.containsKey(customerId)) {
            final List<CollectionSheetCustomerAccountCollectionDto> customerAccountFeesList = accountCollectionsOnCustomerAccountGroupedByCustomerId.get(customerId);
            Comparator<CollectionSheetCustomerAccountCollectionDto> comparator = new Comparator<CollectionSheetCustomerAccountCollectionDto>() {

                @Override
                public int compare(CollectionSheetCustomerAccountCollectionDto cseDto1, CollectionSheetCustomerAccountCollectionDto cseDto2) {
                    return cseDto1.getAccountId().compareTo(cseDto2.getAccountId());
                }
            };
            Collections.sort(customerAccountFeesList, comparator);
            if (Collections.binarySearch(customerAccountFeesList, accountCollectionFee, comparator) < 0) {
                customerAccountFeesList.add(accountCollectionFee);
            }
        } else {
            final List<CollectionSheetCustomerAccountCollectionDto> customerAccountFeesList = new ArrayList<CollectionSheetCustomerAccountCollectionDto>();
            customerAccountFeesList.add(accountCollectionFee);
            accountCollectionsOnCustomerAccountGroupedByCustomerId.put(customerId, customerAccountFeesList);
        }
    }
    return accountCollectionsOnCustomerAccountGroupedByCustomerId;
}
Also used : HashMap(java.util.HashMap) CollectionSheetCustomerAccountCollectionDto(org.mifos.application.servicefacade.CollectionSheetCustomerAccountCollectionDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Comparator(java.util.Comparator)

Example 38 with Comparator

use of java.util.Comparator in project pinot by linkedin.

the class PinotRestletApplication method attachRoutesForClass.

protected void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(ComparatorUtils.chainedComparator(new Comparator<String>() {

        @Override
        public int compare(String left, String right) {
            int leftLength = left.length();
            int rightLength = right.length();
            return leftLength < rightLength ? -1 : (leftLength == rightLength ? 0 : 1);
        }
    }, ComparatorUtils.NATURAL_COMPARATOR));
    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }
    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        attachRoute(router, routePath, clazz);
    }
}
Also used : TreeSet(java.util.TreeSet) Method(java.lang.reflect.Method) Paths(com.linkedin.pinot.common.restlet.swagger.Paths) Annotation(java.lang.annotation.Annotation) Comparator(java.util.Comparator)

Example 39 with Comparator

use of java.util.Comparator in project pinot by linkedin.

the class PinotLLCRealtimeSegmentManager method completeCommittingSegments.

public void completeCommittingSegments(String realtimeTableName, List<String> segmentIds) {
    Comparator<LLCSegmentName> comparator = new Comparator<LLCSegmentName>() {

        @Override
        public int compare(LLCSegmentName o1, LLCSegmentName o2) {
            return o2.compareTo(o1);
        }
    };
    Map<Integer, MinMaxPriorityQueue<LLCSegmentName>> partitionToLatestSegments = new HashMap<>();
    for (String segmentId : segmentIds) {
        LLCSegmentName segmentName = new LLCSegmentName(segmentId);
        final int partitionId = segmentName.getPartitionId();
        MinMaxPriorityQueue latestSegments = partitionToLatestSegments.get(partitionId);
        if (latestSegments == null) {
            latestSegments = MinMaxPriorityQueue.orderedBy(comparator).maximumSize(2).create();
            partitionToLatestSegments.put(partitionId, latestSegments);
        }
        latestSegments.offer(segmentName);
    }
    completeCommittingSegmentsInternal(realtimeTableName, partitionToLatestSegments);
}
Also used : Object2IntLinkedOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap) HashMap(java.util.HashMap) MinMaxPriorityQueue(com.google.common.collect.MinMaxPriorityQueue) LLCSegmentName(com.linkedin.pinot.common.utils.LLCSegmentName) Comparator(java.util.Comparator)

Example 40 with Comparator

use of java.util.Comparator in project KeepScore by nolanlawson.

the class MainActivity method showLoadBackupDialog.

private void showLoadBackupDialog() {
    if (!SdcardHelper.isAvailable()) {
        ToastHelper.showLong(this, R.string.toast_no_sdcard);
        return;
    }
    final List<String> backups = SdcardHelper.list(Location.Backups);
    if (backups.isEmpty()) {
        ToastHelper.showShort(this, R.string.toast_no_backups);
        return;
    }
    final ProgressDialog progressDialog = showProgressDialog(R.string.text_loading_generic, backups.size());
    // show progress dialog to avoid jankiness
    new AsyncTask<Void, Void, List<GamesBackupSummary>>() {

        @Override
        protected List<GamesBackupSummary> doInBackground(Void... params) {
            List<GamesBackupSummary> summaries = new ArrayList<GamesBackupSummary>();
            // fetch the summaries only, so that we don't have to read the entire XML file for each one
            for (String backup : backups) {
                File file = SdcardHelper.getFile(backup, Location.Backups);
                Uri uri = Uri.fromFile(file);
                Format format = file.getName().endsWith(".gz") ? Format.GZIP : Format.XML;
                GamesBackupSummary summary = GamesBackupSerializer.readGamesBackupSummary(uri, format, getContentResolver());
                summaries.add(summary);
                publishProgress((Void) null);
            }
            // show most recent ones first
            Collections.sort(summaries, new Comparator<GamesBackupSummary>() {

                public int compare(GamesBackupSummary lhs, GamesBackupSummary rhs) {
                    return Long.valueOf(rhs.getDateSaved()).compareTo(lhs.getDateSaved());
                }
            });
            return summaries;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
            progressDialog.incrementProgressBy(1);
        }

        @Override
        protected void onPostExecute(List<GamesBackupSummary> result) {
            super.onPostExecute(result);
            progressDialog.dismiss();
            showLoadBackupDialogFinished(result);
        }
    }.execute((Void) null);
}
Also used : GamesBackupSummary(com.nolanlawson.keepscore.serialization.GamesBackupSummary) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) Comparator(java.util.Comparator) Format(com.nolanlawson.keepscore.helper.SdcardHelper.Format) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

Comparator (java.util.Comparator)322 ArrayList (java.util.ArrayList)123 List (java.util.List)58 Test (org.junit.Test)58 HashMap (java.util.HashMap)50 IOException (java.io.IOException)36 Map (java.util.Map)35 File (java.io.File)24 HashSet (java.util.HashSet)23 TreeSet (java.util.TreeSet)20 Set (java.util.Set)18 Iterator (java.util.Iterator)15 Method (java.lang.reflect.Method)14 Collections (java.util.Collections)14 Date (java.util.Date)14 TreeMap (java.util.TreeMap)14 ArrayMap (android.util.ArrayMap)12 Collection (java.util.Collection)11 LinkedList (java.util.LinkedList)11 SimpleDateFormat (java.text.SimpleDateFormat)10