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:net.awired.visuwall.plugin.teamcity.TeamCityConnection.java

@Override
public int getLastBuildNumber(SoftwareProjectId softwareProjectId)
        throws ProjectNotFoundException, BuildNumberNotFoundException {
    checkConnected();/*  w w w .jav a2 s.c om*/
    checkSoftwareProjectId(softwareProjectId);
    List<Integer> buildNumbers = getBuildNumbers(softwareProjectId);
    if (buildNumbers.isEmpty()) {
        throw new BuildNumberNotFoundException(
                "Can't find build numbers for software project id : " + softwareProjectId);
    }
    Integer lastBuildNumber = Collections.max(buildNumbers);
    return lastBuildNumber;
}

From source file:org.openmrs18.Concept.java

/**
 * Add the given ConceptAnswer to the list of answers for this Concept
 * /*from  www  .j  a v  a  2  s .  co  m*/
 * @param conceptAnswer
 * @should add the ConceptAnswer to Concept
 * @should not fail if answers list is null
 * @should not fail if answers contains ConceptAnswer already
 * @should set the sort weight to the max plus one if not provided
 */
public void addAnswer(ConceptAnswer conceptAnswer) {
    if (conceptAnswer != null) {
        if (getAnswers(true) == null) {
            answers = new HashSet<ConceptAnswer>();
            conceptAnswer.setConcept(this);
            answers.add(conceptAnswer);
        } else if (!answers.contains(conceptAnswer)) {
            conceptAnswer.setConcept(this);
            answers.add(conceptAnswer);
        }

        if ((conceptAnswer.getSortWeight() == null) || (conceptAnswer.getSortWeight() <= 0)) {
            //find largest sort weight
            ConceptAnswer a = Collections.max(answers);
            Double sortWeight = (a == null) ? 1d : ((a.getSortWeight() == null) ? 1d : a.getSortWeight() + 1d);//a.sortWeight can be NULL
            conceptAnswer.setSortWeight(sortWeight);
        }
    }
}

From source file:org.sakaiproject.gradebookng.tool.panels.AssignmentStatisticsPanel.java

private String constructHighestLabel(final List<Double> allGrades, final Assignment assignment) {
    final double highest = Collections.max(allGrades);
    final String highestFormatted = FormatHelper.formatDoubleToDecimal(Double.valueOf(highest));

    if (GradingType.PERCENTAGE.equals(this.gradingType)) {
        return (new StringResourceModel("label.percentage.valued", null, new Object[] { highestFormatted }))
                .getString();/*from  w w w. j  a  v  a 2  s.  com*/
    }

    final Double total = assignment.getPoints();
    final String percentage = FormatHelper.formatDoubleAsPercentage(100 * (highest / total.doubleValue()));

    return new StringResourceModel("label.statistics.highestvalue", null,
            new Object[] { highestFormatted, FormatHelper.formatGrade(String.valueOf(total)), percentage })
                    .getString();
}

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

/**
 * //from www  .  j  av  a2  s  .c o  m
 * @param noOfDimensions
 *            number of Dimensions must be smaller than number of Monitors
 * @param monitorResheduling
 *            number of rescheduling the downhill simplex
 * @param mapRef
 *            reference to HostMap
 * @return optimized positions for Monitors
 */
private static GnpSpace getGnpWithDownhillSimplex(int noOfDimensions, int monitorResheduling, HostMap mapRef) {

    GnpSpace.calculationStepStatus = 1;
    GnpSpace.calculationInProgress = true;

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

    // N + 1 initial random Solutions
    int dhs_N = mapRef.getNoOfMonitors();
    ArrayList<GnpSpace> solutions = new ArrayList<GnpSpace>(dhs_N + 1);
    for (int c = 0; c < dhs_N + 1; c++)
        solutions.add(new GnpSpace(noOfDimensions, mapRef));

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

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

        // resheduling
        int count = 0;
        for (GnpSpace gnp : solutions) {
            if (gnp != bestSolution) {
                GnpPosition monitor = gnp.getMonitorPosition(count);
                monitor.diversify(gnp.getDimension(), maxDiversity);
                count++;
            }
        }

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

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

            // move to center ...
            GnpSpace center = GnpSpace.getCenterSolution(solutions);
            GnpSpace newSolution1 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha);
            double newError1 = newSolution1.getObjectiveValueMonitor();
            if (newError1 <= bestError) {
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                GnpSpace newSolution2 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha + gamma);
                double newError2 = newSolution2.getObjectiveValueMonitor();
                if (newError2 <= newError1) {
                    solutions.set(IndexOfWorstSolution, newSolution2);
                    bestError = newError2;
                } else {
                    solutions.set(IndexOfWorstSolution, newSolution1);
                    bestError = newError1;
                }
                bestSolution = solutions.get(IndexOfWorstSolution);
            } else if (newError1 < 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, GnpSpace.getMovedSolution(solutions.get(c), bestSolution, beta));
                }
                bestSolution = Collections.min(solutions);
                bestError = bestSolution.getObjectiveValueMonitor();
            }
            worstSolution = Collections.max(solutions);
            worstError = worstSolution.getObjectiveValueMonitor();
        }

    }

    // Set the Coordinate Reference to the Peer
    for (int c = 0; c < bestSolution.getNumberOfMonitors(); c++) {
        bestSolution.getMonitorPosition(c).getHostRef()
                .setPositionReference(bestSolution.getMonitorPosition(c));
    }

    // GnpSpace.calculationStepStatus = 0;
    // GnpSpace.calculationInProgress = false;
    return bestSolution;
}

From source file:com.google.appengine.tools.mapreduce.v2.impl.MapReduceState.java

/**
 * Update this state to reflect the given set of mapper call counts.
 *//*from   w  ww .  ja v  a  2  s  .c om*/
public void setProcessedCounts(List<Long> processedCounts) {
    if (processedCounts == null || processedCounts.size() == 0) {
        return;
    }

    // If max == 0, the numeric range will be from 0 to 0. This causes some
    // problems when scaling to the range, so add 1 to max, assuming that the
    // smallest value can be 0, and this ensures that the chart always shows,
    // at a minimum, a range from 0 to 1 - when all shards are just starting.
    long maxPlusOne = Collections.max(processedCounts) + 1;

    List<String> countLabels = new ArrayList<String>();
    for (int i = 0; i < processedCounts.size(); i++) {
        countLabels.add(String.valueOf(i));
    }

    Data countData = DataUtil.scaleWithinRange(0, maxPlusOne, processedCounts);

    // TODO(user): Rather than returning charts from both servers, let's just
    // do it on the client's end.
    Plot countPlot = Plots.newBarChartPlot(countData);
    BarChart countChart = GCharts.newBarChart(countPlot);
    countChart.addYAxisLabels(AxisLabelsFactory.newNumericRangeAxisLabels(0, maxPlusOne));
    countChart.addXAxisLabels(AxisLabelsFactory.newAxisLabels(countLabels));
    countChart.setSize(300, 200);
    countChart.setBarWidth(BarChart.AUTO_RESIZE);
    countChart.setSpaceBetweenGroupsOfBars(1);
    entity.setUnindexedProperty(CHART_PROPERTY, new Text(countChart.toURLString()));
}

From source file:fNIRs.FNIRsStats.java

private static int getIdFieldWidth(List<String> groupNames, List<Integer> conditions, int precision) {
    // calculate required widths for printed names and condition numbers:
    int nameWidth = longestLength(groupNames); // length of longest name
    int conditionWidth = // number of digits in the largest condition number
            String.valueOf(Collections.max(conditions)).length();
    // make sure the fields will be wide enough to hold the ANOVA values,
    // which will consist of a 0 or 1 followed by a . and precision 0s:
    // AM I USING "PRECISION" RIGHT?
    int result = nameWidth + 2 + conditionWidth; // 2 == " c".length()
    if (result < precision + 2) { // 2 == "1.".length()
        // if not, increase the condition width so the total field width is
        // large enough:
        // System.out.println("ANOVA values are wider than identifiers.");
        result = precision + 2;//  ww w.ja  v a 2  s.  c o m
    }
    return result;
}

From source file:org.libreplan.business.workingday.EffortDuration.java

public static EffortDuration max(EffortDuration... durations) {
    return Collections.max(Arrays.asList(durations));
}

From source file:com.google.appengine.tools.mapreduce.MapReduceState.java

/**
 * Update this state to reflect the given set of mapper call counts.
 */// w  w w.ja  va 2 s  .  co m
public void setProcessedCounts(List<Long> processedCounts) {
    if (processedCounts == null || processedCounts.size() == 0) {
        return;
    }

    // If max == 0, the numeric range will be from 0 to 0. This causes some
    // problems when scaling to the range, so add 1 to max, assuming that the
    // smallest value can be 0, and this ensures that the chart always shows,
    // at a minimum, a range from 0 to 1 - when all shards are just starting.
    long maxPlusOne = Collections.max(processedCounts) + 1;

    List<String> countLabels = new ArrayList<String>();
    for (int i = 0; i < processedCounts.size(); i++) {
        countLabels.add(String.valueOf(i));
    }

    Data countData = DataUtil.scaleWithinRange(0, maxPlusOne, processedCounts);

    // TODO(frew): Rather than returning charts from both servers, let's just
    // do it on the client's end.
    Plot countPlot = Plots.newBarChartPlot(countData);
    BarChart countChart = GCharts.newBarChart(countPlot);
    countChart.addYAxisLabels(AxisLabelsFactory.newNumericRangeAxisLabels(0, maxPlusOne));
    countChart.addXAxisLabels(AxisLabelsFactory.newAxisLabels(countLabels));
    countChart.setSize(300, 200);
    countChart.setBarWidth(BarChart.AUTO_RESIZE);
    countChart.setSpaceBetweenGroupsOfBars(1);
    entity.setUnindexedProperty(CHART_PROPERTY, new Text(countChart.toURLString()));
}

From source file:io.hummer.util.test.GenericTestResult.java

public List<Double> getValues(String valueNameOrPattern, boolean addZeroes, boolean treatNameAsPattern) {
    List<Double> result = new LinkedList<Double>();
    for (IterationResult r : iterations) {
        for (Entry e : r.getEntries()) {
            if ((!treatNameAsPattern && e.getName().equals(valueNameOrPattern))
                    || (treatNameAsPattern && e.getName().matches(valueNameOrPattern))) {
                double val = e.getValue();
                if (addZeroes || val != 0.0)
                    result.add(val);
            }//from  w  w  w .java  2 s.co  m
        }
    }
    if (result.size() > eliminateXhighestValues) {
        for (int i = 0; i < eliminateXhighestValues; i++) {
            Double max = Collections.max(result);
            result.remove(max);
        }
    }
    if (result.size() > eliminateXlowestValues) {
        for (int i = 0; i < eliminateXlowestValues; i++) {
            Double min = Collections.min(result);
            result.remove(min);
        }
    }
    return result;
}

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

/**
 * /*from  w ww. j a  va2 s.c  om*/
 * @param noOfDimensions
 *            number of Dimensions must be smaller than number of Monitors
 * @param monitorResheduling
 *            number of rescheduling the downhill simplex
 * @param mapRef
 *            reference to HostMap
 * @return optimized positions for Monitors
 */
private static GnpSpace getGnpWithDownhillSimplex(int noOfDimensions, int monitorResheduling, HostMap mapRef) {

    GnpSpace.calculationStepStatus = 1;
    GnpSpace.calculationInProgress = true;

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

    // N + 1 initial random Solutions
    int dhs_N = mapRef.getNoOfMonitors();
    ArrayList<GnpSpace> solutions = new ArrayList<GnpSpace>(dhs_N + 1);
    for (int c = 0; c < dhs_N + 1; c++) {
        solutions.add(new GnpSpace(noOfDimensions, mapRef));
    }

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

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

        // resheduling
        int count = 0;
        for (GnpSpace gnp : solutions) {
            if (gnp != bestSolution) {
                GnpPosition monitor = gnp.getMonitorPosition(count);
                monitor.diversify(gnp.getDimension(), maxDiversity);
                count++;
            }
        }

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

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

            // move to center ...
            GnpSpace center = GnpSpace.getCenterSolution(solutions);
            GnpSpace newSolution1 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha);
            double newError1 = newSolution1.getObjectiveValueMonitor();
            if (newError1 <= bestError) {
                int IndexOfWorstSolution = solutions.indexOf(worstSolution);
                GnpSpace newSolution2 = GnpSpace.getMovedSolution(worstSolution, center, 1 + alpha + gamma);
                double newError2 = newSolution2.getObjectiveValueMonitor();
                if (newError2 <= newError1) {
                    solutions.set(IndexOfWorstSolution, newSolution2);
                    bestError = newError2;
                } else {
                    solutions.set(IndexOfWorstSolution, newSolution1);
                    bestError = newError1;
                }
                bestSolution = solutions.get(IndexOfWorstSolution);
            } else if (newError1 < 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, GnpSpace.getMovedSolution(solutions.get(c), bestSolution, beta));
                    }
                }
                bestSolution = Collections.min(solutions);
                bestError = bestSolution.getObjectiveValueMonitor();
            }
            worstSolution = Collections.max(solutions);
            worstError = worstSolution.getObjectiveValueMonitor();
        }

    }

    // Set the Coordinate Reference to the Peer
    for (int c = 0; c < bestSolution.getNumberOfMonitors(); c++) {
        bestSolution.getMonitorPosition(c).getHostRef()
                .setPositionReference(bestSolution.getMonitorPosition(c));
    }

    // GnpSpace.calculationStepStatus = 0;
    // GnpSpace.calculationInProgress = false;
    return bestSolution;
}