List of usage examples for java.util Collections min
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRResultsController.java
@Override protected PdfPTable createAnalysisGroupInfoTable() { //maps log transformed conc (double) to list of velocities (double) List<DoseResponsePair> data = doseResponseController.getImportedDRDataHolder().getDoseResponseData(); // new table with 5 columns PdfPTable dataTable = new PdfPTable(5); PdfUtils.setUpPdfPTable(dataTable);/*from ww w . j a v a2s. c o m*/ // add 1st row: column names PdfUtils.addCustomizedCell(dataTable, "DOSE", boldFont); PdfUtils.addCustomizedCell(dataTable, "# TECHNICAL REPLICATES", boldFont); PdfUtils.addCustomizedCell(dataTable, "LOWEST RESPONSE", boldFont); PdfUtils.addCustomizedCell(dataTable, "HIGHEST RESPONSE", boldFont); PdfUtils.addCustomizedCell(dataTable, "MEDIAN RESPONSE", boldFont); // for each condition get results and add a cell for (DoseResponsePair condition : data) { Integer replicates = condition.getResponses().size(); List<Double> velocities = condition.getResponses(); PdfUtils.addCustomizedCell(dataTable, condition.getDose().toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, replicates.toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(Collections.min(velocities)).toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(Collections.max(velocities)).toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeMedian(velocities)).toString(), bodyFont); } return dataTable; }
From source file:org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategy.java
/** * Sort objects by the following two criteria. 1) the number executors of the topology that needs to be scheduled is already on the object (node or rack) in descending order. * The reasoning to sort based on criterion 1 is so we schedule the rest of a topology on the same object (node or rack) as the existing executors of the topology. * 2) the subordinate/subservient resource availability percentage of a rack in descending order * We calculate the resource availability percentage by dividing the resource availability of the object (node or rack) by the resource availability of the entire rack or cluster depending on if object * references a node or a rack.//from w w w.j a va 2s. c o m * By doing this calculation, objects (node or rack) that have exhausted or little of one of the resources mentioned above will be ranked after racks that have more balanced resource availability. * So we will be less likely to pick a rack that have a lot of one resource but a low amount of another. * * @param allResources contains all individual ObjectResources as well as cumulative stats * @param existingScheduleFunc a function to get existing executors already scheduled on this object * @return a sorted list of ObjectResources */ private TreeSet<ObjectResources> sortObjectResources(final AllResources allResources, final ExistingScheduleFunc existingScheduleFunc) { for (ObjectResources objectResources : allResources.objectResources) { StringBuilder sb = new StringBuilder(); if (allResources.availCpuResourcesOverall <= 0.0 || allResources.availMemResourcesOverall <= 0.0) { objectResources.effectiveResources = 0.0; } else { List<Double> values = new LinkedList<Double>(); //add cpu double cpuPercent = (objectResources.availCpu / allResources.availCpuResourcesOverall) * 100.0; values.add(cpuPercent); sb.append(String.format("CPU %f(%f%%) ", objectResources.availCpu, cpuPercent)); //add memory double memoryPercent = (objectResources.availMem / allResources.availMemResourcesOverall) * 100.0; values.add(memoryPercent); sb.append(String.format("MEM %f(%f%%) ", objectResources.availMem, memoryPercent)); objectResources.effectiveResources = Collections.min(values); } LOG.debug("{}: Avail [ {} ] Total [ CPU {} MEM {}] effective resources: {}", objectResources.id, sb.toString(), objectResources.totalCpu, objectResources.totalMem, objectResources.effectiveResources); } TreeSet<ObjectResources> sortedObjectResources = new TreeSet<ObjectResources>( new Comparator<ObjectResources>() { @Override public int compare(ObjectResources o1, ObjectResources o2) { int execsScheduled1 = existingScheduleFunc.getNumExistingSchedule(o1.id); int execsScheduled2 = existingScheduleFunc.getNumExistingSchedule(o2.id); if (execsScheduled1 > execsScheduled2) { return -1; } else if (execsScheduled1 < execsScheduled2) { return 1; } else { if (o1.effectiveResources > o2.effectiveResources) { return -1; } else if (o1.effectiveResources < o2.effectiveResources) { return 1; } else { List<Double> o1_values = new LinkedList<Double>(); List<Double> o2_values = new LinkedList<Double>(); o1_values.add((o1.availCpu / allResources.availCpuResourcesOverall) * 100.0); o2_values.add((o2.availCpu / allResources.availCpuResourcesOverall) * 100.0); o1_values.add((o1.availMem / allResources.availMemResourcesOverall) * 100.0); o2_values.add((o2.availMem / allResources.availMemResourcesOverall) * 100.0); double o1_avg = ResourceUtils.avg(o1_values); double o2_avg = ResourceUtils.avg(o2_values); if (o1_avg > o2_avg) { return -1; } else if (o1_avg < o2_avg) { return 1; } else { return o1.id.compareTo(o2.id); } } } } }); sortedObjectResources.addAll(allResources.objectResources); LOG.debug("Sorted Object Resources: {}", sortedObjectResources); return sortedObjectResources; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static double minDouble2DArray(double[][] arrayIn) { // Calculate the minimum value of a 2D float array double min = Double.MAX_VALUE; double colMin; for (double[] arrayInRow : arrayIn) { List b = Arrays.asList(ArrayUtils.toObject(arrayInRow)); colMin = (double) Collections.min(b); if (colMin < min) { min = colMin;/* w w w .java2 s.c o m*/ } } return min; }
From source file:com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions.java
public String determineLdapSingleAttributeValue(String dn, String attributeName, Collection<?> values) throws NamingException { if (values == null || values.isEmpty()) { return null; }//from www . jav a 2s . co m Collection<String> stringValues = null; // Determine item type, try to convert to strings Object firstElement = values.iterator().next(); if (firstElement instanceof String) { stringValues = (Collection) values; } else if (firstElement instanceof Element) { stringValues = new ArrayList<String>(values.size()); for (Object value : values) { Element element = (Element) value; stringValues.add(element.getTextContent()); } } else { throw new IllegalArgumentException("Unexpected value type " + firstElement.getClass()); } if (stringValues.size() == 1) { return stringValues.iterator().next(); } if (StringUtils.isBlank(dn)) { throw new IllegalArgumentException( "No dn argument specified, cannot determine which of " + values.size() + " values to use"); } LdapName parsedDn = new LdapName(dn); for (int i = 0; i < parsedDn.size(); i++) { Rdn rdn = parsedDn.getRdn(i); Attributes rdnAttributes = rdn.toAttributes(); NamingEnumeration<String> rdnIDs = rdnAttributes.getIDs(); while (rdnIDs.hasMore()) { String rdnID = rdnIDs.next(); Attribute attribute = rdnAttributes.get(rdnID); if (attributeName.equals(attribute.getID())) { for (int j = 0; j < attribute.size(); j++) { Object value = attribute.get(j); if (stringValues.contains(value)) { return (String) value; } } } } } // Fallback. No values in DN. Just return the first alphabetically-wise value. return Collections.min(stringValues); }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float minDouble3DArray(float[][][] arrayIn) { // Calculate the minimum value of a 3D float array float min = Float.MAX_VALUE; float colMin; for (float[][] twoDInRow : arrayIn) { for (float[] arrayInRow : twoDInRow) { List b = Arrays.asList(ArrayUtils.toObject(arrayInRow)); colMin = (float) Collections.min(b); if (colMin < min) { min = colMin;/*w w w . j ava 2 s. c o m*/ } } } return min; }
From source file:org.libreplan.business.planner.entities.TaskElement.java
public static IntraDayDate minDate(Collection<? extends TaskElement> tasksToSave) { List<IntraDayDate> startDates = toStartDates(tasksToSave); return startDates.isEmpty() ? null : Collections.min(startDates); }
From source file:com.vgi.mafscaling.Rescale.java
private void updateNewMafScale() { try {// w ww. jav a2 s .c om corrMafData.clear(); currMafData.clear(); Utils.clearTable(newMafTable); if (newMaxVFmtTextBox.getValue() == null || maxVUnchangedFmtTextBox.getValue() == null || minVFmtTextBox.getValue() == null || origMafTable.getValueAt(0, 0).toString().isEmpty()) return; if (origVoltArray.size() == 0 || origVoltArray.size() != origGsArray.size()) return; if (origVoltArray.size() < 10) { JOptionPane.showMessageDialog(null, "It looks like you have only partial original MAF scale table", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } double newMafV = (((Number) newMaxVFmtTextBox.getValue()).doubleValue()); if (newMafV < origVoltArray.get(0)) { JOptionPane.showMessageDialog(null, "New Max V [" + newMafV + "] can't be lower than first MAF table value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } if (newMafV > origVoltArray.get(origVoltArray.size() - 1)) { JOptionPane.showMessageDialog(null, "New Max V [" + newMafV + "] can't be higher than last MAF table value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } double minV = (((Number) minVFmtTextBox.getValue()).doubleValue()); if (minV <= origVoltArray.get(1)) { JOptionPane.showMessageDialog(null, "Min V [" + minV + "] must be higher than second MAF table value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } if (minV > newMafV) { JOptionPane.showMessageDialog(null, "Min V [" + minV + "] can't be higher than new MAF V value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } double maxVUnch = (((Number) maxVUnchangedFmtTextBox.getValue()).doubleValue()); if (maxVUnch <= minV) { JOptionPane.showMessageDialog(null, "Max Unchanged [" + maxVUnch + "] must be higher than Min V value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } if (maxVUnch > newMafV) { JOptionPane.showMessageDialog(null, "Max Unchanged [" + maxVUnch + "] can't be higher than new MAF V value", "Invalid Data", JOptionPane.ERROR_MESSAGE); return; } int i, j, z; ArrayList<Double> newVoltArray = new ArrayList<Double>(); ArrayList<Double> newGsArray = new ArrayList<Double>(); newVoltArray.add(origVoltArray.get(0)); newGsArray.add(origGsArray.get(0)); // Find first value greater than MinV from original scale, // calculate mid-point and add them as second and third values to the new array. // After that simply copy all original values up until Max Unchanged value. boolean minFound = false; double val; for (i = 2; i < origVoltArray.size(); ++i) { val = origVoltArray.get(i); if (minFound) { if (val <= maxVUnch) newVoltArray.add(val); else break; } else if (minV <= val) { newVoltArray.add((val - origVoltArray.get(0)) / 2.0 + origVoltArray.get(0)); newVoltArray.add(val); minFound = true; } } int newMaxUnchIdx = newVoltArray.size() - 1; // Find avg % change per section in the original scale but for the same number of points as new scale double pointsCount = origVoltArray.size() - newVoltArray.size(); int sectionCount = (int) Math.ceil((double) pointsCount / (double) CellsPerSection); List<Double> modDeltaList = deltaVoltArray.subList(newMaxUnchIdx, deltaVoltArray.size()); double avgDelta = Utils.mean(modDeltaList); double maxDelta = Collections.max(modDeltaList); double minDelta = Collections.min(modDeltaList); double avgSectionChange = (maxDelta - minDelta) / sectionCount; double changePercent = (maxDelta - minDelta) / avgSectionChange; // Calculate delta per section double delta; ArrayList<Double> adj = new ArrayList<Double>(); for (i = 0; i < sectionCount; ++i) adj.add(avgDelta); int end = (int) Math.floor(sectionCount / 2.0); for (i = 0, j = sectionCount - 1; i < j; ++i, --j) { delta = avgDelta / 100.00 * changePercent * (end - i); adj.set(i, avgDelta - delta); adj.set(j, avgDelta + delta); } // Apply diff for each cell of each section for (i = newMaxUnchIdx + 1, j = 0, z = 0; i < origVoltArray.size(); ++i, ++j) { double diff = adj.get(z); if (j >= CellsPerSection) { j = 0; ++z; diff = adj.get(z); } newVoltArray.add(newVoltArray.get(i - 1) + diff); } // Since the above diffs are based of the original scale change simply adjust the new values to fit the new scale double corr = (newMafV - newVoltArray.get(newVoltArray.size() - 1)) / pointsCount; for (i = newMaxUnchIdx + 1, j = 1; i < newVoltArray.size(); ++i, ++j) newVoltArray.set(i, newVoltArray.get(i) + j * corr); calculateNewGs(newVoltArray, newGsArray); Utils.ensureColumnCount(newVoltArray.size(), newMafTable); for (i = 0; i < newVoltArray.size(); ++i) { newMafTable.setValueAt(newVoltArray.get(i), 0, i); newMafTable.setValueAt(newGsArray.get(i), 1, i); } setXYSeries(currMafData, origVoltArray, origGsArray); setXYSeries(corrMafData, newVoltArray, newGsArray); setRanges(mafChartPanel); } catch (Exception e) { logger.error(e); } }
From source file:edu.utah.further.i2b2.query.criteria.service.impl.I2b2SearchCriterionBuilder.java
/** * Demographic birth date criterion//from www. j a v a 2 s. c o m * * @return the constructed {@link SearchCriterion} */ private SearchCriterion buildDemBirthDate() { final List<Date> dates = toDateList(domain); return SearchCriteria.range(SearchType.BETWEEN, "dateOfBirth", Collections.min(dates), Collections.max(dates)); }
From source file:edu.utah.further.i2b2.query.criteria.service.impl.I2b2SearchCriterionBuilder.java
/** * Demographic birth year criterions for i2b2 are constructed using a BETWEEN * /*from w ww . j a v a 2s . co m*/ * @return the constructed {@link SearchCriterion} */ @SuppressWarnings("boxing") private SearchCriterion buildDemBirthYear() { final List<Integer> years = toIntegerList(domain); return SearchCriteria.range(SearchType.BETWEEN, "birthYear", new Integer(Collections.min(years)), new Integer(Collections.max(years))); }
From source file:edu.utah.further.i2b2.query.criteria.service.impl.I2b2SearchCriterionBuilder.java
@SuppressWarnings("boxing") private SearchCriterion buildCriteriaWithGreaterThan(final String parameterName) { String greaterThanEntry = new String(); for (final String entry : domain) { if (entry.contains(">")) { greaterThanEntry = entry;/*from w w w . j a va 2s . co m*/ domain.remove(entry); break; } } if (!greaterThanEntry.isEmpty()) { if (domain.isEmpty()) { return simpleExpression(greaterThanEntry.contains("=") ? GE : GT, parameterName, Integer.valueOf(greaterThanEntry.substring(greaterThanEntry.length() - 2))); } final List<Integer> years = toIntegerList(domain); return simpleExpression(GE, parameterName, Collections.min(years)); } final List<Integer> years = toIntegerList(domain); return SearchCriteria.range(SearchType.BETWEEN, parameterName, new Integer(Collections.min(years)), new Integer(Collections.max(years))); }