List of usage examples for java.util Collections max
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)
From source file:net.sourceforge.fenixedu.domain.student.Student.java
public DelegateElection getLastElectedDelegateElection() { List<DelegateElection> elections = new ArrayList<DelegateElection>(getElectedElectionsSet()); return (elections.isEmpty() ? null : Collections.max(elections, DelegateElection.ELECTION_COMPARATOR_BY_VOTING_START_DATE)); }
From source file:com.tesora.dve.tools.aitemplatebuilder.AiTemplateBuilder.java
private Set<TemplateRangeItem> getTopRanges(final Ranges ranges) { if (!ranges.isEmpty()) { final SortedSet<Long> sortedJoinCardinalities = new TreeSet<Long>( ranges.getPredictedFutureJoinCardinalities()); final Set<Long> uniqueJoinFrequencies = new HashSet<Long>(ranges.getJoinFrequencies()); ranges.evaluate(uniqueJoinFrequencies, sortedJoinCardinalities); }//ww w . j a va2s.co m /* * Retain only the highest score ranges, * removing the lower score alternatives. */ final List<CommonRange> sortedRanges = ranges.getSortedCommonRanges(); final Set<TemplateRangeItem> topRanges = new TreeSet<TemplateRangeItem>( new Comparator<TemplateRangeItem>() { @Override public int compare(TemplateRangeItem a, TemplateRangeItem b) { return a.getTemplateItemName().compareTo(b.getTemplateItemName()); } }); while (!sortedRanges.isEmpty()) { final CommonRange top = Collections.max(sortedRanges, FuzzyLinguisticVariable.getScoreComparator()); if ((top.getScore() > 0.0) || (top instanceof UserDefinedCommonRange)) { topRanges.add(top); final ColorStringBuilder progress = new ColorStringBuilder(); progress.append("Overlapping common ranges: ").append(LINE_SEPARATOR); final List<CommonRange> overlappingRanges = Ranges.getOverlapping(sortedRanges, top); sortedRanges.removeAll(overlappingRanges); for (final CommonRange groupRange : overlappingRanges) { progress.append(groupRange); progress.append(LINE_SEPARATOR); } log(progress.toString()); } else { /* * All ranges have zero score. * Most likely because we are in the safe mode * considering only auto-increment columns. * Move on and try to find private ranges for the tables * based on other (ident) columns or fall back to Random. */ sortedRanges.clear(); } } return topRanges; }
From source file:com.ape.camera2raw.Camera2RawFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that * is at least as large as the respective texture view size, and that is at most as large as the * respective max size, and whose aspect ratio matches with the specified value. If such size * doesn't exist, choose the largest one that is at most as large as the respective max size, * and whose aspect ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output * class//from ww w.j a va 2 s . co m * @param textureViewWidth The width of the texture view relative to sensor coordinate * @param textureViewHeight The height of the texture view relative to sensor coordinate * @param maxWidth The maximum width that can be chosen * @param maxHeight The maximum height that can be chosen * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // Collect the supported resolutions that are smaller than the preview Surface List<Size> notBigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight && option.getHeight() == option.getWidth() * h / w) { if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { bigEnough.add(option); } else { notBigEnough.add(option); } } } // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough. if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else if (notBigEnough.size() > 0) { return Collections.max(notBigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
From source file:org.apache.hadoop.hbase.master.assignment.AssignmentManager.java
/** * Get a list of servers that this region can not assign to. * For system table, we must assign them to a server with highest version. *///from w w w .j ava2 s.c om public List<ServerName> getExcludedServersForSystemTable() { List<Pair<ServerName, String>> serverList = master.getServerManager().getOnlineServersList().stream() .map((s) -> new Pair<>(s, master.getRegionServerVersion(s))).collect(Collectors.toList()); if (serverList.isEmpty()) { return new ArrayList<>(); } String highestVersion = Collections .max(serverList, (o1, o2) -> VersionInfo.compareVersion(o1.getSecond(), o2.getSecond())) .getSecond(); return serverList.stream().filter((p) -> !p.getSecond().equals(highestVersion)).map(Pair::getFirst) .collect(Collectors.toList()); }
From source file:net.sourceforge.fenixedu.domain.DegreeCurricularPlan.java
public ExecutionYear getLastExecutionYear() { return Collections.max(getExecutionDegreesSet(), ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_YEAR) .getExecutionYear(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
public boolean hasActiveLastState(final ExecutionSemester executionSemester) { final Set<RegistrationState> states = getRegistrationStates(executionSemester); return states.isEmpty() ? false : Collections.max(states, RegistrationState.DATE_COMPARATOR).isActive(); }
From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java
public Tutorship getLastTutorship() { if (!getTutorshipsSet().isEmpty()) { return Collections.max(getTutorshipsSet(), Tutorship.TUTORSHIP_START_DATE_COMPARATOR); }/*from w w w. j a va 2s . c o m*/ return null; }
From source file:org.apache.hadoop.hbase.util.HBaseFsck.java
/** * Scan hbase:meta, adding all regions found to the regionInfo map. * @throws IOException if an error is encountered *//* www. ja va 2s .com*/ boolean loadMetaEntries() throws IOException { MetaScannerVisitor visitor = new MetaScannerVisitorBase() { int countRecord = 1; // comparator to sort KeyValues with latest modtime final Comparator<Cell> comp = new Comparator<Cell>() { @Override public int compare(Cell k1, Cell k2) { return (int) (k1.getTimestamp() - k2.getTimestamp()); } }; @Override public boolean processRow(Result result) throws IOException { try { // record the latest modification of this META record long ts = Collections.max(result.listCells(), comp).getTimestamp(); Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(result); if (pair == null || pair.getFirst() == null) { emptyRegionInfoQualifiers.add(result); errors.reportError(ERROR_CODE.EMPTY_META_CELL, "Empty REGIONINFO_QUALIFIER found in hbase:meta"); return true; } ServerName sn = null; if (pair.getSecond() != null) { sn = pair.getSecond(); } HRegionInfo hri = pair.getFirst(); if (!(isTableIncluded(hri.getTable()) || hri.isMetaRegion())) { return true; } PairOfSameType<HRegionInfo> daughters = HRegionInfo.getDaughterRegions(result); MetaEntry m = new MetaEntry(hri, sn, ts, daughters.getFirst(), daughters.getSecond()); HbckInfo previous = regionInfoMap.get(hri.getEncodedName()); if (previous == null) { regionInfoMap.put(hri.getEncodedName(), new HbckInfo(m)); } else if (previous.metaEntry == null) { previous.metaEntry = m; } else { throw new IOException("Two entries in hbase:meta are same " + previous); } PairOfSameType<HRegionInfo> mergeRegions = HRegionInfo.getMergeRegions(result); for (HRegionInfo mergeRegion : new HRegionInfo[] { mergeRegions.getFirst(), mergeRegions.getSecond() }) { if (mergeRegion != null) { // This region is already been merged HbckInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName()); hbInfo.setMerged(true); } } // show proof of progress to the user, once for every 100 records. if (countRecord % 100 == 0) { errors.progress(); } countRecord++; return true; } catch (RuntimeException e) { LOG.error("Result=" + result); throw e; } } }; if (!checkMetaOnly) { // Scan hbase:meta to pick up user regions MetaScanner.metaScan(getConf(), visitor); } errors.print(""); return true; }
From source file:org.sakaiproject.component.gradebook.GradebookServiceHibernateImpl.java
/** * set the droppedFromGrade attribute of each * of the n highest and the n lowest scores of a * student based on the assignment's category * @param gradeRecords/*w w w . j a va 2s .c o m*/ * @return void * * NOTE: When the UI changes, this needs to be made private again */ public void applyDropScores(Collection<AssignmentGradeRecord> gradeRecords) { if (gradeRecords == null || gradeRecords.size() < 1) { return; } long start = System.currentTimeMillis(); List<String> studentIds = new ArrayList<String>(); List<Category> categories = new ArrayList<Category>(); Map<String, List<AssignmentGradeRecord>> gradeRecordMap = new HashMap<String, List<AssignmentGradeRecord>>(); for (AssignmentGradeRecord gradeRecord : gradeRecords) { if (gradeRecord == null || gradeRecord.getPointsEarned() == null) { // don't consider grades that have null pointsEarned (this occurs when a previously entered score for an assignment is removed; record stays in database) continue; } // reset gradeRecord.setDroppedFromGrade(false); Assignment assignment = gradeRecord.getAssignment(); if (assignment.getUngraded() // GradebookService.GRADE_TYPE_LETTER || assignment.isNotCounted() // don't consider grades that are not counted toward course grade || assignment.getItemType().equals(Assignment.item_type_adjustment) || assignment.isRemoved()) { continue; } // get all the students represented String studentId = gradeRecord.getStudentId(); if (!studentIds.contains(studentId)) { studentIds.add(studentId); } // get all the categories represented Category cat = gradeRecord.getAssignment().getCategory(); if (cat != null) { if (!categories.contains(cat)) { categories.add(cat); } List<AssignmentGradeRecord> gradeRecordsByCatAndStudent = gradeRecordMap .get(studentId + cat.getId()); if (gradeRecordsByCatAndStudent == null) { gradeRecordsByCatAndStudent = new ArrayList<AssignmentGradeRecord>(); gradeRecordsByCatAndStudent.add(gradeRecord); gradeRecordMap.put(studentId + cat.getId(), gradeRecordsByCatAndStudent); } else { gradeRecordsByCatAndStudent.add(gradeRecord); } } } if (categories == null || categories.size() < 1) { return; } for (Category cat : categories) { Integer dropHighest = cat.getDropHighest(); Integer dropLowest = cat.getDrop_lowest(); Integer keepHighest = cat.getKeepHighest(); Long catId = cat.getId(); if ((dropHighest != null && dropHighest > 0) || (dropLowest != null && dropLowest > 0) || (keepHighest != null && keepHighest > 0)) { for (String studentId : studentIds) { // get the student's gradeRecords for this category List<AssignmentGradeRecord> gradesByCategory = new ArrayList<AssignmentGradeRecord>(); List<AssignmentGradeRecord> gradeRecordsByCatAndStudent = gradeRecordMap .get(studentId + cat.getId()); if (gradeRecordsByCatAndStudent != null) { gradesByCategory.addAll(gradeRecordsByCatAndStudent); int numGrades = gradesByCategory.size(); if (dropHighest > 0 && numGrades > dropHighest + dropLowest) { for (int i = 0; i < dropHighest; i++) { AssignmentGradeRecord highest = Collections.max(gradesByCategory, AssignmentGradeRecord.numericComparator); highest.setDroppedFromGrade(true); gradesByCategory.remove(highest); if (log.isDebugEnabled()) log.debug("dropHighest applied to " + highest); } } if (keepHighest > 0 && numGrades > (gradesByCategory.size() - keepHighest)) { dropLowest = gradesByCategory.size() - keepHighest; } if (dropLowest > 0 && numGrades > dropLowest + dropHighest) { for (int i = 0; i < dropLowest; i++) { AssignmentGradeRecord lowest = Collections.min(gradesByCategory, AssignmentGradeRecord.numericComparator); lowest.setDroppedFromGrade(true); gradesByCategory.remove(lowest); if (log.isDebugEnabled()) log.debug("dropLowest applied to " + lowest); } } } } if (log.isDebugEnabled()) log.debug("processed " + studentIds.size() + "students in category " + cat.getId()); } } if (log.isDebugEnabled()) log.debug("GradebookManager.applyDropScores took " + (System.currentTimeMillis() - start) + " millis to execute"); }
From source file:net.sourceforge.fenixedu.domain.Person.java
public Qualification getLastQualification() { return !getAssociatedQualificationsSet().isEmpty() ? Collections.max(getAssociatedQualificationsSet(), Qualification.COMPARATOR_BY_YEAR) : null;/* w w w . j a v a 2s.c o m*/ }