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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations