Example usage for java.util Collections max

List of usage examples for java.util Collections max

Introduction

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

Prototype

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) 

Source Link

Document

Returns the maximum element of the given collection, according to the natural ordering of its elements.

Usage

From source file:au.org.ala.delta.intkey.ui.CharacterImageDialog.java

public FloatRange getInputRealValues() {
    FloatRange retRange = null;/*  ww  w  .j  av  a  2  s.c  om*/

    String inputText = _multipleImageViewer.getVisibleViewer().getInputText();

    if (!StringUtils.isEmpty(inputText)) {
        // Use value supplied in input field
        retRange = ParsingUtils.parseRealCharacterValue(inputText);
    } else {
        // Use values for selected value fields
        if (!_selectedValues.isEmpty()) {
            Set<Float> boundsSet = new HashSet<Float>();
            for (Pair<String, String> selectedValue : _selectedValues) {
                float minVal = Float.parseFloat(selectedValue.getFirst());
                boundsSet.add(minVal);

                // Second value in the pair will be null if the value field
                // represents a
                // single real value rather than a range.
                if (selectedValue.getSecond() != null) {
                    float maxVal = Float.parseFloat(selectedValue.getSecond());
                    boundsSet.add(maxVal);
                }
            }

            float overallMin = Collections.min(boundsSet);
            float overallMax = Collections.max(boundsSet);
            retRange = new FloatRange(overallMin, overallMax);
        }
    }

    // if the range is still null, return a float range with negative
    // infinity. This represents "no values selected".
    if (retRange == null) {
        retRange = new FloatRange(Float.NEGATIVE_INFINITY);
    }

    return retRange;
}

From source file:de.tud.kom.p2psim.impl.network.gnp.topology.GnpSpace.java

/**
 * Calculates a good positions for the host
 * //from   ww w  .  jav  a 2  s . c o m
 * @param host
 *            to position
 * @param monitorResheduling
 *            number of rescheduling the downhill simplex
 * @return gnp position for peer
 */
private GnpPosition insertCoordinateDownhillSimplex(Host host, int monitorResheduling) {

    double alpha = 1.0;
    double beta = 0.5;
    double gamma = 2;
    double maxDiversity = 0.5;

    // N + 1 initial random Solutions
    ArrayList<GnpPosition> solutions = new ArrayList<GnpPosition>(noOfDimensions + 1);

    for (int c = -1; c < noOfDimensions; c++) {
        GnpPosition coord = new GnpPosition(noOfDimensions, host, this);
        solutions.add(coord);
    }

    // best and worst solution
    GnpPosition bestSolution = Collections.min(solutions);
    GnpPosition worstSolution = Collections.max(solutions);
    double bestError = bestSolution.getDownhillSimplexError();
    double worstError = worstSolution.getDownhillSimplexError();

    double newError = 0.0;

    for (int z = 0; z < monitorResheduling; z++) {

        // resheduling
        for (GnpPosition coord : solutions) {
            if (coord != bestSolution) {
                coord.diversify(this.getDimension(), maxDiversity);
            }
        }

        // best and worst solution
        bestSolution = Collections.min(solutions);
        worstSolution = Collections.max(solutions);
        bestError = bestSolution.getDownhillSimplexError();
        worstError = worstSolution.getDownhillSimplexError();

        // stop criterion
        while (worstError - bestError > 0.000001 && calculationInProgress) {

            // move to center ...
            GnpPosition center = GnpPosition.getCenterSolution(solutions);
            GnpPosition newSolution1 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha);
            newError = newSolution1.getDownhillSimplexError();
            if (newError <= bestError) {
                GnpPosition newSolution2 = GnpPosition.getMovedSolution(worstSolution, center,
                        1 + alpha + gamma);
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                if (newSolution2.getDownhillSimplexError() <= newError) {
                    solutions.set(IndexOfWorstSolution, newSolution2);
                } else {
                    solutions.set(IndexOfWorstSolution, newSolution1);
                }
                bestSolution = solutions.get(IndexOfWorstSolution);
                bestError = bestSolution.getDownhillSimplexError();
            } else if (newError < worstError) {
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                solutions.set(IndexOfWorstSolution, newSolution1);
            } else { // ... or contract around best solution
                for (int c = 0; c < solutions.size(); c++) {
                    if (solutions.get(c) != bestSolution)
                        solutions.set(c, GnpPosition.getMovedSolution(solutions.get(c), bestSolution, beta));
                }
                bestSolution = Collections.min(solutions);
                bestError = bestSolution.getDownhillSimplexError();
            }
            worstSolution = Collections.max(solutions);
            worstError = worstSolution.getDownhillSimplexError();
        }
    }

    // Set the Coordinate Reference to the Peer
    host.setPositionReference(bestSolution);
    return bestSolution;
}

From source file:org.peerfact.impl.network.gnp.topology.GnpSpace.java

/**
 * Calculates a good positions for the host
 * // ww  w  . j a v a2s  . c om
 * @param host
 *            to position
 * @param monitorResheduling
 *            number of rescheduling the downhill simplex
 * @return gnp position for peer
 */
private GnpPosition insertCoordinateDownhillSimplex(Host host, int monitorResheduling) {

    double alpha = 1.0;
    double beta = 0.5;
    double gamma = 2;
    double maxDiversity = 0.5;

    // N + 1 initial random Solutions
    ArrayList<GnpPosition> solutions = new ArrayList<GnpPosition>(noOfDimensions + 1);

    for (int c = -1; c < noOfDimensions; c++) {
        GnpPosition coord = new GnpPosition(noOfDimensions, host, this);
        solutions.add(coord);
    }

    // best and worst solution
    GnpPosition bestSolution = Collections.min(solutions);
    GnpPosition worstSolution = Collections.max(solutions);
    double bestError = bestSolution.getDownhillSimplexError();
    double worstError = worstSolution.getDownhillSimplexError();

    double newError = 0.0;

    for (int z = 0; z < monitorResheduling; z++) {

        // resheduling
        for (GnpPosition coord : solutions) {
            if (coord != bestSolution) {
                coord.diversify(this.getDimension(), maxDiversity);
            }
        }

        // best and worst solution
        bestSolution = Collections.min(solutions);
        worstSolution = Collections.max(solutions);
        bestError = bestSolution.getDownhillSimplexError();
        worstError = worstSolution.getDownhillSimplexError();

        // stop criterion
        while (worstError - bestError > 0.000001 && calculationInProgress) {

            // move to center ...
            GnpPosition center = GnpPosition.getCenterSolution(solutions);
            GnpPosition newSolution1 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha);
            newError = newSolution1.getDownhillSimplexError();
            if (newError <= bestError) {
                GnpPosition newSolution2 = GnpPosition.getMovedSolution(worstSolution, center,
                        1 + alpha + gamma);
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                if (newSolution2.getDownhillSimplexError() <= newError) {
                    solutions.set(IndexOfWorstSolution, newSolution2);
                } else {
                    solutions.set(IndexOfWorstSolution, newSolution1);
                }
                bestSolution = solutions.get(IndexOfWorstSolution);
                bestError = bestSolution.getDownhillSimplexError();
            } else if (newError < worstError) {
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                solutions.set(IndexOfWorstSolution, newSolution1);
            } else { // ... or contract around best solution
                for (int c = 0; c < solutions.size(); c++) {
                    if (solutions.get(c) != bestSolution) {
                        solutions.set(c, GnpPosition.getMovedSolution(solutions.get(c), bestSolution, beta));
                    }
                }
                bestSolution = Collections.min(solutions);
                bestError = bestSolution.getDownhillSimplexError();
            }
            worstSolution = Collections.max(solutions);
            worstError = worstSolution.getDownhillSimplexError();
        }
    }

    // Set the Coordinate Reference to the Peer
    host.setPositionReference(bestSolution);
    return bestSolution;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.tcf.TcfReader.java

/**
 * Get the start and end offsets of a span annotation
 * //from   w ww.  j a v  a  2  s  .c  o  m
 * @param aSpanTokens
 *            list of span {@link eu.clarin.weblicht.wlfxb.tc.api.Token}s
 * @param aAllTokens
 *            all available tokens in the file
 */
private int[] getOffsets(eu.clarin.weblicht.wlfxb.tc.api.Token[] aSpanTokens, Map<String, Token> aAllTokens) {
    List<Integer> beginPositions = new ArrayList<Integer>();
    List<Integer> endPositions = new ArrayList<Integer>();
    for (eu.clarin.weblicht.wlfxb.tc.api.Token token : aSpanTokens) {
        beginPositions.add(aAllTokens.get(token.getID()).getBegin());
        endPositions.add(aAllTokens.get(token.getID()).getEnd());
    }
    return new int[] { (Collections.min(beginPositions)), (Collections.max(endPositions)) };
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double[][] normalizeIm(float[][] imIn) {
    // Normalize single-channel image pixel values to [0, 1]
    int imWidth = imIn.length;
    int imHeight = imIn[0].length;
    double imOut[][] = new double[imWidth][imHeight];
    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;
    double colMin, colMax;
    for (float[] imInRow : imIn) {
        List<Float> b = Arrays.asList(ArrayUtils.toObject(imInRow));
        colMin = (float) Collections.min(b);
        if (colMin < min) {
            min = colMin;/*  w  ww.j a  v a 2  s . c  o  m*/
        }
        colMax = (float) Collections.max(b);
        if (colMax > max) {
            max = colMax;
        }
    }
    double spread = max - min;
    for (int ii = 0; ii < imWidth; ii++) {
        for (int jj = 0; jj < imHeight; jj++) {
            imOut[ii][jj] = (imIn[ii][jj] - min) / spread;
        }
    }
    return imOut;
}

From source file:com.vgi.mafscaling.OpenLoop.java

private void setRanges() {
    double paddingX;
    double paddingY;
    XYPlot plot = mafChartPanel.getChartPanel().getChart().getXYPlot();
    plot.getDomainAxis(0).setLabel(XAxisName);
    plot.getRangeAxis(1).setLabel(Y2AxisName);
    plot.getRangeAxis(0).setVisible(true);
    if (checkBoxMafRpmData.isSelected() && checkBoxMafRpmData.isEnabled()) {
        paddingX = runData.getMaxX() * 0.05;
        paddingY = runData.getMaxY() * 0.05;
        plot.getDomainAxis(0).setRange(runData.getMinX() - paddingX, runData.getMaxX() + paddingX);
        plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY);
        plot.getRangeAxis(0).setVisible(false);
        plot.getRangeAxis(1).setLabel(XAxisName);
        plot.getDomainAxis(0).setLabel(rpmAxisName);
    } else if (checkBoxRunData.isSelected() && checkBoxRunData.isEnabled() && !checkBoxCurrentMaf.isSelected()
            && !checkBoxCorrectedMaf.isSelected() && !checkBoxSmoothedMaf.isSelected()) {
        paddingX = runData.getMaxX() * 0.05;
        paddingY = runData.getMaxY() * 0.05;
        plot.getDomainAxis(0).setRange(runData.getMinX() - paddingX, runData.getMaxX() + paddingX);
        plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY);
    } else if (checkBoxSmoothing.isSelected()) {
        double maxY = Collections.max(Arrays.asList(
                new Double[] { currMafData.getMaxY(), smoothMafData.getMaxY(), corrMafData.getMaxY() }));
        double minY = Collections.min(Arrays.asList(
                new Double[] { currMafData.getMinY(), smoothMafData.getMinY(), corrMafData.getMinY() }));
        paddingX = smoothMafData.getMaxX() * 0.05;
        paddingY = maxY * 0.05;//from   w w  w  .jav  a 2s .co m
        plot.getDomainAxis(0).setRange(smoothMafData.getMinX() - paddingX, smoothMafData.getMaxX() + paddingX);
        plot.getRangeAxis(0).setRange(minY - paddingY, maxY + paddingY);
    } else if ((checkBoxCurrentMaf.isSelected() && checkBoxCurrentMaf.isEnabled())
            || (checkBoxCorrectedMaf.isSelected() && checkBoxCorrectedMaf.isEnabled())
            || (checkBoxSmoothedMaf.isSelected() && checkBoxSmoothedMaf.isEnabled())) {
        paddingX = voltArray.get(voltArray.size() - 1) * 0.05;
        paddingY = gsCorrected.get(gsCorrected.size() - 1) * 0.05;
        plot.getDomainAxis(0).setRange(voltArray.get(0) - paddingX,
                voltArray.get(voltArray.size() - 1) + paddingX);
        plot.getRangeAxis(0).setRange(gsCorrected.get(0) - paddingY,
                gsCorrected.get(gsCorrected.size() - 1) + paddingY);
        if (checkBoxRunData.isSelected()) {
            paddingX = runData.getMaxX() * 0.05;
            paddingY = runData.getMaxY() * 0.05;
            plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY);
        }
    } else {
        plot.getRangeAxis(0).setAutoRange(true);
        plot.getDomainAxis(0).setAutoRange(true);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.tcf.TcfReader.java

/**
 * Get the start and end offsets of a span annotation
 * //from   w  w  w . j  a v  a  2s .c  o m
 * @param aSpanTokens
 *            list of span token ids. [t_3,_t_5, t_1]
 * @param aAllTokens
 *            all available tokens in the file
 */
private int[] getOffsets(String[] aSpanTokens, Map<String, Token> aAllTokens) {
    List<Integer> beginPositions = new ArrayList<Integer>();
    List<Integer> endPositions = new ArrayList<Integer>();
    for (String token : aSpanTokens) {
        beginPositions.add(aAllTokens.get(token).getBegin());
        endPositions.add(aAllTokens.get(token).getEnd());
    }
    return new int[] { (Collections.min(beginPositions)), (Collections.max(endPositions)) };
}

From source file:org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming.java

/**
 * Combines the status results from a list of parallel branches to report a single overall status
 * @param statuses//from w  ww  . j  a v  a 2s .  c  o  m
 * @return Status, or null if none can be defined
 */
@CheckForNull
public static GenericStatus condenseStatus(@Nonnull Collection<GenericStatus> statuses) {
    if (statuses.isEmpty()) {
        return null;
    }
    return Collections.max(statuses);
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double[][] normalizeIm(double[][] imIn) {
    // Normalize single-channel image pixel values to [0, 1]
    int imWidth = imIn.length;
    int imHeight = imIn[0].length;
    double imOut[][] = new double[imWidth][imHeight];
    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;
    double colMin, colMax;
    for (double[] imInRow : imIn) {
        List<Double> b = Arrays.asList(ArrayUtils.toObject(imInRow));
        colMin = (double) Collections.min(b);
        if (colMin < min) {
            min = colMin;/*from   ww w. j  a  v  a2 s . c o m*/
        }
        colMax = (double) Collections.max(b);
        if (colMax > max) {
            max = colMax;
        }
    }
    double spread = max - min;
    for (int ii = 0; ii < imWidth; ii++) {
        for (int jj = 0; jj < imHeight; jj++) {
            imOut[ii][jj] = (imIn[ii][jj] - min) / spread;
        }
    }
    return imOut;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRResultsController.java

/**
 * Create PdfTable with info on each condition of the analysis group;
 *
 * @return/*  ww  w . j a v a  2  s  .c  o  m*/
 */
//possibly reuse dRInputController's createTableModel(List<PlateCondition> processedConditions)
@Override
protected PdfPTable createAnalysisGroupInfoTable() {
    //maps log transformed conc (double) to list of velocities (double)
    List<DoseResponsePair> fittedData = doseResponseController.getDataToFit(false);
    //CONTROL HAS BEEN GIVEN A CONCENTRATION FOR FITTING PURPOSES: find control concentration (lowest)
    List<Double> allConcentrations = new ArrayList<>();
    for (DoseResponsePair row : fittedData) {
        allConcentrations.add(row.getDose());
    }
    Double controlConcentration = Collections.min(allConcentrations);

    // new table with 6 columns
    PdfPTable dataTable = new PdfPTable(6);
    PdfUtils.setUpPdfPTable(dataTable);
    // add 1st row: column names
    PdfUtils.addCustomizedCell(dataTable, "DRUG CONCENTRATION", boldFont);
    PdfUtils.addCustomizedCell(dataTable, "# TECHNICAL REPLICATES", boldFont);
    PdfUtils.addCustomizedCell(dataTable, "TECHNICAL REPLICATES EXCLUDED?", boldFont);
    PdfUtils.addCustomizedCell(dataTable, "LOWEST VELOCITY", boldFont);
    PdfUtils.addCustomizedCell(dataTable, "HIGHEST VELOCITY", boldFont);
    PdfUtils.addCustomizedCell(dataTable, "MEDIAN VELOCITY", boldFont);

    // for each condition get results and add a cell
    for (DoseResponsePair condition : fittedData) {
        Integer replicates = condition.getResponses().size();
        String excluded;
        int excludedCount = 0;
        List<Double> velocities = condition.getResponses();

        //count how many replicates were excluded
        for (int i = 0; i < velocities.size(); i++) {
            Double replicate = velocities.get(i);
            if (replicate == null) {
                excludedCount++;
            }
        }
        if (excludedCount == 0) {
            excluded = "NO";
        } else {
            excluded = "YES, " + excludedCount;
        }

        //put log-value of the concentration back to an understandable format
        String concentration;
        Double logConc = condition.getDose();
        Double transformed = Math.pow(10, logConc);
        //check which concentration unit is to be used
        //if lower than 0.1 M: use nM unit
        if (transformed < Math.pow(10, -7)) {
            concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 9)) + " nM";
        } //if lower than 0.1 mM: use M unit
        else if (transformed < Math.pow(10, -3)) {
            concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 6)) + " M";
        } //else for everything >= 1 mM use mM unit
        else {
            concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 3)) + " mM";
        }
        //if this is the control, replace concentration string
        if (logConc.equals(controlConcentration)) {
            concentration = "Control";
        }
        //remove null's (excluded replicates) from velocities collection
        velocities.removeAll(Collections.singleton(null));

        PdfUtils.addCustomizedCell(dataTable, concentration, bodyFont);
        PdfUtils.addCustomizedCell(dataTable, replicates.toString(), bodyFont);
        PdfUtils.addCustomizedCell(dataTable, excluded, bodyFont);
        PdfUtils.addCustomizedCell(dataTable,
                AnalysisUtils.roundThreeDecimals(Collections.min(velocities)).toString(), bodyFont);
        PdfUtils.addCustomizedCell(dataTable,
                AnalysisUtils.roundThreeDecimals(Collections.max(velocities)).toString(), bodyFont);
        PdfUtils.addCustomizedCell(dataTable,
                AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeMedian(velocities)).toString(), bodyFont);

    }

    return dataTable;
}