List of usage examples for java.util Comparator Comparator
Comparator
From source file:org.openmrs.module.xforms.page.controller.formentry.PatientPageController.java
private Map<Form, FormEntryHandler> getForms(Patient patient) { List<String> excludFormUuids = new ArrayList<String>(); excludFormUuids.add("a000cb34-9ec1-4344-a1c8-f692232f6edd"); excludFormUuids.add("c75f120a-04ec-11e3-8780-2b40bef9a44b"); excludFormUuids.add("d2c7532c-fb01-11e2-8ff2-fd54ab5fdb2a"); excludFormUuids.add("b5f8ffd8-fbde-11e2-8ff2-fd54ab5fdb2a"); excludFormUuids.add("a007bbfe-fbe5-11e2-8ff2-fd54ab5fdb2a"); FormEntryContext fec = new FormEntryContext(patient); Map<Form, FormEntryHandler> entryUrlMap = new TreeMap<Form, FormEntryHandler>(new Comparator<Form>() { public int compare(Form left, Form right) { int temp = left.getName().toLowerCase().compareTo(right.getName().toLowerCase()); if (temp == 0) temp = OpenmrsUtil.compareWithNullAsLowest(left.getVersion(), right.getVersion()); if (temp == 0) temp = OpenmrsUtil.compareWithNullAsGreatest(left.getId(), right.getId()); return temp; }/*from w ww . jav a 2s .c o m*/ }); List<Extension> handlers = ModuleFactory.getExtensions("org.openmrs.module.web.extension.FormEntryHandler", MEDIA_TYPE.html); if (handlers != null) { for (Extension ext : handlers) { FormEntryHandler handler = (FormEntryHandler) ext; Collection<Form> toEnter = handler.getFormsModuleCanEnter(fec); if (toEnter != null) { for (Form form : toEnter) { if (excludFormUuids.contains(form.getUuid())) { continue; } entryUrlMap.put(form, handler); } } } } return entryUrlMap; }
From source file:it.units.malelab.sse.MyGeneticAlgorithm.java
@Override public Population evolve(Population initial, StoppingCondition condition) { Population current = initial;/*from w w w. j a va2s .co m*/ generationsEvolved = 0; while (!condition.isSatisfied(current)) { current = nextGeneration(current); generationsEvolved++; //obtain stats List<EnumMap<Evaluator.ResultType, Double>> statsList = new ArrayList<>(current.getPopulationSize()); Iterator<Chromosome> iterator = current.iterator(); while (iterator.hasNext()) { OperationsChromosome chromosome = (OperationsChromosome) iterator.next(); EnumMap<Evaluator.ResultType, Double> stats = chromosome.getStats(); if (stats.containsKey(Evaluator.ResultType.OVERLAPNESS)) { statsList.add(stats); } } Collections.sort(statsList, new Comparator<EnumMap<Evaluator.ResultType, Double>>() { @Override public int compare(EnumMap<Evaluator.ResultType, Double> stats1, EnumMap<Evaluator.ResultType, Double> stats2) { return Double.compare(stats1.get(Evaluator.ResultType.OVERLAPNESS), stats2.get(Evaluator.ResultType.OVERLAPNESS)); } }); EnumMap<Evaluator.ResultType, Double> bestStats = statsList.get(0); EnumMap<Evaluator.ResultType, Double> top10Stats = mean(statsList.subList(0, 10)); EnumMap<Evaluator.ResultType, Double> allStats = mean(statsList); System.out.printf("ovp=%5.3f/%5.3f/%5.3f ", bestStats.get(Evaluator.ResultType.OVERLAPNESS), top10Stats.get(Evaluator.ResultType.OVERLAPNESS), allStats.get(Evaluator.ResultType.OVERLAPNESS)); System.out.printf("ops=%4.0f/%4.0f/%4.0f ", bestStats.get(Evaluator.ResultType.AVG_OPS), top10Stats.get(Evaluator.ResultType.AVG_OPS), allStats.get(Evaluator.ResultType.AVG_OPS)); System.out.printf("mfp=%4.0f/%4.0f/%4.0f ", bestStats.get(Evaluator.ResultType.AVG_FOOTPRINT), top10Stats.get(Evaluator.ResultType.AVG_FOOTPRINT), allStats.get(Evaluator.ResultType.AVG_FOOTPRINT)); System.out.printf("err=%5.3f/%5.3f/%5.3f ", bestStats.get(Evaluator.ResultType.ERROR_RATIO), top10Stats.get(Evaluator.ResultType.ERROR_RATIO), allStats.get(Evaluator.ResultType.ERROR_RATIO)); System.out.printf("size=%3.0f/%3.0f/%3.0f ", bestStats.get(Evaluator.ResultType.SIZE), top10Stats.get(Evaluator.ResultType.SIZE), allStats.get(Evaluator.ResultType.SIZE)); System.out.printf("evals=%8d\n", evaluator.getEvaluatedCount()); //System.out.println(evaluator.getErrorCodes()); } return current; }
From source file:pl.edu.icm.comac.vis.server.service.GraphToolkit.java
/** * Method to choose appropriate not-favourite nodes of the graph. It takes * all nodes outside the normal and large sets, and chooses only those, who * are not overflowing the normal nodes over 'itemLinkLimit'. Note, that if * at most one normal node is not overflown by item, others may be. * * @param normal list of normal favaourite nodes. * @param large list of favourite nodes which are overflown, i.e. we have limited * knowledge of their links// www. j a v a2s. c o m * @param links map of all links for all items, normal and external * @param itemLinkLimit recommended size od the links * @return set of the items choosen for the graphs as not favourite nodes. */ public Set<String> calculateAdditions(Set<String> normal, Set<String> large, Map<String, Set<String>> links, long itemLinkLimit) { Map<String, Long> outgoingLinks = new HashMap<>(); normal.stream().forEach(x -> outgoingLinks.put(x, 0l)); List<String> leftovers = links.keySet().stream().filter(x -> !(normal.contains(x) || large.contains(x))) .collect(Collectors.toList()); //now order list by the link count in each of each element: Collections.sort(leftovers, new Comparator<String>() { @Override public int compare(String o1, String o2) { int res = -((Integer) links.get(o1).size()).compareTo(((Integer) links.get(o2).size())); if (res == 0) { return o1.compareToIgnoreCase(o2); } else { return res; } } }); Set<String> approved = new HashSet<String>(); for (String item : leftovers) { final Set<String> itemLinks = links.get(item); if (itemLinks.stream().anyMatch(x -> { return outgoingLinks.containsKey(x) && outgoingLinks.get(x) < itemLinkLimit; })) { approved.add(item); itemLinks.stream().filter(x -> outgoingLinks.containsKey(x)) .forEach(x -> outgoingLinks.put(x, outgoingLinks.get(x) + 1)); } } return approved; }
From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java
public void printHelp(PrintWriter stream, String usage, String header, String footer) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override//from w w w .j a va2 s .com public int compare(Option opt1, Option opt2) { return (int) Math.signum(optionsOrder.get(opt1.getOpt()) - optionsOrder.get(opt2.getOpt())); } }); formatter.printHelp(stream, HelpFormatter.DEFAULT_WIDTH, usage, header, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer); }
From source file:ch.cyberduck.core.openstack.SwiftLocationFeature.java
@Override public Set<Name> getLocations() { final Set<Name> locations = new LinkedHashSet<Name>(); final List<Region> regions = new ArrayList<Region>(session.getClient().getRegions()); Collections.sort(regions, new Comparator<Region>() { @Override/*from w w w . ja v a 2 s . c o m*/ public int compare(final Region r1, final Region r2) { if (r1.isDefault()) { return -1; } if (r2.isDefault()) { return 1; } return 0; } }); for (Region region : regions) { if (StringUtils.isBlank(region.getRegionId())) { // v1 authentication contexts do not have region support continue; } locations.add(new SwiftRegion(region.getRegionId())); } return locations; }
From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java
@Override public List<Organization> getOrganizations() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter(ShsLdapAttributes.ATTR_OBJECT_CLASS, ShsLdapAttributes.CLASS_SHS_ORGEXTENSION)); List<Organization> organizations = findAll(null, filter, new OrganizationMapper()); Collections.sort(organizations, new Comparator<Organization>() { @Override//ww w . ja v a 2s .c o m public int compare(Organization o1, Organization o2) { return o1.getOrgName().compareToIgnoreCase(o2.getOrgName()); } }); return organizations; }
From source file:com.c123.billbuddy.dal.Top10PaymentReducer.java
@Override public Payment[] reduce(SpaceRemotingResult<Payment[]>[] results, SpaceRemotingInvocation remotingInvocation) throws Exception { log.info("Starting Top10MerchantFeeAmountReducer"); List<Payment> payments = new ArrayList<Payment>(); // Each result is an array of events. Each result is from a single partition. for (SpaceRemotingResult<Payment[]> result : results) { if (result.getException() != null) { // just log the fact that there was an exception log.error("Executor Remoting Exception [" + result.getException() + "]"); continue; }//ww w . ja v a 2s .c o m Collections.addAll(payments, result.getResult()); } Collections.sort(payments, new Comparator<Payment>() { public int compare(Payment p1, Payment p2) { return p2.getPaymentAmount().compareTo(p1.getPaymentAmount()); } }); // If the number of results needed is less than the number of events that were reduced, then // return a sublist. Otherwise, return the entire list of events. Payment[] top10Payment; if (payments.size() < 10) { top10Payment = new Payment[payments.size()]; payments.toArray(top10Payment); } else { top10Payment = new Payment[10]; payments.subList(0, 10).toArray(top10Payment); } return top10Payment; }
From source file:edu.cmu.tetrad.search.Test.java
private double logOfSum(List<Double> logs) { Collections.sort(logs, new Comparator<Double>() { @Override/*from ww w .java2 s . com*/ public int compare(Double o1, Double o2) { return -Double.compare(o1, o2); } }); double sum = 0.0; int N = logs.size() - 1; double loga0 = logs.get(0); for (int i = 1; i <= N; i++) { sum += Math.exp(logs.get(i) - loga0); } sum += 1; return loga0 + Math.log(sum); }
From source file:com.squid.core.database.model.Index.java
public void addColumn(ColumnPos columnPos) { ArrayList<ColumnPos> copy = new ArrayList<ColumnPos>(this.columns); copy.add(columnPos);//from w ww. j a v a2 s . c o m if (copy.size() > 1) { Collections.sort(copy, new Comparator<ColumnPos>() { @Override public int compare(ColumnPos o1, ColumnPos o2) { return o1.getPos() - o2.getPos(); } }); } this.columns = copy; }
From source file:com.wojtechnology.sunami.SongManager.java
public List<FireMixtape> getByTitle() { List<FireMixtape> displayList = new ArrayList<>(mSongList); if (mSongList.size() <= 0) { return displayList; }//from w ww .ja v a 2s . c o m Collections.sort(displayList, new Comparator<FireMixtape>() { @Override public int compare(FireMixtape lhs, FireMixtape rhs) { return compareTitles(lhs, rhs); } }); Map<Character, Integer> letters = new HashMap<>(); int i = 0; while (firstLetter(displayList.get(i).title) < 'A' || firstLetter(displayList.get(i).title) > 'Z') { i++; if (i >= displayList.size()) return displayList; } int sum = i; int j = i; for (char headerTitle = 'A'; headerTitle <= 'Z' && i < displayList.size(); i++) { if (firstLetter(displayList.get(i).title) != headerTitle) { letters.put(headerTitle, i - j); headerTitle++; j = i; i--; } } for (char headerTitle = 'A'; headerTitle <= 'Z' && letters.containsKey(headerTitle); headerTitle++) { if (letters.get(headerTitle) != 0) { FireMixtape mixtape = HeaderHelper.makeHeader(context, Character.toString(headerTitle)); displayList.add(sum, mixtape); sum++; } sum += letters.get(headerTitle); } FireMixtape final_header = HeaderHelper.makeFinal(context, getFinalLabel()); displayList.add(final_header); return displayList; }