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.vgi.mafscaling.Rescale.java
private void updateNewMafScale() { try {//from w w w . ja va 2s . co m 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 w w w .j a va 2s. co 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:io.plaidapp.ui.HomeActivity.java
/** * Highlight the new item by://from w ww . j av a2s . c om * 1. opening the drawer * 2. scrolling it into view * 3. flashing it's background * 4. closing the drawer */ private void highlightNewSources(final Source... sources) { final Runnable closeDrawerRunnable = new Runnable() { @Override public void run() { drawer.closeDrawer(GravityCompat.END); } }; drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { // if the user interacts with the filters while it's open then don't auto-close private final View.OnTouchListener filtersTouch = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { drawer.removeCallbacks(closeDrawerRunnable); return false; } }; @Override public void onDrawerOpened(View drawerView) { // scroll to the new item(s) and highlight them List<Integer> filterPositions = new ArrayList<>(sources.length); for (Source source : sources) { if (source != null) { filterPositions.add(filtersAdapter.getFilterPosition(source)); } } int scrollTo = Collections.max(filterPositions); filtersList.smoothScrollToPosition(scrollTo); for (int position : filterPositions) { FilterAdapter.FilterViewHolder holder = (FilterAdapter.FilterViewHolder) filtersList .findViewHolderForAdapterPosition(position); if (holder != null) { // this is failing for the first saved search, then working for subsequent calls // TODO work out why! holder.highlightFilter(); } } filtersList.setOnTouchListener(filtersTouch); } @Override public void onDrawerClosed(View drawerView) { // reset filtersList.setOnTouchListener(null); drawer.setDrawerListener(null); } @Override public void onDrawerStateChanged(int newState) { // if the user interacts with the drawer manually then don't auto-close if (newState == DrawerLayout.STATE_DRAGGING) { drawer.removeCallbacks(closeDrawerRunnable); } } }); drawer.openDrawer(GravityCompat.END); drawer.postDelayed(closeDrawerRunnable, 2000); }
From source file:edu.utah.further.i2b2.query.criteria.service.impl.I2b2SearchCriterionBuilder.java
/** * Demographic birth year criterions for i2b2 are constructed using a BETWEEN * /*w ww.j a va 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.cmu.tetrad.search.TimeSeriesUtils.java
public static IKnowledge getKnowledge(Graph graph) { // System.out.println("Entering getKnowledge ... "); int numLags = 1; // need to fix this! List<Node> variables = graph.getNodes(); List<Integer> laglist = new ArrayList<>(); IKnowledge knowledge = new Knowledge2(); int lag;//w w w . j a va2s .c om for (Node node : variables) { String varName = node.getName(); String tmp; if (varName.indexOf(':') == -1) { lag = 0; laglist.add(lag); } else { tmp = varName.substring(varName.indexOf(':') + 1, varName.length()); lag = Integer.parseInt(tmp); laglist.add(lag); } } numLags = Collections.max(laglist); // System.out.println("Variable list before the sort = " + variables); Collections.sort(variables, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { String name1 = getNameNoLag(o1); String name2 = getNameNoLag(o2); // System.out.println("name 1 = " + name1); // System.out.println("name 2 = " + name2); String prefix1 = getPrefix(name1); String prefix2 = getPrefix(name2); // System.out.println("prefix 1 = " + prefix1); // System.out.println("prefix 2 = " + prefix2); int index1 = getIndex(name1); int index2 = getIndex(name2); // System.out.println("index 1 = " + index1); // System.out.println("index 2 = " + index2); if (getLag(o1.getName()) == getLag(o2.getName())) { if (prefix1.compareTo(prefix2) == 0) { return Integer.compare(index1, index2); } else { return prefix1.compareTo(prefix2); } } else { return getLag(o1.getName()) - getLag(o2.getName()); } } }); // System.out.println("Variable list after the sort = " + variables); for (Node node : variables) { String varName = node.getName(); String tmp; if (varName.indexOf(':') == -1) { lag = 0; // laglist.add(lag); } else { tmp = varName.substring(varName.indexOf(':') + 1, varName.length()); lag = Integer.parseInt(tmp); // laglist.add(lag); } knowledge.addToTier(numLags - lag, node.getName()); } //System.out.println("Knowledge in graph = " + knowledge); return knowledge; }
From source file:com.example.lijingjiang.mobile_sensor_display.SimplePedometerActivity.java
public double[] SleepEfficiency(ArrayList<Integer> sleep, double targetRating) { int LF = 0;// ww w. j a v a2s.c om int HF = 0; int window = 60; int index = 0; while (index + window < sleep.size()) { List<Integer> subSleep = sleep.subList(index, index + window); if (Collections.max(subSleep) - Collections.min(subSleep) < 9) { LF++; } else { HF++; } index = index + window; } List<Integer> subSleep = sleep.subList(index, sleep.size() - 1); if (Collections.max(subSleep) - Collections.min(subSleep) < 9) { LF++; } else { HF++; } double data[] = new double[2]; data[0] = LF / HF; //rating data[1] = 1 - (Math.abs(targetRating - data[0]) / data[0]); //efficiency return data; }
From source file:com.vgi.mafscaling.ClosedLoop.java
private void calculateCorrectedGS() { double time;//from www . java2s . com double load; double rpm; double dvdt; double afr; double mafv; double stft; double ltft; double iat; double corr; double val1; double val2; String timeStr; String loadStr; String rpmStr; String mafvStr; String afrStr; String stftStr; String ltftStr; String dvdtStr; String iatStr; int closestMafIdx; int closestRmpIdx; int closestLoadIdx; int i; String tableName = "Log Data"; ArrayList<Integer> temp = new ArrayList<Integer>(gsArray.size()); correctionMeanArray = new ArrayList<Double>(gsArray.size()); correctionModeArray = new ArrayList<Double>(gsArray.size()); ArrayList<HashMap<Double, Integer>> modeCalcArray = new ArrayList<HashMap<Double, Integer>>(); for (i = 0; i < gsArray.size(); ++i) { temp.add(0); correctionMeanArray.add(0.0); correctionModeArray.add(0.0); modeCalcArray.add(new HashMap<Double, Integer>()); } ArrayList<Double> afrRpmArray = new ArrayList<Double>(); for (i = 1; i < polfTable.getRowCount(); ++i) { afrRpmArray.add(Double.valueOf(polfTable.getValueAt(i, 0).toString())); Utils.ensureRowCount(i + 1, afr1Table); Utils.ensureRowCount(i + 1, afr2Table); afr1Table.setValueAt(polfTable.getValueAt(i, 0), i, 0); afr2Table.setValueAt(polfTable.getValueAt(i, 0), i, 0); } ArrayList<Double> afrLoadArray = new ArrayList<Double>(); for (i = 1; i < polfTable.getColumnCount(); ++i) { afrLoadArray.add(Double.valueOf(polfTable.getValueAt(0, i).toString())); Utils.ensureColumnCount(i + 1, afr1Table); Utils.ensureColumnCount(i + 1, afr2Table); afr1Table.setValueAt(polfTable.getValueAt(0, i), 0, i); afr2Table.setValueAt(polfTable.getValueAt(0, i), 0, i); } Integer val; HashMap<Double, Integer> modeCountMap; for (i = 0; i < logDataTable.getRowCount(); ++i) { timeStr = logDataTable.getValueAt(i, 0).toString(); loadStr = logDataTable.getValueAt(i, 1).toString(); rpmStr = logDataTable.getValueAt(i, 2).toString(); mafvStr = logDataTable.getValueAt(i, 3).toString(); afrStr = logDataTable.getValueAt(i, 4).toString(); stftStr = logDataTable.getValueAt(i, 5).toString(); ltftStr = logDataTable.getValueAt(i, 6).toString(); dvdtStr = logDataTable.getValueAt(i, 7).toString(); iatStr = logDataTable.getValueAt(i, 8).toString(); if (timeStr.isEmpty() || loadStr.isEmpty() || rpmStr.isEmpty() || mafvStr.isEmpty() || afrStr.isEmpty() || stftStr.isEmpty() || ltftStr.isEmpty() || dvdtStr.isEmpty() || iatStr.isEmpty()) break; if (!Utils.validateDouble(timeStr, i, 0, tableName) || !Utils.validateDouble(loadStr, i, 1, tableName) || !Utils.validateDouble(rpmStr, i, 2, tableName) || !Utils.validateDouble(mafvStr, i, 3, tableName) || !Utils.validateDouble(afrStr, i, 4, tableName) || !Utils.validateDouble(stftStr, i, 5, tableName) || !Utils.validateDouble(ltftStr, i, 6, tableName) || !Utils.validateDouble(dvdtStr, i, 7, tableName) || !Utils.validateDouble(iatStr, i, 8, tableName)) return; time = Double.valueOf(timeStr); load = Double.valueOf(loadStr); rpm = Double.valueOf(rpmStr); mafv = Double.valueOf(mafvStr); afr = Double.valueOf(afrStr); stft = Double.valueOf(stftStr); ltft = Double.valueOf(ltftStr); dvdt = Double.valueOf(dvdtStr); iat = Double.valueOf(iatStr); corr = ltft + stft; trimArray.add(corr); rpmArray.add(rpm); timeArray.add(time); iatArray.add(iat); mafvArray.add(mafv); dvdtArray.add(dvdt); closestMafIdx = Utils.closestValueIndex(load * rpm / 60.0, gsArray); correctionMeanArray.set(closestMafIdx, (correctionMeanArray.get(closestMafIdx) * temp.get(closestMafIdx) + corr) / (temp.get(closestMafIdx) + 1)); temp.set(closestMafIdx, temp.get(closestMafIdx) + 1); modeCountMap = modeCalcArray.get(closestMafIdx); double roundedCorr = ((double) Math.round(corr * 10.0)) / 10.0; val = modeCountMap.get(roundedCorr); if (val == null) modeCountMap.put(roundedCorr, 1); else modeCountMap.put(roundedCorr, val + 1); closestRmpIdx = Utils.closestValueIndex(rpm, afrRpmArray) + 1; closestLoadIdx = Utils.closestValueIndex(load, afrLoadArray) + 1; val1 = (afr1Table.getValueAt(closestRmpIdx, closestLoadIdx).toString().isEmpty()) ? 0 : Double.valueOf(afr1Table.getValueAt(closestRmpIdx, closestLoadIdx).toString()); val2 = (afr2Table.getValueAt(closestRmpIdx, closestLoadIdx).toString().isEmpty()) ? 0 : Double.valueOf(afr2Table.getValueAt(closestRmpIdx, closestLoadIdx).toString()); afr1Table.setValueAt((val1 * val2 + afr) / (val2 + 1.0), closestRmpIdx, closestLoadIdx); afr2Table.setValueAt(val2 + 1.0, closestRmpIdx, closestLoadIdx); } for (i = 0; i < modeCalcArray.size(); ++i) { modeCountMap = modeCalcArray.get(i); if (modeCountMap.size() > 0) { int maxValueInMap = (Collections.max(modeCountMap.values())); double sum = 0; int count = 0; for (Entry<Double, Integer> entry : modeCountMap.entrySet()) { if (entry.getValue() == maxValueInMap) { sum += entry.getKey(); count += 1; } } correctionModeArray.set(i, sum / count); } } int size = afrRpmArray.size() + 1; while (size < afr1Table.getRowCount()) Utils.removeRow(size, afr1Table); while (size < afr2Table.getRowCount()) Utils.removeRow(size, afr2Table); Utils.colorTable(afr1Table); Utils.colorTable(afr2Table); int firstCorrIndex = 0; double firstCorr = 1; for (i = 0; i < correctionMeanArray.size(); ++i) { corr = 1; if (temp.get(i) > minCellHitCount) { corr = 1.0 + (correctionMeanArray.get(i) + correctionModeArray.get(i)) / 200.00; if (firstCorrIndex == 0) { firstCorrIndex = i; firstCorr = corr; } } gsCorrected.add(i, gsArray.get(i) * corr); } for (i = firstCorrIndex - 1; i > 0; --i) gsCorrected.set(i, gsArray.get(i) * firstCorr); }
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 ww w.j a v a2 s. c o 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))); }
From source file:org.apache.giraph.bsp.BspService.java
/** * Get the latest application attempt and cache it. * * @return the latest application attempt *//*from w w w . jav a2 s . co m*/ public final long getApplicationAttempt() { if (cachedApplicationAttempt != UNSET_APPLICATION_ATTEMPT) { return cachedApplicationAttempt; } try { getZkExt().createExt(applicationAttemptsPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { LOG.info("getApplicationAttempt: Node " + applicationAttemptsPath + " already exists!"); } catch (KeeperException e) { throw new IllegalStateException("Couldn't create application " + "attempts path due to KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException( "Couldn't create application " + "attempts path due to InterruptedException", e); } try { List<String> attemptList = getZkExt().getChildrenExt(applicationAttemptsPath, true, false, false); if (attemptList.isEmpty()) { cachedApplicationAttempt = 0; } else { cachedApplicationAttempt = Long.parseLong(Collections.max(attemptList)); } } catch (KeeperException e) { throw new IllegalStateException("Couldn't get application " + "attempts to KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException("Couldn't get application " + "attempts to InterruptedException", e); } return cachedApplicationAttempt; }
From source file:org.apache.giraph.bsp.BspService.java
/** * Get the latest superstep and cache it. * * @return the latest superstep//from www . ja v a2 s. c o m * @throws InterruptedException * @throws KeeperException */ public final long getSuperstep() { if (cachedSuperstep != UNSET_SUPERSTEP) { return cachedSuperstep; } String superstepPath = getSuperstepPath(getApplicationAttempt()); try { getZkExt().createExt(superstepPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { if (LOG.isInfoEnabled()) { LOG.info("getApplicationAttempt: Node " + applicationAttemptsPath + " already exists!"); } } catch (KeeperException e) { throw new IllegalStateException("getSuperstep: KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException("getSuperstep: InterruptedException", e); } List<String> superstepList; try { superstepList = getZkExt().getChildrenExt(superstepPath, true, false, false); } catch (KeeperException e) { throw new IllegalStateException("getSuperstep: KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException("getSuperstep: InterruptedException", e); } if (superstepList.isEmpty()) { cachedSuperstep = INPUT_SUPERSTEP; } else { cachedSuperstep = Long.parseLong(Collections.max(superstepList)); } return cachedSuperstep; }