Java Code Examples for java.util.SortedSet#last()
The following examples show how to use
java.util.SortedSet#last() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StructuredDataMaster.java From OpenModsLib with MIT License | 6 votes |
private synchronized ConsistencyCheck createConsistencyCheck() { ConsistencyCheck check = new ConsistencyCheck(); SortedSet<Integer> containers = containerToElement.keySet(); if (!containers.isEmpty()) { check.containerCount = containers.size(); check.minContainerId = containers.first(); check.maxContainerId = containers.last(); } if (!elements.isEmpty()) { check.elementCount = elements.size(); check.minElementId = elements.firstKey(); check.maxElementId = elements.lastKey(); } return check; }
Example 2
Source File: NonLinearScaleMap.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
public double map(double x) { Sample t = new Sample(x, 0); SortedSet<Sample> aset = samples.headSet(t); SortedSet<Sample> bset = samples.tailSet(t); if (aset.isEmpty()) { return bset.first().y; } else { if (bset.isEmpty()) { return aset.last().y; } else { Sample a = aset.last(); Sample b = bset.first(); return MathUtils.lerp(a.y, b.y, (x - a.x) / (b.x - a.x)); } } }
Example 3
Source File: SpotInstanceApiLiveTest.java From attic-stratos with Apache License 2.0 | 6 votes |
@Test public void testDescribeSpotRequestsInRegion() { for (String region : Region.DEFAULT_REGIONS) { SortedSet<SpotInstanceRequest> allResults = ImmutableSortedSet.copyOf(client.getSpotInstanceApi().get() .describeSpotInstanceRequestsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { SpotInstanceRequest request = allResults.last(); SortedSet<SpotInstanceRequest> result = ImmutableSortedSet.copyOf(client.getSpotInstanceApi().get() .describeSpotInstanceRequestsInRegion(region, request.getId())); assertNotNull(result); SpotInstanceRequest compare = result.last(); assertEquals(compare, request); } } }
Example 4
Source File: Camera2.java From SimpleVideoEditor with Apache License 2.0 | 6 votes |
private Size chooseOptimalSize() { int surfaceLonger, surfaceShorter; final int surfaceWidth = mPreview.getWidth(); final int surfaceHeight = mPreview.getHeight(); if (surfaceWidth < surfaceHeight) { surfaceLonger = surfaceHeight; surfaceShorter = surfaceWidth; } else { surfaceLonger = surfaceWidth; surfaceShorter = surfaceHeight; } SortedSet<Size> candidates = mPreviewSizes.sizes(mAspectRatio); // Pick the smallest of those big enough for (Size size : candidates) { if (size.getWidth() >= surfaceLonger && size.getHeight() >= surfaceShorter) { return size; } } // If no size is big enough, pick the largest one. return candidates.last(); }
Example 5
Source File: Dismissal.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public YearMonthDay calculateConclusionDate() { if (getCredits().getOfficialDate() != null) { return new YearMonthDay(getCredits().getOfficialDate()); } final SortedSet<IEnrolment> iEnrolments = new TreeSet<IEnrolment>(IEnrolment.COMPARATOR_BY_APPROVEMENT_DATE); iEnrolments.addAll(getSourceIEnrolments()); final YearMonthDay beginDate = getExecutionPeriod().getBeginDateYearMonthDay(); if (!iEnrolments.isEmpty()) { final IEnrolment enrolment = iEnrolments.last(); final YearMonthDay approvementDate = enrolment.getApprovementDate(); return approvementDate != null ? approvementDate : beginDate; } else { return beginDate; } }
Example 6
Source File: HAManager.java From DDMQ with Apache License 2.0 | 6 votes |
public long selectSlaveId(SortedSet<Long> ids) { long slaveId = -1; if (ids.size() - 1 == ids.last()) { slaveId = ids.last() + 1; } else { long preId = 0; for (long id : ids) { if (id == MixAll.MASTER_ID) { continue; } if (id - preId > 1) { slaveId = preId + 1; break; } preId++; } if (slaveId == -1) { slaveId = ids.last() + 1; } } return slaveId; }
Example 7
Source File: MultiSetBackedSortedSet.java From datawave with Apache License 2.0 | 5 votes |
@Override public E last() { SortedSet<E> lastSet = new TreeSet<>(comparator()); for (SortedSet<E> set : sets) { E s = set.last(); if (s != null) { lastSet.add(s); } } return lastSet.last(); }
Example 8
Source File: Registration.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
final public StudentCurricularPlan getLastStudentDegreeCurricularPlansByDegree(Degree degree) { final SortedSet<StudentCurricularPlan> result = new TreeSet<StudentCurricularPlan>(StudentCurricularPlan.DATE_COMPARATOR); for (DegreeCurricularPlan degreeCurricularPlan : this.getDegreeCurricularPlans()) { if (degreeCurricularPlan.getDegree() == degree) { result.add(this.getStudentCurricularPlan(degreeCurricularPlan)); } } return result.last(); }
Example 9
Source File: Sets.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public E last() { SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered; while (true) { E element = sortedUnfiltered.last(); if (predicate.apply(element)) { return element; } sortedUnfiltered = sortedUnfiltered.headSet(element); } }
Example 10
Source File: Camera1.java From TikTok with Apache License 2.0 | 5 votes |
void adjustCameraParameters() { SortedSet<Size> sizes = mPreviewSizes.sizes(mAspectRatio); if (sizes == null) { // Not supported mAspectRatio = chooseAspectRatio(); sizes = mPreviewSizes.sizes(mAspectRatio); } Size size = chooseOptimalSize(sizes); // Always re-apply camera parameters // Largest picture size in this ratio AspectRatio.parse(aspectRatio) SortedSet<Size> sizeSortedSet = mPictureSizes.sizes(mAspectRatio); if (sizeSortedSet == null) { sizeSortedSet = mPictureSizes.sizes(AspectRatio.parse("4:3")); } final Size pictureSize = sizeSortedSet.last(); if (mShowingPreview) { mCamera.stopPreview(); } mCameraParameters.setPreviewSize(size.getWidth(), size.getHeight()); mCameraParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); mCameraParameters.setRotation(calcCameraRotation(mDisplayOrientation)); setAutoFocusInternal(mAutoFocus); setFlashInternal(mFlash); mCamera.setParameters(mCameraParameters); if (mShowingPreview) { mCamera.startPreview(); } }
Example 11
Source File: SegmentScanner.java From hbase with Apache License 2.0 | 5 votes |
/** * Seek the scanner at the first Cell of the row which is the previous row * of specified key * * @param cell seek value * @return true if the scanner at the first valid Cell of previous row, * false if not existing such Cell */ @Override public boolean seekToPreviousRow(Cell cell) throws IOException { if (closed) { return false; } boolean keepSeeking; Cell key = cell; do { Cell firstKeyOnRow = PrivateCellUtil.createFirstOnRow(key); SortedSet<Cell> cellHead = segment.headSet(firstKeyOnRow); Cell lastCellBeforeRow = cellHead.isEmpty() ? null : cellHead.last(); if (lastCellBeforeRow == null) { current = null; return false; } Cell firstKeyOnPreviousRow = PrivateCellUtil.createFirstOnRow(lastCellBeforeRow); this.stopSkippingKVsIfNextRow = true; this.stopSkippingKVsRow = firstKeyOnPreviousRow; seek(firstKeyOnPreviousRow); this.stopSkippingKVsIfNextRow = false; if (peek() == null || segment.getComparator().compareRows(peek(), firstKeyOnPreviousRow) > 0) { keepSeeking = true; key = firstKeyOnPreviousRow; continue; } else { keepSeeking = false; } } while (keepSeeking); return true; }
Example 12
Source File: AWSKeyPairApiLiveTest.java From attic-stratos with Apache License 2.0 | 5 votes |
@Test void testDescribeAWSKeyPairs() { for (String region : Region.DEFAULT_REGIONS) { SortedSet<KeyPair> allResults = newTreeSet(client.describeKeyPairsInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { KeyPair pair = allResults.last(); SortedSet<KeyPair> result = newTreeSet(client.describeKeyPairsInRegion(region, pair.getKeyName())); assertNotNull(result); KeyPair compare = result.last(); assertEquals(compare, pair); } } }
Example 13
Source File: ExecutionCourse.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static ExecutionCourse readLastByExecutionYearAndSigla(final String sigla, ExecutionYear executionYear) { SortedSet<ExecutionCourse> result = new TreeSet<>(EXECUTION_COURSE_EXECUTION_PERIOD_COMPARATOR); for (final ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { for (ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { if (sigla.equalsIgnoreCase(executionCourse.getSigla())) { result.add(executionCourse); } } } return result.isEmpty() ? null : result.last(); }
Example 14
Source File: Registration.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
final public CycleType getCycleType(final ExecutionYear executionYear) { if (!isBolonha() || isEmptyDegree() || getDegreeType().isEmpty()) { return null; } final SortedSet<CycleType> concludedCycles = new TreeSet<CycleType>(getConcludedCycles(executionYear)); if (concludedCycles.isEmpty()) { CycleCurriculumGroup cycleGroup = getLastStudentCurricularPlan().getFirstOrderedCycleCurriculumGroup(); return cycleGroup != null ? cycleGroup.getCycleType() : null; } else { CycleType result = null; for (CycleType cycleType : concludedCycles) { final CycleCurriculumGroup group = getLastStudentCurricularPlan().getCycle(cycleType); if (group.hasEnrolment(executionYear)) { result = cycleType; } } if (result != null) { return result; } final CycleType last = concludedCycles.last(); return last.hasNext() && getDegreeType().hasCycleTypes(last.getNext()) ? last.getNext() : last; } }
Example 15
Source File: SortedRanges.java From RDFS with Apache License 2.0 | 4 votes |
/** * Add the range indices. It is ensured that the added range * doesn't overlap the existing ranges. If it overlaps, the * existing overlapping ranges are removed and a single range * having the superset of all the removed ranges and this range * is added. * If the range is of 0 length, doesn't do anything. * @param range Range to be added. */ synchronized void add(Range range){ if(range.isEmpty()) { return; } long startIndex = range.getStartIndex(); long endIndex = range.getEndIndex(); //make sure that there are no overlapping ranges SortedSet<Range> headSet = ranges.headSet(range); if(headSet.size()>0) { Range previousRange = headSet.last(); LOG.debug("previousRange "+previousRange); if(startIndex<previousRange.getEndIndex()) { //previousRange overlaps this range //remove the previousRange if(ranges.remove(previousRange)) { indicesCount-=previousRange.getLength(); } //expand this range startIndex = previousRange.getStartIndex(); endIndex = endIndex>=previousRange.getEndIndex() ? endIndex : previousRange.getEndIndex(); } } Iterator<Range> tailSetIt = ranges.tailSet(range).iterator(); while(tailSetIt.hasNext()) { Range nextRange = tailSetIt.next(); LOG.debug("nextRange "+nextRange +" startIndex:"+startIndex+ " endIndex:"+endIndex); if(endIndex>=nextRange.getStartIndex()) { //nextRange overlaps this range //remove the nextRange tailSetIt.remove(); indicesCount-=nextRange.getLength(); if(endIndex<nextRange.getEndIndex()) { //expand this range endIndex = nextRange.getEndIndex(); break; } } else { break; } } add(startIndex,endIndex); }
Example 16
Source File: HAManager.java From DDMQ with Apache License 2.0 | 4 votes |
public RoleChangeInfo selectNewMaster(String cluster, String brokerName) { BrokerData brokerData = namesrvController.getRouteInfoManager().getBrokerData(brokerName); if (brokerData == null || !cluster.equals(brokerData.getCluster())) { log.warn("no broker data for broker name:{}, broker data:{}", brokerName, brokerData); return null; } HashMap<Long, String> brokerAddrs = new HashMap<>(brokerData.getBrokerAddrs()); for (Iterator<Map.Entry<Long, String>> it = brokerAddrs.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, String> item = it.next(); if (item.getKey() > namesrvController.getNamesrvConfig().getMaxIdForRoleSwitch()) { it.remove(); } } //no broker if (brokerAddrs == null || brokerAddrs.isEmpty()) { log.warn("no broker addrs, for broker name:{}, broker data:{}", brokerName, brokerData); return null; } //only one, and master if (brokerAddrs.size() == 1 && brokerAddrs.get(MixAll.MASTER_ID) != null) { log.warn("only on broker, but it is current master"); return null; } //slave exist RoleChangeInfo roleChangeInfo = new RoleChangeInfo(); SortedSet<Long> ids = new TreeSet<>(brokerAddrs.keySet()); if (ids.first() == MixAll.MASTER_ID) { roleChangeInfo.oldMaster = new RoleInChange(brokerAddrs.get(ids.first()), ids.first(), ids.last() + 1); } long newMasterId = pickMaster(brokerAddrs); if (newMasterId == -1) { //newMasterId = ids.last(); log.error("do not get master, broker name:{}", brokerName); return null; } roleChangeInfo.newMaster = new RoleInChange(brokerAddrs.get(newMasterId), newMasterId, MixAll.MASTER_ID); return roleChangeInfo; }
Example 17
Source File: SortedRanges.java From big-c with Apache License 2.0 | 4 votes |
/** * Remove the range indices. If this range is * found in existing ranges, the existing ranges * are shrunk. * If range is of 0 length, doesn't do anything. * @param range Range to be removed. */ synchronized void remove(Range range) { if(range.isEmpty()) { return; } long startIndex = range.getStartIndex(); long endIndex = range.getEndIndex(); //make sure that there are no overlapping ranges SortedSet<Range> headSet = ranges.headSet(range); if(headSet.size()>0) { Range previousRange = headSet.last(); LOG.debug("previousRange "+previousRange); if(startIndex<previousRange.getEndIndex()) { //previousRange overlaps this range //narrow down the previousRange if(ranges.remove(previousRange)) { indicesCount-=previousRange.getLength(); LOG.debug("removed previousRange "+previousRange); } add(previousRange.getStartIndex(), startIndex); if(endIndex<=previousRange.getEndIndex()) { add(endIndex, previousRange.getEndIndex()); } } } Iterator<Range> tailSetIt = ranges.tailSet(range).iterator(); while(tailSetIt.hasNext()) { Range nextRange = tailSetIt.next(); LOG.debug("nextRange "+nextRange +" startIndex:"+startIndex+ " endIndex:"+endIndex); if(endIndex>nextRange.getStartIndex()) { //nextRange overlaps this range //narrow down the nextRange tailSetIt.remove(); indicesCount-=nextRange.getLength(); if(endIndex<nextRange.getEndIndex()) { add(endIndex, nextRange.getEndIndex()); break; } } else { break; } } }
Example 18
Source File: SortedRanges.java From hadoop-gpu with Apache License 2.0 | 4 votes |
/** * Add the range indices. It is ensured that the added range * doesn't overlap the existing ranges. If it overlaps, the * existing overlapping ranges are removed and a single range * having the superset of all the removed ranges and this range * is added. * If the range is of 0 length, doesn't do anything. * @param range Range to be added. */ synchronized void add(Range range){ if(range.isEmpty()) { return; } long startIndex = range.getStartIndex(); long endIndex = range.getEndIndex(); //make sure that there are no overlapping ranges SortedSet<Range> headSet = ranges.headSet(range); if(headSet.size()>0) { Range previousRange = headSet.last(); LOG.debug("previousRange "+previousRange); if(startIndex<previousRange.getEndIndex()) { //previousRange overlaps this range //remove the previousRange if(ranges.remove(previousRange)) { indicesCount-=previousRange.getLength(); } //expand this range startIndex = previousRange.getStartIndex(); endIndex = endIndex>=previousRange.getEndIndex() ? endIndex : previousRange.getEndIndex(); } } Iterator<Range> tailSetIt = ranges.tailSet(range).iterator(); while(tailSetIt.hasNext()) { Range nextRange = tailSetIt.next(); LOG.debug("nextRange "+nextRange +" startIndex:"+startIndex+ " endIndex:"+endIndex); if(endIndex>=nextRange.getStartIndex()) { //nextRange overlaps this range //remove the nextRange tailSetIt.remove(); indicesCount-=nextRange.getLength(); if(endIndex<nextRange.getEndIndex()) { //expand this range endIndex = nextRange.getEndIndex(); break; } } else { break; } } add(startIndex,endIndex); }
Example 19
Source File: Alumni.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 4 votes |
public PhysicalAddress getLastPersonalAddress() { SortedSet<PhysicalAddress> addressSet = new TreeSet<PhysicalAddress>(DomainObjectUtil.COMPARATOR_BY_ID); addressSet.addAll(getStudent().getPerson().getPhysicalAddresses()); return !addressSet.isEmpty() && addressSet.last() != null ? addressSet.last() : null; }
Example 20
Source File: ManagedExtension.java From rapidminer-studio with GNU Affero General Public License v3.0 | 2 votes |
/** * Find the installed VersionNumber that is younger than the given version * @since 8.0 * @param version a VersionNumber String representation that is the search limit * @return newest installed version before param version */ public VersionNumber getLatestInstalledVersionBefore(String version) { SortedSet<VersionNumber> head = installedVersions.headSet(new VersionNumber(version)); return head.isEmpty() ? null : head.last(); }