java.util.TreeSet.add()方法的使用及代码示例

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

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

TreeSet.add介绍

[英]Adds the specified object to this TreeSet.
[中]将指定的对象添加到此树集。

代码示例

代码示例来源:origin: stackoverflow.com

TreeSet<String> set = new TreeSet<String>();
set.add("lol");
set.add("cat");
// automatically sorts natural order when adding

for (String s : set) {
  System.out.println(s);
}
// Prints out "cat" and "lol"

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

@Override
  public void bulkLoadFromOrderedIterator(@Nonnull Iterator<byte[]> orderedIterator) {
    treeSet.clear();
    for (int i = maxSize; --i >= 0 && orderedIterator.hasNext(); ) {
      treeSet.add(orderedIterator.next());
    }
  }
}

代码示例来源:origin: perwendel/spark

/**
 * @return an <code>Enumeration</code> of <code>String</code> objects
 * containing the names of all the objects bound to this session.
 */
public Set<String> attributes() {
  TreeSet<String> attributes = new TreeSet<>();
  Enumeration<String> enumeration = session.getAttributeNames();
  while (enumeration.hasMoreElements()) {
    attributes.add(enumeration.nextElement());
  }
  return attributes;
}

代码示例来源:origin: loklak/loklak_server

private static SortedSet<File> tailSet(SortedSet<File> set, int count) {
  if (count >= set.size()) return set;
  TreeSet<File> t = new TreeSet<File>();
  Iterator<File> fi = set.iterator();
  for (int i = 0; i < set.size() - count; i++) fi.next();
  while (fi.hasNext()) t.add(fi.next());
  return t;
}

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

@Test
public void testIncrementalBackupTableSet() throws IOException {
 TreeSet<TableName> tables1 = new TreeSet<>();
 tables1.add(TableName.valueOf("t1"));
 tables1.add(TableName.valueOf("t2"));
 tables1.add(TableName.valueOf("t3"));
 TreeSet<TableName> tables2 = new TreeSet<>();
 tables2.add(TableName.valueOf("t3"));
 tables2.add(TableName.valueOf("t4"));
 tables2.add(TableName.valueOf("t5"));
 table.addIncrementalBackupTableSet(tables1, "root");
 BackupSystemTable table = new BackupSystemTable(conn);
 TreeSet<TableName> res1 = (TreeSet<TableName>) table.getIncrementalBackupTableSet("root");
 assertTrue(tables1.size() == res1.size());
 Iterator<TableName> desc1 = tables1.descendingIterator();
 Iterator<TableName> desc2 = res1.descendingIterator();
 while (desc1.hasNext()) {
  assertEquals(desc1.next(), desc2.next());
 }
 table.addIncrementalBackupTableSet(tables2, "root");
 TreeSet<TableName> res2 = (TreeSet<TableName>) table.getIncrementalBackupTableSet("root");
 assertTrue((tables2.size() + tables1.size() - 1) == res2.size());
 tables1.addAll(tables2);
 desc1 = tables1.descendingIterator();
 desc2 = res2.descendingIterator();
 while (desc1.hasNext()) {
  assertEquals(desc1.next(), desc2.next());
 }
 cleanBackupTable();
}

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

/**
 * Indicate that a stream escapes at the given target Location.
 *
 * @param source
 *            the Stream that is escaping
 * @param target
 *            the target Location (where the stream escapes)
 */
public void addStreamEscape(Stream source, Location target) {
  StreamEscape streamEscape = new StreamEscape(source, target);
  streamEscapeSet.add(streamEscape);
  if (FindOpenStream.DEBUG) {
    System.out.println("Adding potential stream escape " + streamEscape);
  }
}

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

@Override
  public String next() {
    String r = input.next();
    if (cache.size() < card) {
      cache.add(r);
      return r;
    }
    r = cache.floor(r);
    return r == null ? cache.first() : r;
  }
}

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

public Key executeAfter(final Runnable command, final long time, final TimeUnit unit) {
  final long millis = unit.toMillis(time);
  if ((state & SHUTDOWN) != 0) {
    throw log.threadExiting();
  }
  if (millis <= 0) {
    execute(command);
    return Key.IMMEDIATE;
  }
  final long deadline = (nanoTime() - START_TIME) + Math.min(millis, LONGEST_DELAY) * 1000000L;
  final TimeKey key = new TimeKey(deadline, command);
  synchronized (workLock) {
    final TreeSet<TimeKey> queue = delayWorkQueue;
    queue.add(key);
    if (queue.iterator().next() == key) {
      // we're the next one up; poke the selector to update its delay time
      if (polling) { // flag is always false if we're the same thread
        selector.wakeup();
      }
    }
    return key;
  }
}

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

JavaClass c = Repository.lookupClass(className);
  TreeSet<AnnotationEnum> inheritedAnnotations = new TreeSet<>();
  if (c.getSuperclassNameIndex() > 0) {
      inheritedAnnotations.add(n);
    n = lookInOverriddenMethod(o, implementedInterface, m, getMinimal);
    if (n != null) {
      inheritedAnnotations.add(n);
    System.out.println("# of inherited annotations : " + inheritedAnnotations.size());
    if (inheritedAnnotations.size() == 1) {
      return inheritedAnnotations.first();
    System.out.println("looking for default annotations: " + c.getClassName() + " defines " + m);
System.out.println("Default annotation for " + kind + " is " + n);

代码示例来源:origin: alibaba/jstorm

@SuppressWarnings("unchecked")
@Override
public TreeSet<T> update(Number object, TreeSet<T> cache, Object... others) {
  // TODO Auto-generated method stub
  if (cache == null) {
    cache = new TreeSet<T>(comparator);
  }
  cache.add((T) object);
  if (cache.size() > n) {
    cache.remove(cache.last());
  }
  return cache;
}

代码示例来源:origin: alibaba/jstorm

@Override
public TreeSet<T> merge(Collection<TreeSet<T>> objs, TreeSet<T> unflushed, Object... others) {
  // TODO Auto-generated method stub
  TreeSet<T> temp = new TreeSet<T>(comparator);
  if (unflushed != null) {
    temp.addAll(unflushed);
  }
  for (TreeSet<T> set : objs) {
    temp.addAll(set);
  }
  if (temp.size() <= n) {
    return temp;
  }
  TreeSet<T> ret = new TreeSet<T>(comparator);
  int i = 0;
  for (T item : temp) {
    if (i < n) {
      ret.add(item);
      i++;
    } else {
      break;
    }
  }
  return ret;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Sorted list of unique max-versions in the data set.  For select list in jelly.
 */
@Restricted(NoExternalUse.class)
public Iterator<VersionNumber> getVersionList() {
  TreeSet<VersionNumber> set = new TreeSet<VersionNumber>();
  for (VersionRange vr : data.values()) {
    if (vr.max != null) {
      set.add(vr.max);
    }
  }
  return set.iterator();
}

代码示例来源:origin: cmusphinx/sphinx4

public void add(T item) {
  items.add(item);
  if (items.size() > maxSize)
    items.pollFirst();
}

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

/**
 * Returns a collection of locations, ordered according to the compareTo
 * ordering over locations. If you want to list all the locations in a CFG
 * for debugging purposes, this is a good order to do so in.
 *
 * @return collection of locations
 */
public Collection<Location> orderedLocations() {
  TreeSet<Location> tree = new TreeSet<>();
  for (Iterator<Location> locs = locationIterator(); locs.hasNext();) {
    Location loc = locs.next();
    tree.add(loc);
  }
  return tree;
}

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

/**
 * Constructs a new instance of {@code TreeSet} containing the elements of
 * the specified SortedSet and using the same Comparator.
 *
 * @param set
 *            the SortedSet of elements to add.
 */
public TreeSet(SortedSet<E> set) {
  this(set.comparator());
  Iterator<E> it = set.iterator();
  while (it.hasNext()) {
    add(it.next());
  }
}

代码示例来源:origin: square/moshi

public void run() throws Exception {
 Moshi moshi = new Moshi.Builder()
   .add(new SortedSetAdapterFactory())
   .build();
 JsonAdapter<SortedSet<String>> jsonAdapter = moshi.adapter(
   Types.newParameterizedType(SortedSet.class, String.class));
 TreeSet<String> model = new TreeSet<>();
 model.add("a");
 model.add("b");
 model.add("c");
 String json = jsonAdapter.toJson(model);
 System.out.println(json);
}

代码示例来源:origin: FudanNLP/fnlp

s = s.trim();
  if (!s.matches("^$"))
    sWord.add(s);
System.err.println("停用词文件路径错误");

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

@Override
public Long[] listAllVersions() throws IOException {
  if (!fileSystem.exists(basePath)) {
    return new Long[0]; // for the removed SegmentAppendTrieDictBuilder
  }
  FileStatus[] versionDirs = fileSystem.listStatus(basePath, new PathFilter() {
    @Override
    public boolean accept(Path path) {
      return path.getName().startsWith(VERSION_PREFIX);
    }
  });
  TreeSet<Long> versions = new TreeSet<>();
  for (int i = 0; i < versionDirs.length; i++) {
    Path path = versionDirs[i].getPath();
    versions.add(Long.parseLong(path.getName().substring(VERSION_PREFIX.length())));
  }
  return versions.toArray(new Long[versions.size()]);
}

代码示例来源:origin: square/okhttp

/** Returns an immutable case-insensitive set of header names. */
public Set<String> names() {
 TreeSet<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
 for (int i = 0, size = size(); i < size; i++) {
  result.add(name(i));
 }
 return Collections.unmodifiableSet(result);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
   * Returns an array consisting of the unique values in {@code data}.
   * The return array is sorted in descending order.  Empty arrays
   * are allowed, but null arrays result in NullPointerException.
   * Infinities are allowed.  NaN values are allowed with maximum
   * sort order - i.e., if there are NaN values in {@code data},
   * {@code Double.NaN} will be the first element of the output array,
   * even if the array also contains {@code Double.POSITIVE_INFINITY}.
   *
   * @param data array to scan
   * @return descending list of values included in the input array
   * @throws NullPointerException if data is null
   * @since 3.6
   */
  public static double[] unique(double[] data) {
    TreeSet<Double> values = new TreeSet<Double>();
    for (int i = 0; i < data.length; i++) {
      values.add(data[i]);
    }
    final int count = values.size();
    final double[] out = new double[count];
    Iterator<Double> iterator = values.iterator();
    int i = 0;
    while (iterator.hasNext()) {
      out[count - ++i] = iterator.next();
    }
    return out;
  }
}

相关文章