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:multithread.ExtendPairingRecursiveTask.java

private void generatePairingAndNullSpaceUsingMatchingPointWithPropertiesNostaticlist(
        ResultsFromEvaluateCost resultSeed, final CollectionOfPointsWithPropertiesIfc shape1,
        final CollectionOfPointsWithPropertiesIfc shape2, AlgoParameters algoParameters) {

    // Both points has StrikingProperties not none and they all match (also if only one of course)
    Map<Integer, List<PairPointWithDistance>> mapforAllMatchingStrikingProperties = new HashMap<>();

    // Both points has more than one striking properties and at least one of them match
    List<PairPointWithDistance> listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance = new ArrayList<>();

    // Both points has None Striking Properties
    List<PairPointWithDistance> listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance = new ArrayList<>();

    // One point has None striking property and the others has striking properties
    List<PairPointWithDistance> listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance = new ArrayList<>();

    // Both points has Striking properties but not a single one is matching
    List<PairPointWithDistance> listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance = new ArrayList<>();

    for (int i = 0; i < shape1.getSize(); i++) {
        for (int j = 0; j < shape2.getSize(); j++) {

            // Only Pairs of matching properties point are kept
            PointWithPropertiesIfc pointWithProperties1 = shape1.getPointFromId(i);
            PointWithPropertiesIfc pointWithProperties2 = shape2.getPointFromId(j);

            RealMatrix matrix = resultSeed.getRotationMatrix();
            float[] vector1 = new float[3];
            for (int k = 0; k < 3; k++) {
                vector1[k] = (float) (pointWithProperties2.getCoords().getCoords()[k]
                        + resultSeed.getTranslationVectorToTranslateShape2ToOrigin().getEntry(k));
            }/*w  ww  .  j  a  va2  s  .c  o m*/

            double[] vector2 = new double[3];
            for (int k = 0; k < 3; k++) {
                for (int l = 0; l < 3; l++) {
                    vector2[k] += matrix.getEntry(k, l) * vector1[l];
                }
            }

            for (int k = 0; k < 3; k++) {
                vector1[k] = (float) (vector2[k]
                        - resultSeed.getTranslationVectorToTranslateShape2ToOrigin().getEntry(k)
                        + resultSeed.getTranslationVector().getEntry(k));
            }

            double distance = MathTools.computeDistance(pointWithProperties1.getCoords().getCoords(), vector1);

            if (distance < algoParameters.getDISTANCE_MIN_FOR_EXTENDED_PAIRING_FROM_SEED()) {

                PairPointWithDistance pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance = new PairPointWithDistance(
                        i, j, distance);

                int countOfMatchingStrikingPropertiesWhenAllAreMatching = StrikingPropertiesTools
                        .evaluatePointsMatchingAllNotNoneProperties(pointWithProperties1, pointWithProperties2);
                if (countOfMatchingStrikingPropertiesWhenAllAreMatching > 0) {
                    AddToMap.addElementToAMapOfList(mapforAllMatchingStrikingProperties,
                            countOfMatchingStrikingPropertiesWhenAllAreMatching,
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    continue;
                }

                if (StrikingPropertiesTools.evaluatePointsMatchingOneButNotAllNotNoneProperties(
                        pointWithProperties1, pointWithProperties2)) {
                    listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance.add(
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    continue;
                }

                if (StrikingPropertiesTools.evaluatePointsMatchingOnlyNoneProperties(pointWithProperties1,
                        pointWithProperties2)) {
                    listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance.add(
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    continue;
                }

                if (StrikingPropertiesTools.evaluatePointsNoneMatchingANotNONEtoOnlyNoneProperties(
                        pointWithProperties1, pointWithProperties2)) {
                    listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance.add(
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    continue;
                }

                if (StrikingPropertiesTools.evaluatePointsNoneMatchingANotNONEtoNotNoneProperties(
                        pointWithProperties1, pointWithProperties2)) {
                    listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance.add(
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    continue;
                }
            }
        }
    }
    //      for (Entry<Integer, List<PairPointWithDistance>> entry: mapforAllMatchingStrikingProperties.entrySet()){
    //         cleanListPairsFromPointsInvolvedInSeedPairings(resultSeed.getPairingAndNullSpaces(), entry.getValue());
    //      }
    //      cleanListPairsFromPointsInvolvedInSeedPairings(resultSeed.getPairingAndNullSpaces(), listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance);
    //      cleanListPairsFromPointsInvolvedInSeedPairings(resultSeed.getPairingAndNullSpaces(), listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance);
    //      cleanListPairsFromPointsInvolvedInSeedPairings(resultSeed.getPairingAndNullSpaces(), listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance);
    //      cleanListPairsFromPointsInvolvedInSeedPairings(resultSeed.getPairingAndNullSpaces(), listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance);

    for (Entry<Integer, List<PairPointWithDistance>> entry : mapforAllMatchingStrikingProperties.entrySet()) {
        Collections.sort(entry.getValue(), new PairPointWithDistance.LowestDistancePairPointWithDistance());
    }
    Collections.sort(listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance,
            new PairPointWithDistance.LowestDistancePairPointWithDistance());
    Collections.sort(listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance,
            new PairPointWithDistance.LowestDistancePairPointWithDistance());
    Collections.sort(listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance,
            new PairPointWithDistance.LowestDistancePairPointWithDistance());
    Collections.sort(listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance,
            new PairPointWithDistance.LowestDistancePairPointWithDistance());
    // loop on the list
    // when a point already found is found then skip the pair
    //      for (Entry<Integer, List<PairPointWithDistance>> entry: mapforAllMatchingStrikingProperties.entrySet()){
    //         cleanOfDuplicatePoints(entry.getValue());
    //      }
    //      cleanOfDuplicatePoints(listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance);
    //      cleanOfDuplicatePoints(listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance);
    //      cleanOfDuplicatePoints(listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance);
    //      cleanOfDuplicatePoints(listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance);

    // Now I should try to pair unpaired point so far
    // clean the list of pairs matching distance but without matching properties OF pairs having points in matching properties list

    globalList.clear();
    List<Integer> keys = new ArrayList<>();
    keys.addAll(mapforAllMatchingStrikingProperties.keySet());
    Collections.sort(keys, Collections.reverseOrder());
    for (Integer key : keys) {
        globalList.addAll(mapforAllMatchingStrikingProperties.get(key));
    }

    globalList.addAll(listPairsMatchingOneAmongOthersStrikingPropertiesWithShortDistance);
    globalList.addAll(listPairsMatchingOnlyNoneStrikingPropertiesWithShortDistance);
    globalList.addAll(listPairsNoneMatchingWithoutStrikingPropertiesWithShortDistance);
    globalList.addAll(listPairsNonMatchingWithoutStrikingPropertiesWithShortDistance);

    cleanOfDuplicatePoints(globalList);

    // now i can build the pairing
    // initial pairing might be on minishape and shape1 and aligned shape on a larger set like Shape
    //PairingAndNullSpaces newPairingAndNewNullSpaces = deepCopyNewPairingAndNewNullSpacesAndExtendIfNeeded(resultSeed.getPairingAndNullSpaces(), shape1, shape2);

    resultSeed.getPairingAndNullSpaces().getPairing().clear();
    emptyPairingShape1(shape1, resultSeed.getPairingAndNullSpaces());
    emptyPairingShape2(shape2, resultSeed.getPairingAndNullSpaces());

    // loop on new pairs and add
    Iterator<PairPointWithDistance> itr = globalList.iterator();
    while (itr.hasNext()) {
        PairPointWithDistance pairPointWithDistance = itr.next();
        if (pairPointWithDistance.getDistance() < 0.7) { // We really use the sorting for very short distances
            if (resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap1()
                    .contains(Integer.valueOf(pairPointWithDistance.getPairInteger().point1))
                    && resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap2()
                            .contains(Integer.valueOf(pairPointWithDistance.getPairInteger().point2))) {
                resultSeed.getPairingAndNullSpaces().getPairing().put(
                        pairPointWithDistance.getPairInteger().point1,
                        pairPointWithDistance.getPairInteger().point2);
                boolean toto = resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap1()
                        .remove(Integer.valueOf(pairPointWithDistance.getPairInteger().point1));
                boolean toto2 = resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap2()
                        .remove(Integer.valueOf(pairPointWithDistance.getPairInteger().point2));

                itr.remove();
            }
        }
    }
    Collections.sort(globalList, new PairPointWithDistance.LowestDistancePairPointWithDistance());
    Iterator<PairPointWithDistance> itr2 = globalList.iterator();
    while (itr2.hasNext()) {
        PairPointWithDistance pairPointWithDistance = itr2.next();
        if (resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap1()
                .contains(Integer.valueOf(pairPointWithDistance.getPairInteger().point1))
                && resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap2()
                        .contains(Integer.valueOf(pairPointWithDistance.getPairInteger().point2))) {
            resultSeed.getPairingAndNullSpaces().getPairing().put(pairPointWithDistance.getPairInteger().point1,
                    pairPointWithDistance.getPairInteger().point2);
            boolean toto = resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap1()
                    .remove(Integer.valueOf(pairPointWithDistance.getPairInteger().point1));
            boolean toto2 = resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap2()
                    .remove(Integer.valueOf(pairPointWithDistance.getPairInteger().point2));
        }
    }

    if (debug == true) {
        boolean validPairing = PairingTools.validate(resultSeed.getPairingAndNullSpaces());
        if (validPairing == false) {
            System.out.println("Extended pairing is not valid");
        }

        // for debug I recheck if there are remaining short distance

        List<PairPointWithDistance> remainingShortDistance = new ArrayList<>();

        for (Integer point1 : resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap1()) {
            PointWithPropertiesIfc pointWithProperties1 = shape1.getPointFromId(point1);

            for (Integer point2 : resultSeed.getPairingAndNullSpaces().getNullSpaceOfMap2()) {

                PointWithPropertiesIfc pointWithProperties2 = shape2.getPointFromId(point2);

                RealMatrix matrix = resultSeed.getRotationMatrix();
                float[] vector1 = new float[3];
                for (int k = 0; k < 3; k++) {
                    vector1[k] = (float) (pointWithProperties2.getCoords().getCoords()[k]
                            + resultSeed.getTranslationVectorToTranslateShape2ToOrigin().getEntry(k));
                }

                double[] vector2 = new double[3];
                for (int k = 0; k < 3; k++) {
                    for (int l = 0; l < 3; l++) {
                        vector2[k] += matrix.getEntry(k, l) * vector1[l];
                    }
                }

                for (int k = 0; k < 3; k++) {
                    vector1[k] = (float) (vector2[k]
                            - resultSeed.getTranslationVectorToTranslateShape2ToOrigin().getEntry(k)
                            + resultSeed.getTranslationVector().getEntry(k));
                }

                double distance = MathTools.computeDistance(pointWithProperties1.getCoords().getCoords(),
                        vector1);

                if (distance < algoParameters.getDISTANCE_MIN_FOR_EXTENDED_PAIRING_FROM_SEED()) {

                    PairPointWithDistance pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance = new PairPointWithDistance(
                            point1, point2, distance);
                    remainingShortDistance.add(
                            pairPointIdsFromMinishape1andMinishape2WithMatchingStrikingPropertiesWithDistance);
                    //System.out.println(distance);
                }
            }

        }
        System.out.println("remainingShortDistance = " + remainingShortDistance.size());

    }

}

From source file:com.act.lcms.db.analysis.WaveformAnalysis.java

/**
 * This function takes in a standard molecules's intensity vs time data and a collection of negative controls data
 * and plots the SNR value at each time period, assuming the time jitter effects are negligible (more info on this
 * is here: https://github.com/20n/act/issues/136). Based on the snr values, it rank orders the metlin ions of the
 * molecule.//  w  ww  . ja  va2 s .c  o m
 * @param ionToIntensityData A map of chemical to intensity/time data
 * @param standardChemical The chemical that is the standard of analysis
 * @return A sorted linked hash map of Metlin ion to (intensity, time) pairs from highest intensity to lowest
 */
public static LinkedHashMap<String, XZ> performSNRAnalysisAndReturnMetlinIonsRankOrderedBySNR(
        ChemicalToMapOfMetlinIonsToIntensityTimeValues ionToIntensityData, String standardChemical,
        Map<String, List<Double>> restrictedTimeWindows) {

    TreeMap<Double, List<String>> sortedIntensityToIon = new TreeMap<>(Collections.reverseOrder());
    Map<String, XZ> ionToSNR = new HashMap<>();

    for (String ion : ionToIntensityData.getMetlinIonsOfChemical(standardChemical).keySet()) {

        // We first compress the ion spectra by 5 seconds (this number was gotten from trial and error on labelled
        // spectra). Then, we do feature detection of peaks in the compressed data.
        List<XZ> standardIntensityTime = detectPeaksInIntensityTimeWaveform(
                compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(
                        ionToIntensityData.getMetlinIonsOfChemical(standardChemical).get(ion),
                        COMPRESSION_CONSTANT).getLeft(),
                PEAK_DETECTION_THRESHOLD);

        List<List<XZ>> negativeIntensityTimes = new ArrayList<>();
        for (String chemical : ionToIntensityData.getIonList()) {
            if (!chemical.equals(standardChemical)) {
                negativeIntensityTimes.add(compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(
                        ionToIntensityData.getMetlinIonsOfChemical(chemical).get(ion), COMPRESSION_CONSTANT)
                                .getLeft());
            }
        }

        List<XZ> rmsOfNegativeValues = rmsOfIntensityTimeGraphs(negativeIntensityTimes);

        List<Double> listOfTimeWindows = new ArrayList<>();
        if (restrictedTimeWindows != null && restrictedTimeWindows.get(ion) != null) {
            listOfTimeWindows.addAll(restrictedTimeWindows.get(ion));
        }

        Boolean canUpdateMaxSNRAndTime = true;
        Boolean useRestrictedTimeWindowAnalysis = false;

        // If there are restricted time windows, set the default to not update SNR until certain conditions are met.
        if (listOfTimeWindows.size() > 0) {
            useRestrictedTimeWindowAnalysis = true;
            canUpdateMaxSNRAndTime = false;
        }

        Double maxSNR = 0.0;
        Double maxTime = 0.0;

        // For each of the peaks detected in the positive control, find the spectral intensity values from the negative
        // controls and calculate SNR based on that.
        for (XZ positivePosition : standardIntensityTime) {

            Double time = positivePosition.getTime();

            XZ negativeControlPosition = null;
            for (XZ position : rmsOfNegativeValues) {
                if (position.getTime() > time - POSITION_TIME_WINDOW_IN_SECONDS
                        && position.getTime() < time + POSITION_TIME_WINDOW_IN_SECONDS) {
                    negativeControlPosition = position;
                    break;
                }
            }

            Double snr = Math.pow(positivePosition.getIntensity() / negativeControlPosition.getIntensity(), 2);

            // If the given time point overlaps with one of the restricted time windows, we can update the snr calculations.
            for (Double restrictedTimeWindow : listOfTimeWindows) {
                if ((time > restrictedTimeWindow - RESTRICTED_RETENTION_TIME_WINDOW_IN_SECONDS)
                        && (time < restrictedTimeWindow + RESTRICTED_RETENTION_TIME_WINDOW_IN_SECONDS)) {
                    canUpdateMaxSNRAndTime = true;
                    break;
                }
            }

            if (canUpdateMaxSNRAndTime) {
                maxSNR = Math.max(maxSNR, snr);
                maxTime = Math.max(maxTime, time);
            }

            if (useRestrictedTimeWindowAnalysis) {
                canUpdateMaxSNRAndTime = false;
            }
        }

        ionToSNR.put(ion, new XZ(maxTime, maxSNR));

        List<String> ionValues = sortedIntensityToIon.get(maxSNR);
        if (ionValues == null) {
            ionValues = new ArrayList<>();
            sortedIntensityToIon.put(maxSNR, ionValues);
        }

        ionValues.add(ion);
    }

    LinkedHashMap<String, XZ> result = new LinkedHashMap<>(sortedIntensityToIon.size());
    for (Map.Entry<Double, List<String>> entry : sortedIntensityToIon.entrySet()) {
        List<String> ions = entry.getValue();
        for (String ion : ions) {
            result.put(ion, ionToSNR.get(ion));
        }
    }

    return result;
}

From source file:org.addhen.smssync.presentation.view.ui.fragment.PublishedMessageFragment.java

private void deleteItems() {
    //Sort in ascending order so deleted items can be easily restored
    Comparator cmp = Collections.reverseOrder();
    Collections.sort(mPendingDeletedMessages, cmp);
    removeItems();/*from  w  w  w  .j  a  v  a 2  s .  c  o  m*/
    Snackbar snackbar = Snackbar.make(getView(),
            getActivity().getString(R.string.item_deleted, mPendingDeletedMessages.size()),
            Snackbar.LENGTH_LONG);
    snackbar.setAction(R.string.undo, e -> {
        mIsPermanentlyDeleted = false;
        // Restore items
        for (PendingDeletedMessage pendingDeletedDeployment : mPendingDeletedMessages) {
            mMessageAdapter.addItem(pendingDeletedDeployment.messageModel,
                    pendingDeletedDeployment.getPosition());
        }
        clearItems();
    });
    View view = snackbar.getView();
    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
    tv.setTextColor(getAppContext().getResources().getColor(R.color.red));
    snackbar.setCallback(new Snackbar.Callback() {
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            if (event != Snackbar.Callback.DISMISS_EVENT_ACTION) {
                if (mPendingDeletedMessages.size() > 0) {
                    for (PendingDeletedMessage pendingDeletedDeployment : mPendingDeletedMessages) {
                        mDeleteMessagePresenter
                                .deleteMessage(pendingDeletedDeployment.messageModel.getMessageUuid());
                    }
                    clearItems();
                }
            }
        }
    });
    snackbar.show();
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.NearbyBeaconsFragment.java

private void emptyGroupIdQueue() {
    List<PwPair> pwPairs = new ArrayList<>();
    for (String groupId : mGroupIdQueue) {
        Log.d(TAG, "groupid " + groupId);
        pwPairs.add(Utils.getTopRankedPwPairByGroupId(mPwCollection, groupId));
    }//from   ww w.j  ava2s . c om
    if (pwPairs != null) {
        Collections.sort(pwPairs, Collections.reverseOrder());
        for (PwPair pwPair : pwPairs) {
            mNearbyDeviceAdapter.addItem(pwPair);
        }
    }
    mGroupIdQueue.clear();
    safeNotifyChange();
}

From source file:com.sfs.whichdoctor.webservice.RotationXmlOutputImpl.java

/**
 * Builds the XML output for the training tool count.
 *
 * @param person the person/*from www. ja  va 2 s .  co  m*/
 * @param trainingType the training type
 * @return the tool count
 */
public final String getToolCount(final PersonBean person, final String trainingType) {

    Map<String, ToolCounts> toolCounts = new TreeMap<String, ToolCounts>(Collections.reverseOrder());

    if (person != null) {
        if (person.getProjects() != null) {
            for (ProjectBean project : person.getProjects()) {
                ToolCount tool = getToolCount(project, trainingType);
                if (tool != null) {
                    ToolCounts tc = new ToolCounts();
                    tc.setMeasure("program");

                    if (project.getYear() > 0) {
                        tc.setMeasure("year");
                        tc.setYear(project.getYear());
                    }

                    if (toolCounts.containsKey(tc.getOrderKey())) {
                        tc = toolCounts.get(tc.getOrderKey());
                    }
                    tc.addManualToolCount(tool);

                    toolCounts.put(tc.getOrderKey(), tc);
                }
            }
        }
        if (person.getRotations() != null) {
            for (RotationBean rotation : person.getRotations()) {
                List<ToolCount> tools = getToolCounts(rotation, trainingType);

                for (ToolCount tool : tools) {
                    // Need to check whether a manual or report
                    ToolCounts tc = new ToolCounts();
                    tc.setMeasure("year");
                    tc.setYear(rotation.getYear());

                    if (toolCounts.containsKey(tc.getOrderKey())) {
                        tc = toolCounts.get(tc.getOrderKey());
                    }
                    if (tool.isManualToolCount()) {
                        tc.addManualToolCount(tool);
                    } else {
                        tc.addReportToolCount(tool);
                    }
                    toolCounts.put(tc.getOrderKey(), tc);
                }
            }
        }
    }

    Element xml = new Element("ToolCountsInfo");

    for (String key : toolCounts.keySet()) {
        ToolCounts tcs = toolCounts.get(key);

        Element tcsXml = new Element("ToolCounts");

        String measure = "program";
        String year = "";

        if (!StringUtils.equalsIgnoreCase(tcs.getMeasure(), "program")) {
            measure = "year";
            if (tcs.getYear() > 0) {
                year = String.valueOf(tcs.getYear());
            }
        }
        tcsXml.setAttribute("measure", measure);
        tcsXml.setAttribute("year", year);

        if (tcs.getManualToolCounts().size() > 0) {
            tcsXml.addContent(getToolCountXml("manual", tcs.getManualToolCounts()));
        }
        if (tcs.getReportToolCounts().size() > 0) {
            tcsXml.addContent(getToolCountXml("report", tcs.getReportToolCounts()));
        }
        xml.addContent(tcsXml);
    }

    XMLOutputter outputter = new XMLOutputter();
    Format format = Format.getCompactFormat();
    format.setOmitDeclaration(true);

    outputter.setFormat(format);

    return outputter.outputString(new Document(xml));
}

From source file:org.agnitas.web.CampaignAction.java

private void setSortedMailingList(Campaign.Stats stat, HttpServletRequest req, CampaignForm aForm) {
    LinkedList<Number> resultList = new LinkedList<Number>();
    MailingDao mailDao = (MailingDao) getBean("MailingDao");

    // this hashmap contains the mapping from a Date back to the Mail-ID.
    HashMap<Date, Number> tmpDate2MailIDMapping = new HashMap<Date, Number>();
    LinkedList<Date> sortedMailingList = new LinkedList<Date>();

    Hashtable map = stat.getMailingData(); // holds the complete mailing Data
    map.keySet(); // all keys for the mailingData (mailIDs)

    Number tmpMailID = null;/*from   w  ww .j  av  a 2  s  .  co m*/
    MaildropEntry tmpEntry = null;
    Mailing tmpMailing = null;

    // loop over all keys.
    Iterator it = map.keySet().iterator();
    while (it.hasNext()) {
        LinkedList<Date> sortDates = new LinkedList<Date>();
        tmpMailID = (Number) it.next(); // get the mailID   
        // get one Mailing with tmpMailID
        tmpMailing = (Mailing) mailDao.getMailing(tmpMailID.intValue(), getCompanyID(req));
        // check if it is a World-Mailing. We have testmailings and dont care about them!
        if (tmpMailing.isWorldMailingSend() == true) {
            // loop over all tmpMailingdropStatus.
            // we look over all mails and take the first send mailing Time.
            // unfortunately is the set not sorted, so we have to sort it ourself.
            Iterator it2 = tmpMailing.getMaildropStatus().iterator();
            while (it2.hasNext()) {
                tmpEntry = (MaildropEntry) it2.next();
                sortDates.add(tmpEntry.getSendDate());
            }
            // check if sortDates has entries and put the one into the Hashmap.
            if (sortDates.size() != 0) {
                Collections.sort(sortDates);
                tmpDate2MailIDMapping.put(sortDates.get(0), tmpMailID);
                sortedMailingList.add(sortDates.get(0));
            }
        }
    }
    // at this point, we have a Hashmap with all Dates and Mailing ID's and a List with all Date's.
    // now we sort this List and put the result into the Form (sort with reverse Order ;-) ).
    Collections.sort(sortedMailingList, Collections.reverseOrder());
    // loop over the List and put the corresponding MailID into the List.
    for (int i = 0; i < sortedMailingList.size(); i++) {
        resultList.add(tmpDate2MailIDMapping.get(sortedMailingList.get(i)));
    }
    aForm.setSortedKeys(resultList);
}

From source file:eu.uqasar.model.tree.Project.java

/**
 * @return a List with all the historic values
 *///  ww  w.j a va  2  s .  c o m
public List<HistoricValuesProject> getHistoricValues() {
    Collections.sort(this.historicValues, Collections.reverseOrder());
    return historicValues;
}

From source file:org.tightblog.rendering.generators.WeblogEntryListGeneratorTest.java

private Map<LocalDate, List<WeblogEntry>> createSampleEntriesMap() {
    WeblogEntry we1 = WebloggerTest.genWeblogEntry(weblog, "day1story1", twoDaysAgo);
    WeblogEntry we2 = WebloggerTest.genWeblogEntry(weblog, "day1story2", twoDaysAgo);
    WeblogEntry we3 = WebloggerTest.genWeblogEntry(weblog, "day2story1", threeDaysAgo);
    WeblogEntry we4 = WebloggerTest.genWeblogEntry(weblog, "day2story2", threeDaysAgo);
    List<WeblogEntry> listNow = new ArrayList<>();
    listNow.add(we1);// www.j a v a  2  s  . c  o  m
    listNow.add(we2);
    List<WeblogEntry> listYesterday = new ArrayList<>();
    listYesterday.add(we3);
    // won't be returned as maxEntries = 3
    listYesterday.add(we4);

    Map<LocalDate, List<WeblogEntry>> entryMap = new TreeMap<>(Collections.reverseOrder());
    entryMap.put(nowLD, listNow);
    entryMap.put(yesterdayLD, listYesterday);

    return entryMap;
}

From source file:org.fenixedu.academic.domain.Teacher.java

public Stream<TeacherAuthorization> getRevokedTeacherAuthorizationStream() {
    return getRevokedAuthorizationSet().stream().sorted(Collections.reverseOrder());
}