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:com.tesora.dve.tools.DVEAnalyzerCLI.java
private Map<QualifiedName, Integer> getRowCountsFromFile(final File input) throws FileNotFoundException, PEException { final Map<QualifiedName, Integer> rowCounts = new HashMap<QualifiedName, Integer>(); try (final Scanner fileScanner = new Scanner(input)) { boolean isHeaderLine = true; final Integer[] metaColumnIndices = { -1, -1, -1 }; while (fileScanner.hasNextLine()) { final String line = fileScanner.nextLine(); try (@SuppressWarnings("resource") final Scanner lineScanner = new Scanner(line).useDelimiter("\t")) { if (isHeaderLine) { int headerColumnCounter = 0; while (lineScanner.hasNext()) { final String columnHeader = lineScanner.next(); if (columnHeader.equalsIgnoreCase("TABLE_SCHEMA")) { metaColumnIndices[0] = headerColumnCounter; } else if (columnHeader.equalsIgnoreCase("TABLE_NAME")) { metaColumnIndices[1] = headerColumnCounter; } else if (columnHeader.equalsIgnoreCase("TABLE_ROWS")) { metaColumnIndices[2] = headerColumnCounter; }// w ww . j a v a2s . co m ++headerColumnCounter; } if (Collections.min(Arrays.asList(metaColumnIndices)) < 0) { throw new PEException( "Could not find all required column ('TABLE_SCHEMA', 'TABLE_NAME' and 'TABLE_ROWS')."); } isHeaderLine = false; } else { String databaseName = null; String tableName = null; int tableRowCount = 0; int columnCounter = 0; while (lineScanner.hasNext()) { if (columnCounter == metaColumnIndices[0]) { databaseName = lineScanner.next(); } else if (columnCounter == metaColumnIndices[1]) { tableName = lineScanner.next(); } else if (columnCounter == metaColumnIndices[2]) { try { tableRowCount = lineScanner.nextInt(); } catch (final InputMismatchException e) { tableRowCount = 0; // Treat NULL and invalid count values as zero. } } else { lineScanner.next(); } ++columnCounter; } final QualifiedName qualifiedTableName = new QualifiedName( new UnqualifiedName(databaseName), new UnqualifiedName(tableName)); rowCounts.put(qualifiedTableName, tableRowCount); } } } } return rowCounts; }
From source file:org.apache.lens.cube.metadata.CubeMetastoreClient.java
public Date getStorageTableEndDate(String storageTable, String factTableName) throws LensException { List<Date> endDates = getStorageTimes(storageTable, MetastoreUtil.getStoragetableEndTimesKey()); endDates.add((getFactTable(factTableName)).getEndTime()); return Collections.min(endDates); }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) { CorelyzerApp app = CorelyzerApp.getApp(); if (app == null) { return;//from www. ja va2s . co m } if (track >= 0) { // Now, we need to traverse app's list model // to find match of native id // index conversion (native to java list) CRDefaultListModel sessionModel = app.getSessionListModel(); int sessionIndex = -1; TrackSceneNode trackNode = null; for (int i = 0; i < sessionModel.size(); i++) { Session session = (Session) sessionModel.elementAt(i); trackNode = session.getTrackSceneNodeWithTrackId(track); if (trackNode != null) { sessionIndex = i; } } if (sessionIndex < 0) { return; } // Set selected session app.getSessionList().setSelectedIndex(sessionIndex); // Track int ssize; boolean found = false; CRDefaultListModel tmodel = app.getTrackListModel(); // tsize = tmodel.getSize(); TrackSceneNode tt; CoreSection cs = null; for (int i = 0; i < tmodel.size() && !found; i++) { tt = (TrackSceneNode) tmodel.elementAt(i); if (track == tt.getId()) { selectedTrackIndex = i; ssize = tt.getNumCores(); for (int j = 0; j < ssize; j++) { cs = tt.getCoreSection(j); if (section == cs.getId()) { selectedTrackSectionIndex = j; found = true; break; } } } } if (!found || cs == null) { return; } // update ui CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex); JList secList = CorelyzerApp.getApp().getSectionList(); boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex); List<Integer> indices = new ArrayList<Integer>(); indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices()))); if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection if (indices.contains(selectedTrackSectionIndex)) indices.remove(new Integer(selectedTrackSectionIndex)); else indices.add(selectedTrackSectionIndex); int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0])); secList.setSelectedIndices(newSelArray); } else if (event.isShiftDown()) { // select range int[] toSel = null; if (indices.size() == 0) { toSel = makeRangeArray(0, selectedTrackSectionIndex); } else { final int minSel = Collections.min(indices); final int maxSel = Collections.max(indices); if (selectedTrackSectionIndex < minSel) { toSel = makeRangeArray(selectedTrackSectionIndex, minSel); } else if (selectedTrackSectionIndex > maxSel) { toSel = makeRangeArray(maxSel, selectedTrackSectionIndex); } } secList.setSelectedIndices(toSel); } else if (!(event.isAltDown() && selected)) { // don't modify selection if Alt is down and section was already // selected...user is presumably trying to move it secList.setSelectedIndex(selectedTrackSectionIndex); } CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel(); String secName = null; if (lm != null) { Object selSec = lm.getElementAt(selectedTrackSectionIndex); if (selSec != null) { secName = selSec.toString(); } else { System.out.println("no object at index"); } } else { System.out.println("no list model"); } JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0); String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex) .toString(); title.setText("Track: " + trackName); JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1); stitle.setText("Section: " + secName); // Enable section-based popupMenu options this.setEnableSectionBasedPopupMenuOptions(true); // 2/5/2012 brg: check Stagger Sections menu item if necessary final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack); AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14); ab.getModel().setSelected(trackIsStaggered); // check section and graph lock menu items final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection); ab = (AbstractButton) this.scenePopupMenu.getComponent(7); ab.getModel().setSelected(sectionIsLocked); final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack, selectedTrackSection); ab = (AbstractButton) this.scenePopupMenu.getComponent(8); ab.getModel().setSelected(sectionGraphIsLocked); CoreSectionImage csImg = cs.getCoreSectionImage(); if (csImg != null && csImg.getId() != -1) { this.propertyMenuItem.setEnabled(true); this.splitMenuItem.setEnabled(true); } else { this.propertyMenuItem.setEnabled(false); this.splitMenuItem.setEnabled(false); } // System.out.println("---> [in Java DS] Picked Track " + track + // " and Track Section " + section); // String secname = CorelyzerApp.getApp().getSectionListModel(). // getElementAt(section).toString(); // System.out.println("---> [INFO] Section " + secname + // " is selected"); } else { JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0); title.setText("Track: N/A"); JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1); stitle.setText("Section: N/A"); // disable section based items this.setEnableSectionBasedPopupMenuOptions(false); } }
From source file:org.eclipse.dataset.Stats.java
public static double[] outlierValuesList(final Dataset a, int nl, int nh) { final List<Double> lList = new ArrayList<Double>(nl); final List<Double> hList = new ArrayList<Double>(nh); // final List<Double> lList = new LinkedList<Double>(); // final List<Double> hList = new LinkedList<Double>(); double lx = Double.POSITIVE_INFINITY; double hx = Double.NEGATIVE_INFINITY; IndexIterator it = a.getIterator();/*from ww w.java 2s . c o m*/ while (it.hasNext()) { double x = a.getElementDoubleAbs(it.index); if (x < lx) { if (lList.size() == nl) { lList.remove(lx); } lList.add(x); lx = Collections.max(lList); } else if (x == lx) { if (lList.size() < nl) { lList.add(x); } } if (x > hx) { if (hList.size() == nh) { hList.remove(hx); } hList.add(x); hx = Collections.min(hList); } else if (x == hx) { if (hList.size() < nh) { hList.add(x); } } } nl = lList.size(); nh = hList.size(); // Attempt to make values distinct if (lx >= hx) { Collections.sort(hList); for (double h : hList) { if (h > hx) { hx = h; break; } nh--; } if (lx >= hx) { Collections.sort(lList); Collections.reverse(lList); for (double l : lList) { if (l < lx) { lx = l; break; } nl--; } } } return new double[] { lx, hx, nl, nh }; }
From source file:org.eclipse.january.dataset.Stats.java
static double[] outlierValuesList(final Dataset a, int nl, int nh) { final List<Double> lList = new ArrayList<Double>(nl); final List<Double> hList = new ArrayList<Double>(nh); // final List<Double> lList = new LinkedList<Double>(); // final List<Double> hList = new LinkedList<Double>(); double lx = Double.POSITIVE_INFINITY; double hx = Double.NEGATIVE_INFINITY; IndexIterator it = a.getIterator();//from w w w . j a v a2 s . com while (it.hasNext()) { double x = a.getElementDoubleAbs(it.index); if (x < lx) { if (lList.size() == nl) { lList.remove(lx); } lList.add(x); lx = Collections.max(lList); } else if (x == lx) { if (lList.size() < nl) { lList.add(x); } } if (x > hx) { if (hList.size() == nh) { hList.remove(hx); } hList.add(x); hx = Collections.min(hList); } else if (x == hx) { if (hList.size() < nh) { hList.add(x); } } } nl = lList.size(); nh = hList.size(); // Attempt to make values distinct if (lx >= hx) { Collections.sort(hList); for (double h : hList) { if (h > hx) { hx = h; break; } nh--; } if (lx >= hx) { Collections.sort(lList); Collections.reverse(lList); for (double l : lList) { if (l < lx) { lx = l; break; } nl--; } } } return new double[] { lx, hx, nl, nh }; }