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:org.egov.infra.gis.service.GeoLocationService.java

/**
 * // w  w  w .j  a v a  2 s  .  c o m
 * @param wardWiseData Map<String, Integer>- Map having the key as the ward number and value as the no of complaints/properties/assets
 *    in that ward. e.g [<Ward Number>,<no Of Complaints/assets/properties> ]
 * 
 * @param colorCodes Map<Integer,String> - Map having colour codes , the key as the the colour priority and value as the colour 
 * code in RGB format. e.g - key = 1 , means the associated colour to represent the ward having  no of complaints/assets/properties
 * that falls in highest range , key = 2 means associated colour to represent ward having  no of complaints/assets/properties
 * that falls in the 2nd highest range and so on.
 * example :  (1, "FF0000");
 *           (2, "8968CD");
 *            (3, "FFA500");
 *            (4, "4169E1");
 *            (5, "008B00");
 */

public static void setKmlDataToCacheAndRequest(Map<String, BigDecimal> wardWiseData,
        Map<Integer, String> colorCodes, String kmlPath, HttpServletRequest request) {

    LOGGER.debug("GeoLocationService | setKmlDataToCacheAndRequest | Start");

    int totalNoOfColors = colorCodes.size();
    BigDecimal wardDataMinAmount = Collections.min(wardWiseData.values()).setScale(0, BigDecimal.ROUND_HALF_UP); // to hold the minimum amount in all the wards.
    BigDecimal wardDataMaxAmount = Collections.max(wardWiseData.values()).setScale(0, BigDecimal.ROUND_HALF_UP); // to hold the maximum amount in all the wards.
    if ((wardDataMaxAmount.subtract(wardDataMinAmount)).compareTo(BigDecimal.valueOf(totalNoOfColors)) == -1) {
        throw new ValidationException(Arrays.asList(new ValidationError("colorrange",
                "no of colors supplied is more than the range of data " + "in the wards")));
    }

    BigDecimal rangeSize = getRangeSize(wardDataMinAmount, wardDataMaxAmount, totalNoOfColors);

    GeoKmlInfo geoKmlInfo = new GeoKmlInfo();
    Map<String, String> wardWiseKmlColorStyle = new HashMap<String, String>();

    for (Map.Entry<String, BigDecimal> entry : wardWiseData.entrySet()) {
        wardWiseKmlColorStyle.put("style" + entry.getKey(),
                getStyleColorName(entry.getValue(), wardDataMinAmount, totalNoOfColors, rangeSize));
    }

    geoKmlInfo.setWardWiseColor(wardWiseKmlColorStyle);
    geoKmlInfo.setColorCodes(convertToKmlColor(colorCodes));

    request.setAttribute(GeoLocationConstants.KML_DATA_MODEL_JBOSS_CACHE_KEY_NAME,
            putKmlDataToCache(geoKmlInfo));
    request.setAttribute(GeoLocationConstants.COLOR_CODE_AND_RANGE_MAP_NAME,
            getColorRange(wardDataMinAmount, wardDataMaxAmount, rangeSize, colorCodes));
    if (null != kmlPath && StringUtils.isNotEmpty(kmlPath)) {
        request.setAttribute(GeoLocationConstants.KML_URL_PATH_REQ_ATTR_NAME, kmlPath);
    }

    LOGGER.debug("GeoLocationService | setKmlDataToCacheAndRequest | End");

}

From source file:de.unidue.langtech.teaching.rp.detector.LanguageDetectorWeb1T.java

@SuppressWarnings("unused")
/* Show certainty for each language in numeric probabilities
 * Mathematics mainly based on http://stats.stackexchange.com/a/66621
 * Can slightly increase detection time 
 *//*  ww w. j a  v  a2  s .  com*/
private Map<String, Double> getCertainty(Map<String, Double> map) {

    double maxProb = Collections.max(map.values());

    Map<String, Double> newMap = new HashMap<String, Double>();
    double sum = 0.0;

    Map<String, Double> languageProbabilities = new HashMap<String, Double>();

    for (Entry<String, Double> entry : map.entrySet()) {
        newMap.put(entry.getKey(), Math.exp(entry.getValue() - maxProb));
        sum += Math.exp(entry.getValue() - maxProb);
    }

    for (Entry<String, Double> entry : newMap.entrySet()) {
        double certainty = entry.getValue() / sum;

        if (certainty > 0.1) {
            languageProbabilities.put(entry.getKey(), certainty);
        }

    }

    return languageProbabilities;

}

From source file:org.dawnsci.boofcv.internal.BoofCVImageTransformImpl.java

@Override
public IDataset affineTransform(IDataset data, double a11, double a12, double a21, double a22, double dx,
        double dy, boolean keepShape) throws Exception {
    if (data.getShape().length != 2)
        throw new Exception("Data shape is not 2D");
    ImageFloat32 image = ConvertIDataset.convertFrom(data, ImageFloat32.class, 1);

    // IDataset uses row major ordering, but ImageFloat32 uses column major
    // this is why the the affine transform parameters will be exchanged in what follows next...

    int width = 0, height = 0;
    if (keepShape) {
        width = image.width;/*from ww w  .  j a  va 2s.  c o  m*/
        height = image.height;
    } else {
        // calculate resulting bounding box
        Pair<Double, Double> coords00 = affineTransformation(0, 0, a22, a21, a12, a11, dy, dx);
        Pair<Double, Double> coords10 = affineTransformation(0, image.height, a22, a21, a12, a11, dy, dx);
        Pair<Double, Double> coords01 = affineTransformation(image.width, 0, a22, a21, a12, a11, dy, dx);
        Pair<Double, Double> coords11 = affineTransformation(image.width, image.height, a22, a21, a12, a11, dy,
                dx);

        List<Double> coordsx = Arrays.asList(coords00.getFirst(), coords10.getFirst(), coords01.getFirst(),
                coords11.getFirst());
        List<Double> coordsy = Arrays.asList(coords00.getSecond(), coords10.getSecond(), coords01.getSecond(),
                coords11.getSecond());

        double maxx = Collections.max(coordsx);
        double maxy = Collections.max(coordsy);

        height = (int) (maxy);
        width = (int) (maxx);
    }

    ImageFloat32 transformed = new ImageFloat32(width, height);

    DistortImageOps.affine(image, transformed, TypeInterpolate.BILINEAR, a22, a21, a12, a11, dy, dx);
    return ConvertIDataset.convertTo(transformed, true);
}

From source file:com.acmeair.reporter.parser.ResultParser.java

public double[] processData(ArrayList<Double> inputList, boolean isTotalThroughput) {
    if (inputList != null && inputList.size() > 0) {
        if (this instanceof NmonParser) {
            overallResults.setScale_max(90.0);
        } else {/*from  www .j a va  2 s  .  com*/
            overallResults.setScale_max(Collections.max(inputList));
        }
        if (overallResults.getOverallScale_max() < overallResults.getScale_max() && !isTotalThroughput) {
            overallResults.setOverallScale_max(overallResults.getScale_max());
        }
        double scale_factor = 90 / overallResults.getScale_max();
        return ResultParserHelper.scaleInputsData(inputList, scale_factor);
    }
    return null;
}

From source file:au.org.ala.delta.io.BinaryKeyFile.java

public int nextAvailableRecord() {
    int max = 0;/*from   w  w  w . j a  va2s .c om*/
    if (_occupiedRecords.size() > 0) {
        max = Collections.max(_occupiedRecords);
    }
    seekToRecord(max + 1);
    return max + 1;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected void resetRenderer(final IScope scope, final String serieid) {
    final XYBlockRenderer newr = (XYBlockRenderer) this.getOrCreateRenderer(scope, serieid);

    // newr.setSeriesStroke(0, new BasicStroke(0));
    final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);

    if (myserie.getMycolor() != null) {
        newr.setSeriesPaint(0, myserie.getMycolor());
    }//from w  ww .  j  ava2  s.  c  om
    if (myserie.getSValues(scope).size() > 0) {
        final double maxval = Collections.max(myserie.getSValues(scope));
        final double minval = Collections.min(myserie.getSValues(scope));
        Color cdeb = new Color(0, 0, 0, 0);
        if (myserie.getMyMincolor() != null)
            cdeb = myserie.getMyMincolor();
        Color cend = new Color(0.9f, 0.9f, 0.9f, 1.0f);
        if (myserie.getMycolor() != null)
            cend = myserie.getMycolor();

        LookupPaintScale paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, cend);
        if (myserie.getMyMedcolor() != null)
            paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, myserie.getMyMedcolor(), cend);

        newr.setPaintScale(paintscale);

        final NumberAxis scaleAxis = new NumberAxis(myserie.getName());
        scaleAxis.setAxisLinePaint(this.axesColor);
        scaleAxis.setTickMarkPaint(this.axesColor);
        scaleAxis.setTickLabelFont(this.getTickFont());
        scaleAxis.setRange(minval, maxval);
        scaleAxis.setAxisLinePaint(axesColor);
        scaleAxis.setLabelFont(getLabelFont());
        if (textColor != null) {
            scaleAxis.setLabelPaint(textColor);
            scaleAxis.setTickLabelPaint(textColor);
        }
        if (!this.getXTickValueVisible(scope)) {
            scaleAxis.setTickMarksVisible(false);
            scaleAxis.setTickLabelsVisible(false);

        }

        final PaintScaleLegend legend = new PaintScaleLegend(paintscale, scaleAxis);
        legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        legend.setAxisOffset(5.0);
        // legend.setMargin(new RectangleInsets(5, 5, 5, 5));
        // legend.setFrame(new BlockBorder(Color.red));
        // legend.setPadding(new RectangleInsets(10, 10, 10, 10));
        // legend.setStripWidth(10);
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setBackgroundPaint(this.backgroundColor);
        // ArrayList<PaintScaleLegend> caxe=new
        // ArrayList<PaintScaleLegend>();
        // caxe.add(legend);
        // chart.setSubtitles(caxe);
        if (!this.series_label_position.equals("none"))
            chart.addSubtitle(legend);

    }
}

From source file:com.sam_chordas.android.stockhawk.ui.ChartFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    listBidPrice = new ArrayList<>();
    listDate = new ArrayList<>();
    // Set the cursor in our CursorAdapter once the Cursor is loaded

    if (cursor != null && cursor.moveToFirst()) {

        Log.e("CURSOR SIZE=========>", String.valueOf(cursor.getCount()));

        int columnHistoryId = cursor.getColumnIndex(HistoryColumns._ID);
        int columnBidPriceIndex = cursor.getColumnIndex(HistoryColumns.BID_PRICE);
        int columnDateIndex = cursor.getColumnIndex(HistoryColumns.BID_DATE);

        String id = cursor.getString(columnHistoryId);

        String price = cursor.getString(columnBidPriceIndex);
        //put price to bid list
        listBidPrice.add(price);// w ww .j a  va2 s  .  c om

        String bidDate = cursor.getString(columnDateIndex);
        //put price to bid list
        listDate.add(bidDate);

        while (cursor.moveToNext()) {
            id = cursor.getString(columnHistoryId);

            price = cursor.getString(columnBidPriceIndex);
            //put price to bid list
            listBidPrice.add(price);

            bidDate = cursor.getString(columnDateIndex);
            //put price to bid list
            listDate.add(bidDate);
        }

        //set data to chart
        LineData data = new LineData(getXAxisValues(), getDataSet());
        chart.setData(data);

        // let the chart know it's data has changed
        data.notifyDataChanged();
        chart.notifyDataSetChanged();

        //scale Y-axis
        YAxis leftAxis = chart.getAxisLeft();
        YAxis rightAxis = chart.getAxisRight();

        //don't start at 0
        leftAxis.setStartAtZero(false);
        rightAxis.setStartAtZero(false);

        //get min and max values from arraylist
        String minVal = Collections.min(listBidPrice);
        String maxVal = Collections.max(listBidPrice);

        Log.i("MINIMUM VALUE_------>", minVal);
        Log.i("MAXIMUM VALUE_------>", maxVal);

        Float minFloat = Float.valueOf(minVal);
        Float maxFloat = Float.valueOf(maxVal);

        Log.e("MINIMUM FLOAT------>", minFloat.toString());
        Log.e("MAXIMUM FLOAT------>", maxFloat.toString());

        //set min and max values for better scaling
        leftAxis.setAxisMaxValue(maxFloat);
        leftAxis.setAxisMinValue(minFloat);
        rightAxis.setAxisMaxValue(maxFloat);
        rightAxis.setAxisMinValue(minFloat);

        // format values into two decimal points only
        data.setValueFormatter(new MyValueFormatter());

        //refresh chart
        chart.invalidate();
    }

    for (String price : listBidPrice) {
        System.out.println("PRICE ===========>" + price);
    }
    for (String bidDate : listDate) {
        System.out.println("BID DATE ===========>" + bidDate);
    }

}

From source file:org.libreplan.business.planner.chart.ContiguousDaysLine.java

@SuppressWarnings("unchecked")
private static LocalDate max(LocalDate... dates) {
    return Collections.max(Arrays.asList(dates));
}

From source file:be.ugent.maf.cellmissy.analysis.singlecell.preprocessing.impl.SingleCellConditionPreProcessorImpl.java

@Override
public void generateShiftedCoordinatesRanges(SingleCellConditionDataHolder singleCellConditionDataHolder) {
    singleCellConditionDataHolder.getSingleCellWellDataHolders().stream()
            .forEach((singleCellWellDataHolder) -> {
                singleCellWellPreProcessor.generateShiftedCoordinatesRanges(singleCellWellDataHolder);
            });//  w  ww.  j ava 2s  . co  m
    Double[][] transposedMatrix = AnalysisUtils
            .transpose2DArray(singleCellConditionDataHolder.getShiftedTrackCoordinatesMatrix());
    // compute the min and the max coordinates
    Double xMin = Collections.min(Arrays.asList(transposedMatrix[0]));
    Double xMax = Collections.max(Arrays.asList(transposedMatrix[0]));
    Double yMin = Collections.min(Arrays.asList(transposedMatrix[1]));
    Double yMax = Collections.max(Arrays.asList(transposedMatrix[1]));
    Double[][] shiftedCoordinatesRanges = new Double[2][2];
    shiftedCoordinatesRanges[0] = new Double[] { xMin, xMax };
    shiftedCoordinatesRanges[1] = new Double[] { yMin, yMax };
    singleCellConditionDataHolder.setShiftedCoordinatesRanges(shiftedCoordinatesRanges);
}

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

/**
 * Update this state to reflect the given set of mapper call counts.
 *//*from   w w w.  j a  va2s . c o m*/
public void setProcessedCounts(List<Long> processedCounts) {
    if (processedCounts == null || processedCounts.isEmpty()) {
        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()));
}