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:com.opengamma.util.test.DbTest.java

protected static Object[][] getParametersForSeparateMasters(int prevVersionCount) {
    String databaseType = System.getProperty("test.database.type");
    if (databaseType == null) {
        databaseType = "all";
    }//from  w  ww .jav a2 s.com
    Collection<String> databaseTypes = TestProperties.getDatabaseTypes(databaseType);
    ArrayList<Object[]> parameters = new ArrayList<Object[]>();
    for (String dbType : databaseTypes) {
        DbTool dbtool = TestProperties.getDbTool(dbType);
        dbtool.setJdbcUrl(dbtool.getTestDatabaseUrl());
        if (isScriptPublished()) {
            dbtool.addDbScriptDirectory(SCRIPT_INSTALL_DIR.getAbsolutePath());
        } else {
            dbtool.addDbScriptDirectory(DbTool.getWorkingDirectory());
        }
        for (String masterDB : dbtool.getScriptDirs().keySet()) {
            Set<Integer> versions = dbtool.getScriptDirs().get(masterDB).keySet();
            int max = Collections.max(versions);
            int min = Collections.min(versions);
            for (int v = max; v >= Math.max(max - prevVersionCount, min); v--) {
                parameters.add(new Object[] { dbType, masterDB, "" + max /*target_version*/,
                        "" + v /*migrate_from_version*/ });
            }
        }
    }
    Object[][] array = new Object[parameters.size()][];
    parameters.toArray(array);
    return array;
}

From source file:de.bund.bfr.jung.JungUtils.java

private static double getDenominator(Map<?, Double> values) {
    if (values == null || values.isEmpty()) {
        return 1.0;
    }//from  w  ww  . j a  v a2  s  . com

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

    return max != 0.0 ? max : 1.0;
}

From source file:org.kuali.kra.questionnaire.question.QuestionServiceImpl.java

/**
 * This method determines if the questionnaire is the active (most recent version) of the questionnaire.
 * @param questionnaire/*from w  ww.  ja v  a 2 s.c  o  m*/
 * @return true if this is the active questionnaire, false otherwise
 */
@SuppressWarnings("unchecked")
protected boolean isActiveQuestionnaire(Questionnaire questionnaire) {
    Map<String, Object> fieldValues = new HashMap<String, Object>();
    fieldValues.put(QUESTIONNAIRE_ID, questionnaire.getQuestionnaireId());
    Collection<Questionnaire> questionnaires = businessObjectService.findMatching(Questionnaire.class,
            fieldValues);
    if (questionnaires.size() > 0) {
        Questionnaire maxQuestionnaire = (Questionnaire) Collections.max(questionnaires);
        if (maxQuestionnaire.getQuestionnaireRefId().equals(questionnaire.getQuestionnaireRefId())) {
            return true;
        }
    }
    return false;
}

From source file:com.linkedin.drelephant.tez.heuristics.GenericMemoryHeuristic.java

public HeuristicResult apply(TezApplicationData data) {
    if (!data.getSucceeded()) {
        return null;
    }/*  www. j a v a  2  s . c  om*/
    TezTaskData[] tasks = getTasks(data);

    List<Long> totalPhysicalMemory = new LinkedList<Long>();
    List<Long> totalVirtualMemory = new LinkedList<Long>();
    List<Long> runTime = new LinkedList<Long>();

    for (TezTaskData task : tasks) {

        if (task.isSampled()) {
            totalPhysicalMemory.add(task.getCounters().get(TezCounterData.CounterName.PHYSICAL_MEMORY_BYTES));
            totalVirtualMemory.add(task.getCounters().get(TezCounterData.CounterName.VIRTUAL_MEMORY_BYTES));
            runTime.add(task.getTotalRunTimeMs());
        }

    }

    long averagePMem = Statistics.average(totalPhysicalMemory);
    long averageVMem = Statistics.average(totalVirtualMemory);
    long maxPMem;
    long minPMem;
    try {
        maxPMem = Collections.max(totalPhysicalMemory);
        minPMem = Collections.min(totalPhysicalMemory);

    } catch (Exception exception) {
        maxPMem = 0;
        minPMem = 0;
    }
    long averageRunTime = Statistics.average(runTime);

    String containerSizeStr;

    if (!Strings.isNullOrEmpty(data.getConf().getProperty(_containerMemConf))) {
        containerSizeStr = data.getConf().getProperty(_containerMemConf);
    } else {
        containerSizeStr = getContainerMemDefaultMBytes();
    }

    long containerSize = Long.valueOf(containerSizeStr) * FileUtils.ONE_MB;

    double averageMemMb = (double) ((averagePMem) / FileUtils.ONE_MB);

    double ratio = averageMemMb / ((double) (containerSize / FileUtils.ONE_MB));

    Severity severity;

    if (tasks.length == 0) {
        severity = Severity.NONE;
    } else {
        severity = getMemoryRatioSeverity(ratio);
    }

    HeuristicResult result = new HeuristicResult(_heuristicConfData.getClassName(),
            _heuristicConfData.getHeuristicName(), severity, Utils.getHeuristicScore(severity, tasks.length));

    result.addResultDetail("Number of tasks", Integer.toString(tasks.length));
    result.addResultDetail("Maximum Physical Memory (MB)",
            tasks.length == 0 ? "0" : Long.toString(maxPMem / FileUtils.ONE_MB));
    result.addResultDetail("Minimum Physical memory (MB)",
            tasks.length == 0 ? "0" : Long.toString(minPMem / FileUtils.ONE_MB));
    result.addResultDetail("Average Physical Memory (MB)",
            tasks.length == 0 ? "0" : Long.toString(averagePMem / FileUtils.ONE_MB));
    result.addResultDetail("Average Virtual Memory (MB)",
            tasks.length == 0 ? "0" : Long.toString(averageVMem / FileUtils.ONE_MB));
    result.addResultDetail("Average Task RunTime",
            tasks.length == 0 ? "0" : Statistics.readableTimespan(averageRunTime));
    result.addResultDetail("Requested Container Memory (MB)",
            (tasks.length == 0 || containerSize == 0 || containerSize == -1) ? "0"
                    : String.valueOf(containerSize / FileUtils.ONE_MB));

    return result;

}

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

public float[] getMinMax(int iCol) {
    List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol)));
    float[] minmax = new float[2];
    minmax[0] = Collections.min(b);
    minmax[1] = Collections.max(b);
    b = null;//from   w  ww  .jav  a  2  s.c  o m
    return minmax;
}

From source file:dkpro.similarity.algorithms.lsr.aggregate.MCS06AggregateComparator.java

private double getDirectionalRelatedness(Collection<String> stringList1, Collection<String> stringList2)
        throws SimilarityException {
    double weightedSum = 0.0;
    double idfSum = 0.0;

    for (String w1 : stringList1) {
        try {//from w  w  w  . j a v  a 2s  . com
            w1 = w1.toLowerCase();
        } catch (NullPointerException e) {
            // Ignore
            continue;
        }

        Set<Double> subscores = new HashSet<Double>();

        for (String w2 : stringList2) {
            try {
                w2 = w2.toLowerCase();

                Set<String> wordset = new HashSet<String>();
                wordset.add(w1);
                wordset.add(w2);

                double score;
                if (cache.containsKey(wordset)) {
                    score = cache.get(wordset);
                } else {
                    score = measure.getSimilarity(w1, w2);
                    cache.put(wordset, score);
                }

                subscores.add(score);
            } catch (NullPointerException e) {
                // Ignore
            }
        }

        // Get best score for the pair (w1, w2)
        double bestSubscore = 0.0;

        if (stringList2.size() > 0) {
            if (measure.isDistanceMeasure()) {
                bestSubscore = Collections.min(subscores);
            } else {
                bestSubscore = Collections.max(subscores);
            }

            // Handle error cases such as "not found"
            if (bestSubscore < 0.0) {
                bestSubscore = 0.0;
            }
        }

        // Weight
        double weightedScore;
        if (idfValues.containsKey(w1)) {
            weightedScore = bestSubscore * idfValues.get(w1);

            weightedSum += weightedScore;
            idfSum += idfValues.get(w1);
        } else {
            // Well, ignore this token.
            //System.out.println("Ignoring token: \"" + w1 + "\"");
        }
    }

    return weightedSum / idfSum;
}

From source file:it.unifi.rcl.chess.traceanalysis.Trace.java

public double getMax() {
    return Collections.max(data);
}

From source file:org.kuali.coeus.common.questionnaire.impl.question.QuestionServiceImpl.java

/**
 * This method determines if the questionnaire is the active (most recent version) of the questionnaire.
 * @param questionnaire//from w ww  . jav  a2 s.c o m
 * @return true if this is the active questionnaire, false otherwise
 */
@SuppressWarnings("unchecked")
protected boolean isActiveQuestionnaire(Questionnaire questionnaire) {
    Map<String, Object> fieldValues = new HashMap<String, Object>();
    fieldValues.put(QuestionnaireConstants.QUESTIONNAIRE_SEQUENCE_ID_PARAMETER_NAME,
            questionnaire.getQuestionnaireSeqId());
    Collection<Questionnaire> questionnaires = businessObjectService.findMatching(Questionnaire.class,
            fieldValues);
    if (questionnaires.size() > 0) {
        Questionnaire maxQuestionnaire = (Questionnaire) Collections.max(questionnaires);
        if (maxQuestionnaire.getId().equals(questionnaire.getId())) {
            return true;
        }
    }
    return false;
}

From source file:net.librec.recommender.AbstractRecommender.java

/**
 * setup// w  w  w  .  j a v a2s . c  o  m
 *
 * @throws LibrecException if error occurs during setup
 */
protected void setup() throws LibrecException {
    conf = context.getConf();
    isRanking = conf.getBoolean("rec.recommender.isranking");
    if (isRanking) {
        topN = conf.getInt("rec.recommender.ranking.topn", 10);
        if (this.topN <= 0) {
            throw new IndexOutOfBoundsException("rec.recommender.ranking.topn should be more than 0!");
        }
    }
    earlyStop = conf.getBoolean("rec.recommender.earlystop", false);
    verbose = conf.getBoolean("rec.recommender.verbose", true);

    trainMatrix = (SparseMatrix) getDataModel().getTrainDataSet();
    testMatrix = (SparseMatrix) getDataModel().getTestDataSet();
    validMatrix = (SparseMatrix) getDataModel().getValidDataSet();
    userMappingData = getDataModel().getUserMappingData();
    itemMappingData = getDataModel().getItemMappingData();

    numUsers = trainMatrix.numRows();
    numItems = trainMatrix.numColumns();
    numRates = trainMatrix.size();
    ratingScale = new ArrayList<>(trainMatrix.getValueSet());
    Collections.sort(ratingScale);
    maxRate = Collections.max(trainMatrix.getValueSet());
    minRate = Collections.min(trainMatrix.getValueSet());
    globalMean = trainMatrix.mean();

    int[] numDroppedItemsArray = new int[numUsers]; // for AUCEvaluator
    int maxNumTestItemsByUser = 0; //for idcg
    for (int userIdx = 0; userIdx < numUsers; ++userIdx) {
        numDroppedItemsArray[userIdx] = numItems - trainMatrix.rowSize(userIdx);
        int numTestItemsByUser = testMatrix.rowSize(userIdx);
        maxNumTestItemsByUser = maxNumTestItemsByUser < numTestItemsByUser ? numTestItemsByUser
                : maxNumTestItemsByUser;
    }
    conf.setInts("rec.eval.auc.dropped.num", numDroppedItemsArray);
    conf.setInt("rec.eval.item.test.maxnum", maxNumTestItemsByUser);
}

From source file:uk.ac.ebi.atlas.bioentity.properties.BioEntityPropertyService.java

private List<PropertyLink> fetchRelevantGoLinks(int includeAtLeast) {
    List<PropertyLink> propertyLinks = Lists.newArrayList();

    if (!depthToGoTerms.isEmpty()) {
        for (int i = Collections.max(depthToGoTerms.keySet()); i >= 1
                && propertyLinks.size() < includeAtLeast; i--) {
            for (GoPoTerm goPoTerm : depthToGoTerms.get(i)) {
                Optional<PropertyLink> link = linkBuilder.createLink(identifier, "go", goPoTerm.accession(),
                        species);/*from   ww w. j  av a 2  s  .  com*/
                if (link.isPresent()) {
                    propertyLinks.add(link.get());
                }
            }
        }
    }

    return propertyLinks;
}