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.easycloud.las.agent.LogPushThread.java

@Override
public void run() {
    long start = System.currentTimeMillis();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("LogPushThread: started at " + DEFAULT_TIME_FORMAT.format(start));
    }/*from  ww w.j ava2  s.c om*/

    Configuration logPushCfg = new Configuration(LOG_PUSH_PROPS);
    String lastPushed = logPushCfg.get(LAST_PUSHED);
    Date lastPushedTime = parseDate(lastPushed, DEFAULT_TIME_FORMAT);

    String rootPath = agentConfiguration.get(LOG_ROOT_PATH);
    String postfix = agentConfiguration.get(LOG_FILE_POSTFIX);
    if (!postfix.startsWith(".")) {
        postfix = "." + postfix;
    }

    File[] logs = prepareForPushing(rootPath, postfix);

    String hostName = agentConfiguration.get(Constants.AVRO_SOURCE_HOST);
    int port = agentConfiguration.getInt(Constants.AVRO_SOURCE_PORT, DEFAULT_AVRO_PORT);

    List<Date> loggingTimes = new ArrayList<Date>();
    DateFormat df = new SimpleDateFormat(agentConfiguration.get(LOG_FILE_PATTERN));
    for (File logFile : logs) {
        String loggingTimeStr = parseLoggingTime(rootPath, postfix, logFile);
        Date loggingTime = parseDate(loggingTimeStr, df);

        if (loggingTime != null) {
            boolean hasPushed = pushLogFile(lastPushedTime, hostName, port, logFile, loggingTime);
            if (hasPushed) {
                loggingTimes.add(loggingTime);
            }
        } else {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("LogPushThread: Parsing the log file [" + logFile.getPath()
                        + "] failed, and it's skipped.");
            }
        }

    }

    if (CollectionUtils.isNotEmpty(loggingTimes)) {
        Date latestPushedTime = Collections.max(loggingTimes);
        PropertiesWriter propsWriter = new PropertiesWriter(logPushCfg);
        propsWriter.persist(LAST_PUSHED, DEFAULT_TIME_FORMAT.format(latestPushedTime));
    } else {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("LogPushThread: no files was pushed.");
        }
    }

    if (LOGGER.isInfoEnabled()) {
        long end = System.currentTimeMillis();
        LOGGER.info("LogPushThread: finished at " + DEFAULT_TIME_FORMAT.format(end) + ", elapsed: "
                + TimeUtil.elapsedTime(start, end));
    }
}

From source file:org.phenotips.data.similarity.internal.DefaultPatientSimilarityView.java

/**
 * Set the static information for the class. Must be run before creating instances of this class.
 *
 * @param termICs the information content of each term
 * @param vocabularyManager the vocabulary manager
 *//*from   ww  w .  jav a  2s  .  c om*/
public static void initializeStaticData(Map<VocabularyTerm, Double> termICs,
        VocabularyManager vocabularyManager) {
    DefaultPatientSimilarityView.termICs = termICs;
    DefaultPatientSimilarityView.vocabularyManager = vocabularyManager;
    DefaultPatientSimilarityView.maxIC = Collections.max(termICs.values());
}

From source file:org.kuali.kra.common.committee.service.impl.CommitteeServiceImplBase.java

/**
 * @see org.kuali.kra.common.committee.service.CommitteeServiceBase#getCommitteeById(java.lang.String)
 *///w ww  . j  a va2 s. c  o m
@SuppressWarnings("unchecked")
public CMT getCommitteeById(String committeeId) {
    CMT committee = null;
    if (!StringUtils.isBlank(committeeId)) {
        Map<String, Object> fieldValues = new HashMap<String, Object>();
        fieldValues.put(COMMITTEE_ID, committeeId);
        Collection<CMT> committees = businessObjectService.findMatching(getCommitteeBOClassHook(), fieldValues);
        if (committees.size() > 0) {
            /*
             * Return the most recent approved committee (i.e. the committee version with the highest 
             * sequence number that is approved/in the database).
             */
            committee = (CMT) Collections.max(committees);
        }
    }
    return committee;
}

From source file:com.marvelution.jira.plugins.hudson.charts.BuildResultsRatioChartGenerator.java

/**
 * {@inheritDoc}//from ww  w.  j  ava 2s  .  c o  m
 */
@Override
public ChartHelper generateChart() {
    final Map<Integer, Build> buildMap = new HashMap<Integer, Build>();
    final CategoryTableXYDataset dataSet = new CategoryTableXYDataset();
    for (Build build : builds) {
        buildMap.put(Integer.valueOf(build.getBuildNumber()), build);
        dataSet.add(Double.valueOf(build.getBuildNumber()), Double.valueOf(build.getDuration()),
                getI18n().getText("hudson.charts.duration"));
    }
    final JFreeChart chart = ChartFactory.createXYBarChart("", "", false,
            getI18n().getText("hudson.charts.duration"), dataSet, PlotOrientation.VERTICAL, false, false,
            false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);
    final BuildResultRenderer renderer = new BuildResultRenderer(server, buildMap);
    renderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setMargin(0.0D);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseToolTipGenerator(renderer);
    renderer.setURLGenerator(renderer);
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setAxisOffset(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    xyPlot.setRenderer(renderer);
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setLowerBound(Collections.min(buildMap.keySet()));
    domainAxis.setUpperBound(Collections.max(buildMap.keySet()));
    final TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    domainAxis.setStandardTickUnits(ticks);
    xyPlot.setDomainAxis(domainAxis);
    final DateAxis rangeAxis = new DateAxis();
    final DurationFormat durationFormat = new DurationFormat();
    rangeAxis.setDateFormatOverride(durationFormat);
    rangeAxis.setLabel(getI18n().getText("hudson.charts.duration"));
    xyPlot.setRangeAxis(rangeAxis);
    ChartUtil.setupPlot(xyPlot);
    return new ChartHelper(chart);
}

From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.SBFile.java

public float getMax(int iCol) {
    List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol)));
    float max = Collections.max(b);
    b = null;/*from  w w w  .  jav a  2  s .c  o  m*/
    return max;
}

From source file:org.kuali.coeus.common.committee.impl.service.impl.CommitteeServiceImplBase.java

@Override
public CMT getCommitteeById(String committeeId) {
    CMT committee = null;/*from  w w w .  jav  a  2s .c om*/
    if (!StringUtils.isBlank(committeeId)) {
        Map<String, Object> fieldValues = new HashMap<String, Object>();
        fieldValues.put(COMMITTEE_ID, committeeId);
        Collection<CMT> committees = businessObjectService.findMatching(getCommitteeBOClassHook(), fieldValues);
        if (committees.size() > 0) {
            /*
             * Return the most recent approved committee (i.e. the committee version with the highest 
             * sequence number that is approved/in the database).
             */
            committee = (CMT) Collections.max(committees);
        }
    }
    return committee;
}

From source file:com.compomics.cell_coord.computation.impl.TrackOperatorImpl.java

@Override
public void computeShiftedCoordinatesRanges(Track track) {
    Double[][] shiftedCoordinates = track.getShiftedCoordinates();
    Double[][] transpCoord = ComputationUtils.transpose2DArray(shiftedCoordinates);
    List<Double> xCoordAsList = Arrays.asList(transpCoord[0]);
    List<Double> yCoordAsList = Arrays.asList(transpCoord[1]);
    Double xMin = Collections.min(xCoordAsList);
    Double xMax = Collections.max(xCoordAsList);
    Double yMin = Collections.min(yCoordAsList);
    Double yMax = Collections.max(yCoordAsList);
    Double[][] shiftedCoordRanges = new Double[][] { { xMin, xMax }, { yMin, yMax } };
    track.setShiftedCoordinateRanges(shiftedCoordRanges);
}

From source file:org.auraframework.util.perfomance.PTestGoogleChart.java

/**
 * Get the maximum X data point to show in the chart.
 *//*  w  w w  . ja v a  2  s . com*/
public long getMaxXDataPointForChart() {

    if (maxXDataPointForChart == 0) {
        List<Long> dataPoints = new ArrayList<>();
        for (ChartAxisPoints dataPoint : axisPoints) {
            for (ChartPoint point : dataPoint.seriesDataPoints) {
                dataPoints.add(Long.valueOf(point.xValue));
            }
        }
        maxXDataPointForChart = Collections.max(dataPoints);
    }
    return maxXDataPointForChart;
}

From source file:org.squashtest.tm.domain.library.structures.LibraryTree.java

/**
 * Given an integer, returns the layer at the corresponding depth in the tree. That integer must be comprised within the acceptable bounds of that tree, ie 0 and {@link #getDepth()}.
 * The layer is returned as a list of nodes.
 *
 * @param depth the depth of the layer we want an access to.
 * @return the layer as a list of nodes.
 * @throws IndexOutOfBoundsException/*from  w w  w  .  j ava 2 s .c o m*/
 */
public List<T> getLayer(Integer depth) {

    if (depth < 0) {
        throw new IndexOutOfBoundsException("Below lower bound : " + depth);
    }
    if (depth > Collections.max(layers.keySet())) {
        throw new IndexOutOfBoundsException("Above upper bound : " + depth);
    }

    return layers.get(depth);

}