List of usage examples for java.util Collections max
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
From source file:com.google.ie.web.controller.TagController.java
/** * Return a map containing the maximum and minimum weights of the tags in * the tag cloud data received as list//from w w w . ja va 2 s .co m * * @param tags the list of tags to be searched for max and min weights * @return a map containing the maximum and minimum weights */ private Map<String, Long> getTheMaxAndMinWeights(List<Tag> tags) { long min = Collections.min(tags).getWeightage(); long max = Collections.max(tags).getWeightage(); Map<String, Long> mapOfMinMax = new HashMap<String, Long>(); mapOfMinMax.put(WebConstants.MAX_WEIGHT, max); mapOfMinMax.put(WebConstants.MIN_WEIGHT, min); return mapOfMinMax; }
From source file:decision_tree_learning.Matrix.java
public void postmodifyMetadata() { Iterator<TreeMap<Integer, String>> s_m_enum_to_str = this.m_enum_to_str.iterator(); for (int i = 0; i < this.m_str_to_enum.size() - 1; i++) { // we don't wanna touch last attribute's metadata TreeMap<String, Integer> s_m_str_to_enum = this.m_str_to_enum.get(i); int max = Collections.max(s_m_str_to_enum.values()); s_m_str_to_enum.put("MISSING", max + 1); s_m_enum_to_str.next().put(max + 1, "MISSING"); }/*from www.j a v a 2 s . c o m*/ }
From source file:de.tudarmstadt.ukp.dkpro.core.mallet.lda.MalletLdaTopicModelInferencer.java
/** * Assign topics according to the following formula: * <p>/*from w ww. j a v a 2s .c om*/ * Topic proportion must be at least the maximum topic's proportion divided by the maximum * number of topics to be assigned. In addition, the topic proportion must not lie under the * minTopicProb. If more topics comply with these criteria, only retain the n * (maxTopicAssignments) largest values. * * @param topicDistribution a double array containing the document's topic proportions * @return an array of integers pointing to the topics assigned to the document * @deprecated this method should be removed at some point because assignment / topic tagging * should be done in a dedicated step (module). */ // TODO: should return a boolean[] of the same size as topicDistribution // TODO: should probably be moved to a dedicated module because assignments (topic tagging) // should not be done at inference level @Deprecated private int[] assignTopics(final double[] topicDistribution) { /* * threshold is the largest value divided by the maximum number of topics or the fixed * number set as minTopicProb parameter. */ double threshold = Math .max(Collections.max(Arrays.asList(ArrayUtils.toObject(topicDistribution))).doubleValue() / maxTopicAssignments, minTopicProb); /* * assign indexes for values that are above threshold */ List<Integer> indexes = new ArrayList<>(topicDistribution.length); for (int i = 0; i < topicDistribution.length; i++) { if (topicDistribution[i] >= threshold) { indexes.add(i); } } /* * Reduce assignments to maximum number of allowed assignments. */ if (indexes.size() > maxTopicAssignments) { /* sort index list by corresponding values */ Collections.sort(indexes, (aO1, aO2) -> Double.compare(topicDistribution[aO1], topicDistribution[aO2])); while (indexes.size() > maxTopicAssignments) { indexes.remove(0); } } return ArrayUtils.toPrimitive(indexes.toArray(new Integer[indexes.size()])); }
From source file:com.lines.activitys.OptionsActivity.java
/** * Here we get the list of characters in the database * //from w w w. j av a2s .c om */ private void populateCharacters() { mCursor = mDbAdapter.fetchAllLines(); // First get the data from "character" column and filter out unwanted // characters (e.g. STAGE) if (mCursor.moveToFirst()) { do { String character = mCursor.getString(mCursor.getColumnIndex("character")); if (!(character.equals("STAGE") || character.contains("and"))) { characters.add(character); } } while (mCursor.moveToNext()); } HashMap<String, Integer> charOccur = new HashMap<String, Integer>(); // Get the number of lines spoken by each character and store in HashMap Set<String> unique = new HashSet<String>(characters); for (String key : unique) { charOccur.put(key, Collections.frequency(characters, key)); } characters.clear(); // Sort character list based on the number of lines they have while (charOccur.size() > 0) { int max = Collections.max(charOccur.values()); characters.add(getKeyByValue(charOccur, max)); charOccur.remove(getKeyByValue(charOccur, max)); } // Set contents of Character Spinner mAdapterChar = new ArrayAdapter<String>(OptionsActivity.this, android.R.layout.simple_spinner_item, characters); mAdapterChar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mChar.setAdapter(mAdapterChar); mCursor.close(); }
From source file:gr.iit.demokritos.cru.cps.ai.ComputationalCreativityMetrics.java
public ArrayList<Double> Rar_Eff(ArrayList<Double> SomethingOfClust) { double max = Collections.max(SomethingOfClust); ArrayList<Double> score = new ArrayList<Double>(); //the formula is 2*#Clusters/max(#Clusters) for (int i = 0; i < SomethingOfClust.size(); i++) { if (max == 0) { score.add(0.0);//from www .j a v a 2 s .c o m } else { score.add(2.0 * SomethingOfClust.get(i) / max); } } return score; }
From source file:hudson.model.Job.java
@Override public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { super.onLoad(parent, name); File buildDir = getBuildDir(); runIdMigrator = new RunIdMigrator(); runIdMigrator.migrate(buildDir, Jenkins.getInstance().getRootDir()); TextFile f = getNextBuildNumberFile(); if (f.exists()) { // starting 1.28, we store nextBuildNumber in a separate file. // but old Hudson didn't do it, so if the file doesn't exist, // assume that nextBuildNumber was read from config.xml try {/*from ww w . java 2 s . c o m*/ synchronized (this) { this.nextBuildNumber = Integer.parseInt(f.readTrim()); } } catch (NumberFormatException e) { // try to infer the value of the next build number from the existing build records. See JENKINS-11563 File[] folders = buildDir.listFiles(new FileFilter() { public boolean accept(File file) { return file.isDirectory() && file.getName().matches("[0-9]+"); } }); if (folders == null || folders.length == 0) { this.nextBuildNumber = 1; } else { Collection<Integer> foldersInt = Collections2.transform(Arrays.asList(folders), new Function<File, Integer>() { public Integer apply(File file) { return Integer.parseInt(file.getName()); } }); this.nextBuildNumber = Collections.max(foldersInt) + 1; } saveNextBuildNumber(); } } else { // From the old Hudson, or doCreateItem. Create this file now. saveNextBuildNumber(); } if (properties == null) // didn't exist < 1.72 properties = new CopyOnWriteList<JobProperty<? super JobT>>(); for (JobProperty p : properties) p.setOwner(this); }
From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixHBaseAccessor.java
private static Map<Long, Double> readLastMetricValueFromJSON(String json) throws IOException { Map<Long, Double> values = readMetricFromJSON(json); Long lastTimeStamp = Collections.max(values.keySet()); HashMap<Long, Double> valueMap = new HashMap<Long, Double>(1); valueMap.put(lastTimeStamp, values.get(lastTimeStamp)); return valueMap; }
From source file:org.openmrs.Concept.java
/** * Add the given ConceptAnswer to the list of answers for this Concept * /*ww w . j a va 2 s .c om*/ * @param conceptAnswer * @should add the ConceptAnswer to Concept * @should not fail if answers list is null * @should not fail if answers contains ConceptAnswer already * @should set the sort weight to the max plus one if not provided */ public void addAnswer(ConceptAnswer conceptAnswer) { if (conceptAnswer != null) { if (!getAnswers().contains(conceptAnswer)) { conceptAnswer.setConcept(this); getAnswers().add(conceptAnswer); } if ((conceptAnswer.getSortWeight() == null) || (conceptAnswer.getSortWeight() <= 0)) { //find largest sort weight ConceptAnswer a = Collections.max(answers); Double sortWeight = (a == null) ? 1d : ((a.getSortWeight() == null) ? 1d : a.getSortWeight() + 1d);//a.sortWeight can be NULL conceptAnswer.setSortWeight(sortWeight); } } }
From source file:Simulator.PerformanceCalculation.java
JPanel minmaxwaitTime1(boolean minCheck) { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime1()); wait1.put(traceObject.getSurgeonId(), details); } else {/* w ww . j ava2s . c o m*/ wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1()); } no.add(traceObject.getSurgeonId()); } XYSeriesCollection dataset = new XYSeriesCollection(); LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double value = 0; if (minCheck) { value = Collections.min(arrayList); value = value / 600; } else { value = Collections.max(arrayList); value = value / 600; } average.put(integer, value); } XYSeries series = new XYSeries("Surgeon Minimum Wait Time 1"); for (int i = 1; i <= average.size(); i++) { series.add(i, average.get(i)); } dataset.addSeries(series); String name; if (minCheck) { name = "Minimum"; } else { name = "Maximum"; } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 1 For Patients", // Title "Surgeon ID", // x-axis Label "Time (Days)", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot xyPlot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(); renderer.setBaseShapesVisible(true); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true); return new ChartPanel(chart); }
From source file:org.squashtest.tm.domain.library.structures.LibraryTree.java
/** * * <p>Accepts a {@link Closure} that will be applied on the nodes using bottom-up exploration. The method will walk up the tree : * <ul>//from ww w. ja v a2s .c o m * <li>layer <i>n+1</i> will be treated before layer <i>n</i> (reverse order)</li> * <li>nodes within a given layer will be treated regardless their ordering</li> * </ul> * </p> * @param closure code to apply on the nodes. */ public void doBottomUp(Closure closure) { if (!layers.isEmpty()) { Integer layerIndex = Collections.max(layers.keySet()); while (layerIndex >= 0) { List<T> layer = new ArrayList<>(layers.get(layerIndex)); CollectionUtils.forAllDo(layer, closure); layerIndex--; } } }