java.util.SortedSet.last()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中java.util.SortedSet.last()方法的一些代码示例,展示了SortedSet.last()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SortedSet.last()方法的具体详情如下:
包路径:java.util.SortedSet
类名称:SortedSet
方法名:last

SortedSet.last介绍

[英]Returns the last element in this SortedSet. The last element is the highest element.
[中]返回此SortedSet中的最后一个元素。最后一个元素是最高的元素。

代码示例

代码示例来源:origin: google/guava

@Override
 protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  int tooHigh = set.isEmpty() ? 0 : set.last() + 1;
  set.add(tooHigh);
  return checkedCreate(set).headSet(tooHigh);
 }
}

代码示例来源:origin: google/guava

/**
 * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in
 * this range.
 */
public boolean containsAll(Iterable<? extends C> values) {
 if (Iterables.isEmpty(values)) {
  return true;
 }
 // this optimizes testing equality of two range-backed sets
 if (values instanceof SortedSet) {
  SortedSet<? extends C> set = cast(values);
  Comparator<?> comparator = set.comparator();
  if (Ordering.natural().equals(comparator) || comparator == null) {
   return contains(set.first()) && contains(set.last());
  }
 }
 for (C value : values) {
  if (!contains(value)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: google/guava

@Override
 protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  if (set.isEmpty()) {
   /*
    * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
    * greater than tooHigh.
    */
   return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1);
  }
  int tooHigh = set.last() + 1;
  int tooLow = set.first() - 1;
  set.add(tooHigh);
  set.add(tooLow);
  return checkedCreate(set).subSet(tooLow + 1, tooHigh);
 }
}

代码示例来源:origin: google/guava

/**
 * Returns the minimal range that {@linkplain Range#contains(Comparable) contains} all of the
 * given values. The returned range is {@linkplain BoundType#CLOSED closed} on both ends.
 *
 * @throws ClassCastException if the values are not mutually comparable
 * @throws NoSuchElementException if {@code values} is empty
 * @throws NullPointerException if any of {@code values} is null
 * @since 14.0
 */
public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) {
 checkNotNull(values);
 if (values instanceof SortedSet) {
  SortedSet<? extends C> set = cast(values);
  Comparator<?> comparator = set.comparator();
  if (Ordering.natural().equals(comparator) || comparator == null) {
   return closed(set.first(), set.last());
  }
 }
 Iterator<C> valueIterator = values.iterator();
 C min = checkNotNull(valueIterator.next());
 C max = min;
 while (valueIterator.hasNext()) {
  C value = checkNotNull(valueIterator.next());
  min = Ordering.natural().min(min, value);
  max = Ordering.natural().max(max, value);
 }
 return closed(min, max);
}

代码示例来源:origin: internetarchive/heritrix3

private static String last(SortedSet<String> set) {
  return set.isEmpty() ? null : set.last();
}

代码示例来源:origin: Graylog2/graylog2-server

public Configuration(Set<Pipeline> pipelines) {
  if (pipelines.isEmpty()) {
    initialStage = extent[0] = extent[1] = 0;
    return;
  }
  pipelines.forEach(pipeline -> {
    // skip pipelines without any stages, they don't contribute any rules to run
    final SortedSet<Stage> stages = pipeline.stages();
    if (stages.isEmpty()) {
      return;
    }
    extent[0] = Math.min(extent[0], stages.first().stage());
    extent[1] = Math.max(extent[1], stages.last().stage());
    stages.forEach(stage -> stageMultimap.put(stage.stage(), stage));
  });
  if (extent[0] == Integer.MIN_VALUE) {
    throw new IllegalArgumentException("First stage cannot be at " + Integer.MIN_VALUE);
  }
  // the stage before the first stage.
  initialStage = extent[0] - 1;
}

代码示例来源:origin: wildfly/wildfly

public static void main(String[] args) {
    SortedSet<Integer> set=new TreeSet<>();

    for(int i=0; i < args.length; i++) {
      set.add(Integer.parseInt(args[i]));
    }

    int low=set.first(), high=set.last();
    System.out.println("input has " + set.size() + " numbers, low=" + low + ", high=" + high);

    Set<Integer> correct_set=new HashSet<>();
    for(int i=low; i < high; i++) {
      correct_set.add(i);
    }

    correct_set.removeAll(set);
    System.out.println("missing seqnos: " + correct_set);
  }
}

代码示例来源:origin: goldmansachs/gs-collections

public T last()
{
  if (this.delegate.isEmpty())
  {
    throw new NoSuchElementException();
  }
  return this.delegate.last();
}

代码示例来源:origin: apache/zookeeper

sortedNames.add(new ZNodeName(dir + "/" + name));
ownerId = sortedNames.first().getName();
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
if (!lessThanMe.isEmpty()) {
  ZNodeName lastChildName = lessThanMe.last();
  lastChildId = lastChildName.getName();
  if (LOG.isDebugEnabled()) {

代码示例来源:origin: google/j2objc

/**
 * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in
 * this range.
 */
public boolean containsAll(Iterable<? extends C> values) {
 if (Iterables.isEmpty(values)) {
  return true;
 }
 // this optimizes testing equality of two range-backed sets
 if (values instanceof SortedSet) {
  SortedSet<? extends C> set = cast(values);
  Comparator<?> comparator = set.comparator();
  if (Ordering.natural().equals(comparator) || comparator == null) {
   return contains(set.first()) && contains(set.last());
  }
 }
 for (C value : values) {
  if (!contains(value)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public T last()
{
  if (this.delegate.isEmpty())
  {
    throw new NoSuchElementException();
  }
  return this.delegate.last();
}

代码示例来源:origin: knightliao/disconf

sortedNames.add(new ZNodeName(dir + "/" + name));
ownerId = sortedNames.first().getName();
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
if (!lessThanMe.isEmpty()) {
  ZNodeName lastChildName = lessThanMe.last();
  lastChildId = lastChildName.getName();
  if (LOG.isDebugEnabled()) {

代码示例来源:origin: robolectric/robolectric

@VisibleForTesting
protected DefaultSdkPicker(@Nonnull SdkCollection sdkCollection, String enabledSdks) {
 this.sdkCollection = sdkCollection;
 this.enabledSdks = enumerateEnabledSdks(sdkCollection, enabledSdks);
 SortedSet<Sdk> sdks = this.sdkCollection.getKnownSdks();
 try {
  minKnownSdk = sdks.first();
  maxKnownSdk = sdks.last();
 } catch (NoSuchElementException e) {
  throw new RuntimeException("no SDKs are supported among " + sdkCollection.getKnownSdks(), e);
 }
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public T last()
{
  if (this.delegate.isEmpty())
  {
    throw new NoSuchElementException();
  }
  return this.delegate.last();
}

代码示例来源:origin: pmd/pmd

if (!dataPoints.isEmpty()) {
  low = dataPoints.first().getScore();
  high = dataPoints.last().getScore();

代码示例来源:origin: wildfly/wildfly

/**
 * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in
 * this range.
 */
public boolean containsAll(Iterable<? extends C> values) {
 if (Iterables.isEmpty(values)) {
  return true;
 }
 // this optimizes testing equality of two range-backed sets
 if (values instanceof SortedSet) {
  SortedSet<? extends C> set = cast(values);
  Comparator<?> comparator = set.comparator();
  if (Ordering.natural().equals(comparator) || comparator == null) {
   return contains(set.first()) && contains(set.last());
  }
 }
 for (C value : values) {
  if (!contains(value)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: groovy/groovy-core

private MultiLineRun getMultiLineRun(int offset) {
  MultiLineRun ml = null;
  if (offset > 0) {
    Integer os = Integer.valueOf(offset);
    SortedSet set = mlTextRunSet.headSet(os);
    if (!set.isEmpty()) {
      ml = (MultiLineRun)set.last();
      ml = ml.end() >= offset ? ml : null;
    }
  }
  return ml;
}

代码示例来源:origin: apache/opennlp

double minComplete = 2;
double bestComplete = -100000; //approximating -infinity/0 in ln domain
while (odh.size() > 0 && (completeParses.size() < M || (odh.first()).getProb() < minComplete)
  && derivationStage < maxDerivationLength) {
 ndh = new TreeSet<>();
    nd = advanceChunks(tp,(ndh.last()).getProb());
 return new Parse[] {completeParses.first()};
 while (!completeParses.isEmpty() && topParses.size() < numParses) {
  Parse tp = completeParses.last();
  completeParses.remove(tp);
  topParses.add(tp);

代码示例来源:origin: google/j2objc

/**
 * Returns the minimal range that {@linkplain Range#contains(Comparable) contains} all of the
 * given values. The returned range is {@linkplain BoundType#CLOSED closed} on both ends.
 *
 * @throws ClassCastException if the parameters are not <i>mutually comparable</i>
 * @throws NoSuchElementException if {@code values} is empty
 * @throws NullPointerException if any of {@code values} is null
 * @since 14.0
 */
public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) {
 checkNotNull(values);
 if (values instanceof SortedSet) {
  SortedSet<? extends C> set = cast(values);
  Comparator<?> comparator = set.comparator();
  if (Ordering.natural().equals(comparator) || comparator == null) {
   return closed(set.first(), set.last());
  }
 }
 Iterator<C> valueIterator = values.iterator();
 C min = checkNotNull(valueIterator.next());
 C max = min;
 while (valueIterator.hasNext()) {
  C value = checkNotNull(valueIterator.next());
  min = Ordering.natural().min(min, value);
  max = Ordering.natural().max(max, value);
 }
 return closed(min, max);
}

代码示例来源:origin: apache/kylin

private static String getFileName(String homePath, Pattern pattern) {
  File home = new File(homePath);
  SortedSet<String> files = Sets.newTreeSet();
  if (home.exists() && home.isDirectory()) {
    File[] listFiles = home.listFiles();
    if (listFiles != null) {
      for (File file : listFiles) {
        final Matcher matcher = pattern.matcher(file.getName());
        if (matcher.matches()) {
          files.add(file.getAbsolutePath());
        }
      }
    }
  }
  if (files.isEmpty()) {
    throw new RuntimeException("cannot find " + pattern.toString() + " in " + homePath);
  } else {
    return files.last();
  }
}

相关文章