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:fr.ericlab.mabed.structure.Corpus.java

public void prepareCorpus() {
    System.out.println(Util.getDate() + " Preparing corpus...");
    String[] fileArray = new File("input/").list();
    nbTimeSlices = 0;/*from w  ww . j  a  v  a 2 s.c  o m*/
    NumberFormat formatter = new DecimalFormat("00000000");
    ArrayList<Integer> list = new ArrayList<>();
    for (String filename : fileArray) {
        if (filename.endsWith(".text")) {
            try {
                list.add(formatter.parse(filename.substring(0, 8)).intValue());
            } catch (ParseException ex) {
                Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
            }
            nbTimeSlices++;
        }
    }
    int a = Collections.min(list), b = Collections.max(list);
    LineIterator it = null;
    try {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
        it = FileUtils.lineIterator(new File("input/" + formatter.format(a) + ".time"), "UTF-8");
        if (it.hasNext()) {
            Date parsedDate = dateFormat.parse(it.nextLine());
            startTimestamp = new java.sql.Timestamp(parsedDate.getTime());
        }
        it = FileUtils.lineIterator(new File("input/" + formatter.format(b) + ".time"), "UTF-8");
        String lastLine = "";
        while (it.hasNext()) {
            lastLine = it.nextLine();
        }
        Date parsedDate = dateFormat.parse(lastLine);
        endTimestamp = new java.sql.Timestamp(parsedDate.getTime());
    } catch (IOException | ParseException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        LineIterator.closeQuietly(it);
    }
    System.out.print("   - Computing word frequencies");
    GlobalIndexer indexer = new GlobalIndexer(configuration.numberOfThreads, false);
    try {
        indexer.index("input/", configuration.stopwords);
    } catch (InterruptedException | IOException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    }
    indexer = new GlobalIndexer(configuration.numberOfThreads, true);
    try {
        indexer.index("input/", configuration.stopwords);
    } catch (InterruptedException | IOException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(", 100% done.");
}

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

@Override
public void computeCoordinatesRanges(Track track) {
    Double[][] coordinates = track.getCoordinates();
    Double[][] transpCoord = ComputationUtils.transpose2DArray(coordinates);
    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[][] coordinatesRanges = new Double[][] { { xMin, xMax }, { yMin, yMax } };
    track.setCoordinateRanges(coordinatesRanges);
    track.setxNetDisplacement(xMax - xMin);
    track.setyNetDisplacement(yMax - yMin);
}

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

/**
 * @see org.kuali.kra.committee.service.CommitteeService#getCommitteeById(java.lang.String)
 */// ww  w. ja v a2s . c  om
@SuppressWarnings("unchecked")
public Committee getCommitteeById(String committeeId) {
    Committee committee = null;
    if (!StringUtils.isBlank(committeeId)) {
        Map<String, Object> fieldValues = new HashMap<String, Object>();
        fieldValues.put(COMMITTEE_ID, committeeId);
        Collection<Committee> committees = businessObjectService.findMatching(Committee.class, 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 = (Committee) Collections.max(committees);
        }
    }
    return committee;
}

From source file:org.dkpro.similarity.algorithms.lsr.gloss.GlossOverlapComparator.java

@Override
public double getSimilarity(Set<Entity> entities1, Set<Entity> entities2)
        throws LexicalSemanticResourceException, SimilarityException {
    if (entities1.size() == 0 || entities2.size() == 0) {
        if (entities1.size() == 0) {
            logger.debug("First entity set is empty.");
        } else {//  ww  w . j a va 2  s  .c  o  m
            logger.debug("Second entity set is empty.");
        }

        return GlossBasedComparator.NOT_FOUND;
    }

    List<Double> relatednessValues = new ArrayList<Double>();
    for (Entity e1 : entities1) {
        for (Entity e2 : entities2) {
            relatednessValues.add(getSimilarity(e1, e2));
        }
    }

    return Collections.max(relatednessValues);

}

From source file:org.nuxeo.ecm.platform.ui.web.auth.LoginScreenHelper.java

/**
 * Returns the {@link LoginStartupPage} contribution with the highest priority or {@code null} if none is
 * contributed./* w  w  w .jav  a2s .c  o  m*/
 *
 * @since 8.4
 */
protected static LoginStartupPage getDefaultStartupPage(LoginScreenConfig config) {
    if (config.getStartupPages().isEmpty()) {
        return null;
    }
    return Collections.max(config.getStartupPages().values());
}

From source file:br.upe.ecomp.doss.problem.movingpeaks.MovingPeaks.java

/**
 * {@inheritDoc}/*  ww  w.  ja v  a  2  s  . c o  m*/
 */
public double getFitness(double... position) {
    List<Double> fitness = new ArrayList<Double>();
    for (Peak peak : peaks) {
        fitness.add(peak.getFitness(position));
    }
    return Collections.max(fitness);
}

From source file:org.mabb.fontverter.opentype.HorizontalHeadTable.java

void normalize() throws IOException {
    if (font.getHmtx().isFromParsedFont)
        return;/*from   w w w.  ja  v a  2s  .  c o m*/

    font.getHmtx().normalize();
    int[] widths = font.getHmtx().getAdvanceWidths();
    this.numberOfHMetrics = widths.length;

    List<Integer> widthsList = Arrays.asList(ArrayUtils.toObject(widths));
    if (widthsList.size() > 0)
        advanceWidthMax = Collections.max(widthsList);

}

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

/**
 * Get the maximum Y data point to show in the chart.
 *///from  ww w.  ja v a 2s . c  o m
public long getMaxYDataPointForChart() {

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

From source file:com.compomics.cell_coord.gui.controller.summary.VisualizeTracksController.java

/**
 * Compute both the raw and the shifted-to-zero coordinates ranges.
 *//*  ww  w  . j  a  v  a2s . c  o m*/
public void computeRanges() {
    coordRanges = new Double[2][2];
    shiftedCoordRange = new Double[2][2];

    List<Double> xRawMinList = new ArrayList<>();
    List<Double> xRawMaxList = new ArrayList<>();
    List<Double> yRawMinList = new ArrayList<>();
    List<Double> yRawMaxList = new ArrayList<>();

    List<Double> xShiftMinList = new ArrayList<>();
    List<Double> xShiftMaxList = new ArrayList<>();
    List<Double> yShiftMinList = new ArrayList<>();
    List<Double> yShiftMaxList = new ArrayList<>();
    List<Sample> samples = loadTracksController.getSamples();
    for (Sample sample : samples) {
        List<Track> tracks = sample.getTracks();
        for (Track track : tracks) {
            Double[][] coordinateRanges = track.getCoordinateRanges();
            Double[][] shiftedCoordinateRanges = track.getShiftedCoordinateRanges();

            xRawMinList.add(coordinateRanges[0][0]);
            xRawMaxList.add(coordinateRanges[0][1]);
            yRawMinList.add(coordinateRanges[1][0]);
            yRawMaxList.add(coordinateRanges[1][1]);

            xShiftMinList.add(shiftedCoordinateRanges[0][0]);
            xShiftMaxList.add(shiftedCoordinateRanges[0][1]);
            yShiftMinList.add(shiftedCoordinateRanges[1][0]);
            yShiftMaxList.add(shiftedCoordinateRanges[1][1]);
        }
    }
    Double xRawMin = Collections.min(xRawMinList);
    Double xRawMax = Collections.max(xRawMaxList);
    Double yRawMin = Collections.min(yRawMinList);
    Double yRawMax = Collections.max(yRawMaxList);
    coordRanges[0] = new Double[] { xRawMin, xRawMax };
    coordRanges[1] = new Double[] { yRawMin, yRawMax };
    Double xShiftMin = Collections.min(xShiftMinList);
    Double xShiftMax = Collections.max(xShiftMaxList);
    Double yShiftMin = Collections.min(yShiftMinList);
    Double yShiftMax = Collections.max(yShiftMaxList);
    shiftedCoordRange[0] = new Double[] { xShiftMin, xShiftMax };
    shiftedCoordRange[1] = new Double[] { yShiftMin, yShiftMax };
}

From source file:uk.ac.imperial.presage2.db.json.JsonStorage.java

@Override
public void start() throws Exception {
    // check base path
    if (this.baseStoragePath.length() > 0) {
        File basePath = new File(this.baseStoragePath);
        if (!basePath.exists()) {
            basePath.mkdirs();//  ww  w .  ja v a  2 s  . c o m
        }
        if (!basePath.isDirectory()) {
            throw new RuntimeException("Base path is not a directory.");
        }
    }
    // open simulations file if exists, create otherwise
    File simulationsFile = new File(baseStoragePath + simulationsFileName);

    if (!simulationsFile.exists()) {
        simulationsFile.createNewFile();
        root = mapper.createArrayNode();
        mapper.writeValue(simulationsFile, root);
    }

    // read simulations content in to JsonNode
    simulations = new HashMap<Long, ObjectNode>();
    try {
        root = mapper.readValue(simulationsFile, ArrayNode.class);

        for (JsonNode s : root) {
            simulations.put(s.get("id").asLong(), (ObjectNode) s);
        }
    } catch (JsonMappingException e) {
        logger.warn("Couldn't parse simulations file: " + baseStoragePath + simulationsFileName, e);
    }
    // find max simID for new insertions
    try {
        maxSimId = Collections.max(simulations.keySet());
    } catch (NoSuchElementException e) {
        // empty set
        maxSimId = 0;
    }

    started = true;
}