last ( )源码实例Demo

java.util.SortedSet#last ( )源码实例Demo

下面列出了java.util.SortedSet#last ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenModsLib   文件: StructuredDataMaster.java
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;
}
 
源代码2 项目: DDMQ   文件: HAManager.java
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;
}
 
源代码3 项目: fenixedu-academic   文件: Dismissal.java
@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;
    }
}
 
源代码4 项目: SimpleVideoEditor   文件: Camera2.java
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();
}
 
源代码5 项目: attic-stratos   文件: SpotInstanceApiLiveTest.java
@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);
      }
   }

}
 
源代码6 项目: toxiclibs   文件: NonLinearScaleMap.java
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));
        }
    }
}
 
源代码7 项目: fenixedu-academic   文件: Registration.java
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();

}
 
源代码8 项目: datawave   文件: MultiSetBackedSortedSet.java
@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();
}
 
源代码9 项目: codebuff   文件: Sets.java
@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);
  }
}
 
源代码10 项目: TikTok   文件: Camera1.java
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();
    }
}
 
源代码11 项目: hbase   文件: SegmentScanner.java
/**
 * 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;
}
 
源代码12 项目: attic-stratos   文件: AWSKeyPairApiLiveTest.java
@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);
      }
   }
}
 
源代码13 项目: fenixedu-academic   文件: ExecutionCourse.java
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();
}
 
源代码14 项目: fenixedu-academic   文件: Registration.java
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;
    }
}
 
源代码15 项目: fenixedu-academic   文件: Alumni.java
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;
}
 
源代码16 项目: DDMQ   文件: HAManager.java
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;
}
 
源代码17 项目: RDFS   文件: SortedRanges.java
/**
 * 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);
}
 
源代码18 项目: big-c   文件: SortedRanges.java
/**
 * 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;
    }
  }
}
 
源代码19 项目: hadoop-gpu   文件: SortedRanges.java
/**
 * 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);
}
 
源代码20 项目: rapidminer-studio   文件: ManagedExtension.java
/**
 * 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();
}