Example usage for java.util Collections reverseOrder

List of usage examples for java.util Collections reverseOrder

Introduction

In this page you can find the example usage for java.util Collections reverseOrder.

Prototype

@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder() 

Source Link

Document

Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.

Usage

From source file:com.github.pffy.chinese.freq.ChineseFrequency.java

private void analyze() {

    int inputCount = 0;
    int removedCount = 0;
    int hanziCount = 0;
    int uniqueHanziCount = 0;
    int processedCount = 0;

    int freq = 0;

    String csvOutput = this.HEADER_ROW_CSV;
    String tsvOutput = this.HEADER_ROW_TSV;
    String txtOutput = this.HEADER_ROW_TXT;

    String csv, tsv, txt;/* w  w  w  .  jav a 2 s  .  co m*/
    String str, input, pinyin, hanzi;
    Scanner sc;
    List<String> hanziList;
    Map<String, Integer> freqMap;
    JSONObject hpdx;
    String[] arr;

    Set<String> unmappedCharacters;

    hpdx = this.hpdx;

    input = this.input;
    inputCount = input.length();

    input = retainHanzi(input);
    removedCount = inputCount - input.length();

    hanziCount = input.length();

    sc = new Scanner(input);
    sc.useDelimiter("");

    hanziList = new ArrayList<String>();
    freqMap = new HashMap<String, Integer>();

    // counts occurrences
    while (sc.hasNext()) {

        str = sc.next();
        hanziList.add(str);

        if (freqMap.containsKey(str)) {
            freqMap.put(str, (Integer) freqMap.get(str).intValue() + 1);
        } else {
            freqMap.put(str, 1);
        }
    }

    // done with Scanner
    sc.close();

    uniqueHanziCount = freqMap.keySet().size();

    SortedMap<String, String> freqTreeMap = new TreeMap<String, String>(Collections.reverseOrder());

    unmappedCharacters = new HashSet<String>();
    for (Entry<String, Integer> counts : freqMap.entrySet()) {

        try {

            hanzi = counts.getKey();
            pinyin = hpdx.getString(hanzi);

        } catch (JSONException je) {

            // add this unmapped character to the list
            unmappedCharacters.add(counts.getKey());

            // not idx mapped yet. that's ok. move on.
            continue;
        }

        if (pinyin.isEmpty()) {
            // if character is unmapped in idx, do not process.
            continue;
        }

        freq = counts.getValue();

        freqTreeMap.put(String.format("%" + this.PADSIZE_FREQ + "s", freq).replace(' ', '0') + "-" + hanzi + "-"
                + pinyin, hanzi + "," + pinyin + "," + freq);
        processedCount++;
    }

    // outputs
    for (Entry<String, String> outputs : freqTreeMap.entrySet()) {

        csv = this.CRLF + outputs.getValue();
        csvOutput += csv;

        tsv = csv.replaceAll(",", "\t");
        tsvOutput += tsv;

        arr = csv.split(",");

        // arr[0] is hanzi. arr[1] is pinyin. arr[2] is freq.
        txt = padSummary(arr[0] + " [" + arr[1] + "]", this.PADSIZE_SUMMARY + 1) + arr[2];
        txtOutput += txt;
    }

    // cleanup
    csvOutput = csvOutput.trim();
    tsvOutput = tsvOutput.trim();
    txtOutput = txtOutput.trim();

    // post-process
    this.csvOutput = csvOutput;
    this.tsvOutput = tsvOutput;
    this.txtOutput = txtOutput;

    // counts
    this.inputCount = inputCount;
    this.removedCount = removedCount;
    this.hanziCount = hanziCount;
    this.uniqueHanziCount = uniqueHanziCount;
    this.processedCount = processedCount;

    this.unmappedCharacters = unmappedCharacters;

    // summary
    String summaryString = "";

    summaryString += padSummary(this.MSG_TOTAL_COUNT, this.PADSIZE_SUMMARY) + inputCount;
    summaryString += this.CRLF + padSummary(this.MSG_REMOVED_COUNT, this.PADSIZE_SUMMARY) + removedCount;
    summaryString += this.CRLF + padSummary(this.MSG_HANZI_COUNT, this.PADSIZE_SUMMARY) + hanziCount;
    summaryString += this.CRLF + padSummary(this.MSG_UNIQUE_COUNT, this.PADSIZE_SUMMARY) + uniqueHanziCount;
    summaryString += this.CRLF + padSummary(this.MSG_PROCESSED_COUNT, this.PADSIZE_SUMMARY) + processedCount;

    this.summary = summaryString;
}

From source file:com.commonsware.cwac.masterdetail.MasterDetailController.java

@SuppressWarnings("unchecked")
void removeChecked() {
    SparseBooleanArray checked = getListView().getCheckedItemPositions();

    ArrayList<Integer> positions = new ArrayList<Integer>();

    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            positions.add(checked.keyAt(i));
        }/*  w w w.  j  a  v a  2s  . c o m*/
    }

    Collections.sort(positions, Collections.reverseOrder());

    for (int position : positions) {
        removeModel(getModelCollection().get(position));
        getModelCollection().remove(position);
        ((ModelPagerAdapter) getPagerAdapter()).remove(position);
    }

    getListView().clearChoices();
    ((ModelPagerAdapter) getPagerAdapter()).notifyDataSetChanged();
}

From source file:com.thesmartweb.swebrank.Moz.java

/**
 * Method that captures the various Moz metrics for the provided urls (with help of the sample here https://github.com/seomoz/SEOmozAPISamples
 * and ranks them accordingly/*from   w  w w .ja  v a 2  s.c o m*/
 * @param links the urls to analyze
 * @param top_count the amount of results to keep when we rerank the results according to their value of a specific Moz metric
 * @param moz_threshold the threshold to the Moz value to use
 * @param moz_threshold_option flag if we are going to use threshold in the Moz value or not
 * @param mozMetrics list that contains which metric to use for Moz //1st place is Page Authority,2nd external mozRank, 3rd, mozTrust, 4th DomainAuthority and 5th MozRank (it is the default)
 * @param config_path path that has the config files with the api keys and secret for Moz
 * @return an array with the links sorted according to their moz values
 */
public String[] perform(String[] links, int top_count, Double moz_threshold, Boolean moz_threshold_option,
        List<Boolean> mozMetrics, String config_path) {
    //=====short codes for the metrics 
    long upa = 34359738368L;//page authority
    long pda = 68719476736L;//domain authority
    long uemrp = 1048576;//mozrank external equity
    long utrp = 131072;//moztrust 
    long fmrp = 32768;//mozrank subdomain
    long umrp = 16384;//mozrank
    System.gc();
    System.out.println("into Moz");
    Double[] mozRanks = new Double[links.length];
    DataManipulation textualmanipulation = new DataManipulation();
    for (int i = 0; i < links.length; i++) {
        if (links[i] != null) {
            if (!textualmanipulation.StructuredFileCheck(links[i])) {
                try {
                    Thread.sleep(10000);
                    URLMetricsService urlMetricsservice;
                    urlMetricsservice = authenticate(config_path);
                    String objectURL = links[i].substring(0, links[i].length());
                    Gson gson = new Gson();
                    if (mozMetrics.get(1)) {//Domain Authority
                        String response = urlMetricsservice.getUrlMetrics(objectURL, pda);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getPda();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(2)) {//External MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, uemrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUemrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(3)) {//MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, umrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUmrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(4)) {//MozTrust
                        String response = urlMetricsservice.getUrlMetrics(objectURL, utrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUtrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(5)) {//Page Authority
                        String response = urlMetricsservice.getUrlMetrics(objectURL, upa);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getUpa();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    } else if (mozMetrics.get(6)) {//subdomain MozRank
                        String response = urlMetricsservice.getUrlMetrics(objectURL, fmrp);
                        UrlResponse res = gson.fromJson(response, UrlResponse.class);
                        System.gc();
                        if (res != null && !(response.equalsIgnoreCase("{}"))) {
                            String mozvalue_string = res.getFmrp();
                            mozRanks[i] = Double.parseDouble(mozvalue_string);
                        } else {
                            mozRanks[i] = Double.parseDouble("0");
                        }
                    }
                } catch (InterruptedException | JsonSyntaxException | NumberFormatException ex) {
                    System.out.println("exception moz:" + ex.toString());
                    mozRanks[i] = Double.parseDouble("0");
                    String[] links_out = null;
                    return links_out;
                }
            } else {
                mozRanks[i] = Double.parseDouble("0");
            }
        }
    }
    try {//ranking of the urls according to their moz score
         //get the scores to a list
        System.out.println("I am goint to rank the scores of Moz");
        System.gc();
        List<Double> seomozRanks_scores_list = Arrays.asList(mozRanks);
        //create a hashmap in order to map the scores with the indexes
        System.gc();
        IdentityHashMap<Double, Integer> originalIndices = new IdentityHashMap<Double, Integer>();
        //copy the original scores list
        System.gc();
        for (int i = 0; i < seomozRanks_scores_list.size(); i++) {
            originalIndices.put(seomozRanks_scores_list.get(i), i);
            System.gc();
        }
        //sort the scores
        List<Double> sorted_seomozRanks_scores = new ArrayList<Double>();
        System.gc();
        sorted_seomozRanks_scores.addAll(seomozRanks_scores_list);
        System.gc();
        sorted_seomozRanks_scores.removeAll(Collections.singleton(null));
        System.gc();
        if (!sorted_seomozRanks_scores.isEmpty()) {
            Collections.sort(sorted_seomozRanks_scores, Collections.reverseOrder());
        }
        //get the original indexes
        //the max amount of results
        int[] origIndex = new int[150];
        if (!sorted_seomozRanks_scores.isEmpty()) {
            //if we want to take the top scores(for example top 10)
            if (!moz_threshold_option) {
                origIndex = new int[top_count];
                for (int i = 0; i < top_count; i++) {
                    Double score = sorted_seomozRanks_scores.get(i);
                    System.gc();
                    // Lookup original index efficiently
                    origIndex[i] = originalIndices.get(score);
                }
            }
            //if we have a threshold
            else if (moz_threshold_option) {
                int j = 0;
                int counter = 0;
                while (j < sorted_seomozRanks_scores.size()) {
                    if (sorted_seomozRanks_scores.get(j).compareTo(moz_threshold) >= 0) {
                        counter++;
                    }
                    j++;
                }
                origIndex = new int[counter];
                for (int k = 0; k < origIndex.length - 1; k++) {
                    System.gc();
                    Double score = sorted_seomozRanks_scores.get(k);
                    origIndex[k] = originalIndices.get(score);
                }
            }
        }
        String[] links_out = new String[origIndex.length];
        for (int jj = 0; jj < origIndex.length; jj++) {
            System.gc();
            links_out[jj] = links[origIndex[jj]];
        }
        System.gc();
        System.out.println("I have ranked the scores of moz");
        return links_out;
    } catch (Exception ex) {
        System.out.println("exception moz list" + ex.toString());
        //Logger.getLogger(Moz.class.getName()).log(Level.SEVERE, null, ex);
        String[] links_out = null;
        return links_out;
    }
}

From source file:org.lockss.poller.v3.VersionCounts.java

public Map<Integer, Collection<ParticipantUserData>> getSortedRepairCandidatesMap(int landslideMinimum,
        Collection<HashResult> excludedHashes) {
    Map<Integer, Collection<ParticipantUserData>> repairCandidates = new TreeMap<Integer, Collection<ParticipantUserData>>(
            Collections.reverseOrder());
    for (HashResult headVersion : (Collection<HashResult>) headVersionMap.keySet()) {
        if (!excludedHashes.contains(headVersion)) {
            Collection<ParticipantUserData> voters = votedVersionMap.getCollection(headVersion);
            // voters can't be null, since the plainHash is the head
            // version for some voters.
            int size = voters.size();
            if (size >= landslideMinimum) {
                Collection<ParticipantUserData> countVoters = repairCandidates.get(size);
                if (countVoters == null) {
                    countVoters = new HashSet<ParticipantUserData>();
                    repairCandidates.put(size, countVoters);
                }/* w  w  w. j  a v a  2  s.com*/
                Collection<ParticipantUserData> headVoters = headVersionMap.getCollection(headVersion);
                for (ParticipantUserData voter : headVoters) {
                    countVoters.add(voter);
                }
            }
        }
    }
    return repairCandidates;
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.collection.PhysicalWebCollection.java

/**
 * Return a list of PwPairs sorted by rank in descending order.
 * These PwPairs will be deduplicated by siteUrls (favoring the PwPair with
 * the highest rank)./*from   w w w  .j  a  va  2 s  . c  o  m*/
 * @return a sorted list of PwPairs.
 */
public List<PwPair> getPwPairsSortedByRank() {
    // Get all valid PwPairs.
    List<PwPair> allPwPairs = getPwPairs();

    // Sort the list in descending order.
    Collections.sort(allPwPairs, Collections.reverseOrder());

    // Filter the list.
    return removeDuplicateSiteUrls(allPwPairs);
}

From source file:com.act.lcms.db.model.StandardIonResult.java

private static LinkedHashMap<String, XZ> deserializeStandardIonAnalysisResult(String jsonEntry)
        throws IOException {
    // We have to re-sorted the deserialized results so that we meet the contract expected by the caller.
    Map<String, XZ> deserializedResult = OBJECT_MAPPER.readValue(jsonEntry, typeRefForStandardIonAnalysis);
    TreeMap<Double, String> sortedIntensityToIon = new TreeMap<>(Collections.reverseOrder());

    for (Map.Entry<String, XZ> val : deserializedResult.entrySet()) {
        sortedIntensityToIon.put(val.getValue().getIntensity(), val.getKey());
    }/*  ww w.  j a va2s .c  o m*/

    LinkedHashMap<String, XZ> sortedResult = new LinkedHashMap<>();
    for (Map.Entry<Double, String> val : sortedIntensityToIon.entrySet()) {
        String ion = val.getValue();
        sortedResult.put(ion, deserializedResult.get(ion));
    }

    return sortedResult;
}

From source file:ubc.pavlab.gotrack.beans.EnrichmentView.java

private void enrichmentAnalysis(Map<Edition, Map<Gene, Set<GeneOntologyTerm>>> geneGOMap,
        Map<Edition, Set<GeneOntologyTerm>> allTerms, int minAnnotedPopulation) {

    enrichmentData = new HashMap<>();
    boolean emptyChart = true;

    List<Edition> eds = new ArrayList<Edition>(geneGOMap.keySet());
    Collections.sort(eds, Collections.reverseOrder());
    boolean firstRun = true;
    Set<GeneOntologyTerm> termsToEnrich = new HashSet<>();

    for (Edition ed : eds) {

        Map<Gene, Set<GeneOntologyTerm>> data = geneGOMap.get(ed);

        int populationSize = cache.getGenePopulation(currentSpeciesId, ed);
        int k = data.keySet().size();

        Set<GeneOntologyTerm> termsInEdition = allTerms.get(ed);

        // // TODO Multiple tests correction lowered because we're testing less terms?
        // if ( !firstRun ) {
        // termsInEdition = new HashSet<>( termsInEdition );
        // termsInEdition.retainAll( termsToEnrich );
        // }/*from   w ww . j  a v a 2s . c  om*/

        Map<GeneOntologyTerm, Double> enrich = enrichmentData.get(ed);

        if (enrich == null) {
            enrich = new HashMap<>();
            enrichmentData.put(ed, enrich);
        }

        if (termsInEdition != null) {
            int bcorr = termsInEdition.size();
            for (GeneOntologyTerm term : termsInEdition) {

                if (!firstRun && !termsToEnrich.contains(term)) {
                    // Term is part of this edition however did not pass the threshold in the current edition
                    continue;
                }

                Integer populationAnnotated = cache.getGoSetSizes(currentSpeciesId, ed.getEdition(),
                        term.getGoId());

                if (populationAnnotated != null && populationAnnotated >= minAnnotedPopulation) {
                    HypergeometricDistribution hyper = new HypergeometricDistribution(populationSize,
                            populationAnnotated, k);

                    int r = 0;

                    for (Entry<Gene, Set<GeneOntologyTerm>> geneEntry : data.entrySet()) {
                        if (geneEntry.getValue().contains(term)) {
                            r++;
                        }
                    }

                    // log.info( Arrays.asList( populationSize, populationAnnotated, k, r ) );
                    Double res = hyper.upperCumulativeProbability(r);

                    if (bonferroniCorrection) {
                        res = bcorr * res;
                    }

                    res = Math.min(res, 1);

                    if (!firstRun || res <= pThreshold) {
                        enrich.put(term, res);
                        emptyChart = false;
                        if (firstRun) {
                            termsToEnrich.add(term);
                        }
                    } else {
                        // log.info( term + " skipped; p-value not in range" );
                    }

                    // log.info( "Edition: (" + ed.getEdition() + ") " + hyper.upperCumulativeProbability( r ) );

                } else {
                    // log.info( term + " skipped; too small or isn't annotated" );
                }
            }
        }
        firstRun = false;

    }

    if (!emptyChart) {
        enrichmentChart = createChart(enrichmentData, "Enrichment Stability", "Date", "p-value");
        chartReady = true;
        log.info("Chart created");
    } else {
        chartReady = false;
        log.info("Chart Empty");
    }

}

From source file:backup.namenode.NameNodeBackupServicePlugin.java

private BackupWebService<Stats> getBackupWebService(UserGroupInformation ugi, BlockManager blockManager,
        NameNodeRestoreProcessor restoreProcessor) throws IOException {
    File reportPath = restoreProcessor.getReportPath();
    return new BackupWebService<Stats>() {
        @Override/*  w  ww.ja va 2  s  . c om*/
        public StatsWritable getStats() throws IOException {
            StatsWritable stats = new StatsWritable();
            Set<DatanodeDescriptor> datanodes = blockManager.getDatanodeManager().getDatanodes();
            for (DatanodeInfo datanodeInfo : datanodes) {
                try {
                    DataNodeBackupRPC backup = DataNodeBackupRPC.getDataNodeBackupRPC(datanodeInfo, getConf(),
                            ugi);
                    stats.add(backup.getBackupStats());
                    stats.add(backup.getRestoreStats());
                } catch (Exception e) {
                    LOG.error("Error while trying to read hdfs backup stats from datanode {}",
                            datanodeInfo.getHostName());
                }
            }
            return stats;
        }

        @Override
        public void runReport(boolean debug) throws IOException {
            restoreProcessor.runReport(debug);
        }

        @Override
        public List<String> listReports() throws IOException {
            Builder<String> builder = ImmutableList.builder();
            if (!reportPath.exists()) {
                return builder.build();
            }
            File[] list = reportPath.listFiles((dir, name) -> name.startsWith("report."));
            if (list != null) {
                Arrays.sort(list, Collections.reverseOrder());
                for (File f : list) {
                    builder.add(f.getName());
                }
            }
            return builder.build();
        }

        @Override
        public InputStream getReport(String id) throws IOException {
            File file = new File(reportPath, id);
            if (file.exists()) {
                return new FileInputStream(file);
            }
            return null;
        }
    };
}

From source file:org.sparkcommerce.core.offer.service.processor.FulfillmentGroupOfferProcessorImpl.java

@Override
@SuppressWarnings("unchecked")
public boolean applyAllFulfillmentGroupOffers(List<PromotableCandidateFulfillmentGroupOffer> qualifiedFGOffers,
        PromotableOrder order) {//from  w  w  w  .  ja  v  a2s.  c o  m
    Map<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>> offerMap = new HashMap<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>>();
    for (PromotableCandidateFulfillmentGroupOffer candidate : qualifiedFGOffers) {
        FulfillmentGroupOfferPotential potential = new FulfillmentGroupOfferPotential();
        potential.setOffer(candidate.getOffer());
        if (offerMap.get(potential) == null) {
            offerMap.put(potential, new ArrayList<PromotableCandidateFulfillmentGroupOffer>());
        }
        offerMap.get(potential).add(candidate);
    }
    List<FulfillmentGroupOfferPotential> potentials = new ArrayList<FulfillmentGroupOfferPotential>();
    for (FulfillmentGroupOfferPotential potential : offerMap.keySet()) {
        List<PromotableCandidateFulfillmentGroupOffer> fgOffers = offerMap.get(potential);
        Collections.sort(fgOffers,
                new ReverseComparator(new BeanComparator("discountedAmount", new NullComparator())));
        Collections.sort(fgOffers, new BeanComparator("priority", new NullComparator()));

        if (potential.getOffer().isLimitedUsePerOrder()
                && fgOffers.size() > potential.getOffer().getMaxUsesPerOrder()) {
            for (int j = potential.getOffer().getMaxUsesPerOrder(); j < fgOffers.size(); j++) {
                fgOffers.remove(j);
            }
        }
        for (PromotableCandidateFulfillmentGroupOffer candidate : fgOffers) {
            if (potential.getTotalSavings().getAmount().equals(BankersRounding.zeroAmount())) {
                SparkCurrency currency = order.getOrderCurrency();
                if (currency != null) {
                    potential.setTotalSavings(new Money(BigDecimal.ZERO, currency.getCurrencyCode()));
                } else {
                    potential.setTotalSavings(new Money(BigDecimal.ZERO));
                }
            }

            Money priceBeforeAdjustments = candidate.getFulfillmentGroup().calculatePriceWithoutAdjustments();
            Money discountedPrice = candidate.getDiscountedPrice();
            potential.setTotalSavings(
                    potential.getTotalSavings().add(priceBeforeAdjustments.subtract(discountedPrice)));
            potential.setPriority(candidate.getOffer().getPriority());
        }

        potentials.add(potential);
    }

    // Sort fg potentials by priority and discount
    Collections.sort(potentials, new BeanComparator("totalSavings", Collections.reverseOrder()));
    Collections.sort(potentials, new BeanComparator("priority"));
    potentials = removeTrailingNotCombinableFulfillmentGroupOffers(potentials);

    boolean fgOfferApplied = false;
    for (FulfillmentGroupOfferPotential potential : potentials) {
        Offer offer = potential.getOffer();

        boolean alreadyContainsTotalitarianOffer = order.isTotalitarianOfferApplied();
        List<PromotableCandidateFulfillmentGroupOffer> candidates = offerMap.get(potential);
        for (PromotableCandidateFulfillmentGroupOffer candidate : candidates) {
            applyFulfillmentGroupOffer(candidate.getFulfillmentGroup(), candidate);
            fgOfferApplied = true;
        }
        for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
            fg.chooseSaleOrRetailAdjustments();
        }

        if ((offer.isTotalitarianOffer() != null && offer.isTotalitarianOffer())
                || alreadyContainsTotalitarianOffer) {
            fgOfferApplied = compareAndAdjustFulfillmentGroupOffers(order, fgOfferApplied);
            if (fgOfferApplied) {
                break;
            }
        } else if (!offer.isCombinableWithOtherOffers()) {
            break;
        }
    }

    return fgOfferApplied;
}