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:gr.iti.mklab.reveal.forensics.util.Util.java

public static float maxDouble2DArray(float[][] arrayIn) {
    // Calculate the maximum value of a 2D float array
    float max = -Float.MAX_VALUE;
    float colMax;
    for (float[] arrayInRow : arrayIn) {
        List b = Arrays.asList(ArrayUtils.toObject(arrayInRow));
        colMax = (float) Collections.max(b);
        if (colMax > max) {
            max = colMax;//from  w  w  w  .  j a va2  s  . c  o m
        }
    }
    return max;
}

From source file:eu.ggnet.dwoss.redtape.entity.Document.java

/**
 * Removes the position at the id.//from  ww  w . j a v a 2 s.c  o m
 * <p/>
 * @param id the id of the position to be removed.
 * @return the removed position.
 */
public Position removeAt(final int id) {
    if (!positions.containsKey(id))
        return null;
    Position position = positions.remove(id);
    position.document = null;
    position.id = 0;
    // If we have positions which are at the upper end, we want to change there ids.
    if (positions.containsKey(id + 1)) {
        for (int i = (id + 1); i <= Collections.max(positions.keySet()); i++) {
            Position shift = positions.remove(i);
            shift.id = i - 1;
            positions.put(i - 1, shift);
        }
    }
    return position;
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double maxDouble2DArray(double[][] arrayIn) {
    // Calculate the maximum value of a 2D float array
    double max = -Double.MAX_VALUE;
    double colMax;
    for (double[] arrayInRow : arrayIn) {
        List b = Arrays.asList(ArrayUtils.toObject(arrayInRow));
        colMax = (double) Collections.max(b);
        if (colMax > max) {
            max = colMax;//from   w ww. j  ava  2s  .  com
        }
    }
    return max;
}

From source file:com.microsoft.projectoxford.emotionsample.RecognizeActivity.java

private List<RecognizeResult> processWithAutoFaceDetection()
        throws EmotionServiceException, IOException, JSONException {
    Log.d("emotion", "Start emotion detection with auto-face detection");

    Gson gson = new Gson();

    // Put the image into an input stream for detection.
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());

    long startTime = System.currentTimeMillis();

    List<RecognizeResult> result = null;
    ////from  w w  w  .  j a v  a 2 s  .c om
    // Detect emotion by auto-detecting faces in the image.
    //
    result = this.client.recognizeImage(inputStream);

    String json = gson.toJson(result);
    Log.e("result", json);
    try {

        JSONArray jArray = new JSONArray(json);
        JSONObject jObj = jArray.getJSONObject(0);
        JSONObject scores = jObj.getJSONObject("scores");

        HashMap<String, Double> emotionScores = new HashMap<>();
        emotionScores.put("Anger", scores.getDouble("anger"));
        emotionScores.put("Contempt", scores.getDouble("contempt"));
        emotionScores.put("Disgust", scores.getDouble("disgust"));
        emotionScores.put("Fear", scores.getDouble("fear"));
        emotionScores.put("Happiness", scores.getDouble("happiness"));
        emotionScores.put("Neutral", scores.getDouble("neutral"));
        emotionScores.put("Sadness", scores.getDouble("sadness"));
        emotionScores.put("Surprise", scores.getDouble("surprise"));
        double maxScore = Collections.max(emotionScores.values());
        for (Map.Entry<String, Double> entry : emotionScores.entrySet()) {
            if (entry.getValue() == maxScore) {
                Log.e("Max emotion score ", entry.getKey());
                //String testS = entry.getKey();
                mEmotion = entry.getKey();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    Log.e("emotion",
            String.format("Detection done. Elapsed time: %d ms", (System.currentTimeMillis() - startTime)));
    return result;
}

From source file:com.blm.orc.ReaderImpl.java

private int getLastIdx() {
    Set<Integer> indices = Sets.newHashSet();
    for (Type type : footer.getTypesList()) {
        indices.addAll(type.getSubtypesList());
    }//from  www. j a v a 2 s.  c o  m
    return Collections.max(indices);
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

private static <E extends Element> HighlightResult<E> getResult(Collection<E> elements,
        HighlightConditionList highlightConditions) {
    List<Color> colorList = new ArrayList<>();
    ListMultimap<E, Double> alphaValues = ArrayListMultimap.create();
    Map<E, Double> thicknessValues = new LinkedHashMap<>();
    SetMultimap<E, String> labelLists = LinkedHashMultimap.create();
    Map<E, NamedShape> shapes = new LinkedHashMap<>();

    elements.forEach(e -> thicknessValues.put(e, 0.0));

    for (HighlightCondition condition : highlightConditions.getConditions()) {
        if (condition.isInvisible()) {
            continue;
        }/*from   w  w  w.j a va 2  s. co m*/

        Map<E, Double> values = condition.getValues(elements);

        if (condition.getColor() != null) {
            colorList.add(condition.getColor());

            for (E e : elements) {
                List<Double> alphas = alphaValues.get(e);

                if (!highlightConditions.isPrioritizeColors() || alphas.isEmpty()
                        || Collections.max(alphas) == 0.0) {
                    alphas.add(values.get(e));
                } else {
                    alphas.add(0.0);
                }
            }
        }

        if (condition.isUseThickness()) {
            elements.forEach(e -> thicknessValues.put(e, thicknessValues.get(e) + values.get(e)));
        }

        if (condition.getLabelProperty() != null) {
            String property = condition.getLabelProperty();

            for (E e : elements) {
                if (values.get(e) != 0.0 && e.getProperties().get(property) != null) {
                    labelLists.put(e, toString(e.getProperties().get(property)));
                }
            }
        }

        if (condition.getShape() != null) {
            for (E e : elements) {
                if (values.get(e) != 0.0 && !shapes.containsKey(e)) {
                    shapes.put(e, condition.getShape());
                }
            }
        }
    }

    Map<E, Paint> colors = new LinkedHashMap<>();
    Map<E, String> labels = new LinkedHashMap<>();

    Multimaps.asMap(alphaValues).forEach((e, alphas) -> colors.put(e, CanvasUtils
            .mixColors(e instanceof Edge ? Color.BLACK : Color.WHITE, colorList, alphas, e instanceof Edge)));
    Multimaps.asMap(labelLists).forEach((e, labelList) -> labels.put(e, Joiner.on("/").join(labelList)));

    HighlightResult<E> result = new HighlightResult<>();

    result.colors = colors;
    result.thicknessValues = thicknessValues;
    result.labels = labels;
    result.shapes = shapes;

    return result;
}

From source file:org.apache.hadoop.hdfs.server.namenode.JournalSet.java

/**
 * Return a manifest of what finalized edit logs are available. All available
 * edit logs are returned starting from the transaction id passed. If
 * 'fromTxId' falls in the middle of a log, that log is returned as well.
 * /*from   w  w  w.  j  a  va  2  s. c o  m*/
 * @param fromTxId Starting transaction id to read the logs.
 * @return RemoteEditLogManifest object.
 */
public synchronized RemoteEditLogManifest getEditLogManifest(long fromTxId) {
    // Collect RemoteEditLogs available from each FileJournalManager
    List<RemoteEditLog> allLogs = Lists.newArrayList();
    for (JournalAndStream j : journals) {
        if (j.getManager() instanceof FileJournalManager) {
            FileJournalManager fjm = (FileJournalManager) j.getManager();
            try {
                allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, false));
            } catch (Throwable t) {
                LOG.warn("Cannot list edit logs in " + fjm, t);
            }
        }
    }

    // Group logs by their starting txid
    ImmutableListMultimap<Long, RemoteEditLog> logsByStartTxId = Multimaps.index(allLogs,
            RemoteEditLog.GET_START_TXID);
    long curStartTxId = fromTxId;

    List<RemoteEditLog> logs = Lists.newArrayList();
    while (true) {
        ImmutableList<RemoteEditLog> logGroup = logsByStartTxId.get(curStartTxId);
        if (logGroup.isEmpty()) {
            // we have a gap in logs - for example because we recovered some old
            // storage directory with ancient logs. Clear out any logs we've
            // accumulated so far, and then skip to the next segment of logs
            // after the gap.
            SortedSet<Long> startTxIds = Sets.newTreeSet(logsByStartTxId.keySet());
            startTxIds = startTxIds.tailSet(curStartTxId);
            if (startTxIds.isEmpty()) {
                break;
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Found gap in logs at " + curStartTxId + ": "
                            + "not returning previous logs in manifest.");
                }
                logs.clear();
                curStartTxId = startTxIds.first();
                continue;
            }
        }

        // Find the one that extends the farthest forward
        RemoteEditLog bestLog = Collections.max(logGroup);
        logs.add(bestLog);
        // And then start looking from after that point
        curStartTxId = bestLog.getEndTxId() + 1;
    }
    RemoteEditLogManifest ret = new RemoteEditLogManifest(logs);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated manifest for logs since " + fromTxId + ":" + ret);
    }
    return ret;
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double maxDouble3DArray(float[][][] arrayIn) {
    // Calculate the maximum value of a 3D float array
    double max = -Double.MAX_VALUE;
    double colMax;
    for (float[][] twoDInRow : arrayIn) {
        for (float[] arrayInRow : twoDInRow) {
            List b = Arrays.asList(ArrayUtils.toObject(arrayInRow));
            colMax = (float) Collections.max(b);
            if (colMax > max) {
                max = colMax;/*w ww .  j a  v  a  2 s  . com*/
            }
        }
    }
    return max;
}

From source file:com.opengamma.util.test.DbTool.java

public void createTables(String catalog, String schema, final TableCreationCallback callback) {
    final Map<String, Map<Integer, Pair<File, File>>> dbScripts = getScriptDirs();
    for (String masterDB : dbScripts.keySet()) {
        int targetVersion = getTargetVersion() != null ? getTargetVersion()
                : Collections.max(dbScripts.get(masterDB).keySet());
        int migrateFromVersion = getCreateVersion() != null ? getCreateVersion() : targetVersion;
        createTables(masterDB, catalog, schema, targetVersion, migrateFromVersion, callback);
    }/*from ww  w. j av  a  2s. c  o  m*/
}

From source file:org.libreplan.business.planner.entities.TaskElement.java

public static IntraDayDate maxDate(Collection<? extends TaskElement> tasksToSave) {
    List<IntraDayDate> endDates = toEndDates(tasksToSave);

    return endDates.isEmpty() ? null : Collections.max(endDates);
}