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

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

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

TreeSet.<init>介绍

[英]Constructs a new empty instance of TreeSet which uses natural ordering.
[中]构造使用自然排序的TreeSet的新空实例。

代码示例

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

public void redactHeader(String name) {
 Set<String> newHeadersToRedact = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
 newHeadersToRedact.addAll(headersToRedact);
 newHeadersToRedact.add(name);
 headersToRedact = newHeadersToRedact;
}

代码示例来源:origin: hankcs/HanLP

/**
 * 添加一个匹配到的模式串(这个状态对应着这个模式串)
 * @param keyword
 */
public void addEmit(String keyword)
{
  if (this.emits == null)
  {
    this.emits = new TreeSet<String>();
  }
  this.emits.add(keyword);
}

代码示例来源: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: btraceio/btrace

public static List<Interval> union(Collection<Interval> intervals) {
  Set<Interval> itvSet = new TreeSet<>();
  itvSet.addAll(intervals);
  Iterator<Interval> iter = itvSet.iterator();
  Interval previous = null;
  while (iter.hasNext()) {
    if (previous == null) {
      previous = iter.next();
      continue;
    }
    Interval current = iter.next();
    if (current.a <= (previous.b != Integer.MAX_VALUE ? previous.b + 1 : Integer.MAX_VALUE)) {
      previous.b = current.b;
      iter.remove();
    } else {
      previous = current;
    }
  }
  return new ArrayList<>(itvSet);
}

代码示例来源: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: stackoverflow.com

Set<Integer> treeSet = new TreeSet<>();
treeSet.add(3);
treeSet.add(1);
treeSet.add(2);
for (int i : treeSet) {
  System.out.println(i);
}

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

Set<Integer> numbers = new TreeSet<Integer>();
 numbers.add(2);
 numbers.add(5);
 System.out.println(numbers); // "[2, 5]"
 System.out.println(numbers.contains(7)); // "false"
 System.out.println(numbers.add(5)); // "false"
 System.out.println(numbers.size()); // "2"
 int sum = 0;
 for (int n : numbers) {
   sum += n;
 }
 System.out.println("Sum = " + sum); // "Sum = 7"
 numbers.addAll(Arrays.asList(1,2,3,4,5));
 System.out.println(numbers); // "[1, 2, 3, 4, 5]"
 numbers.removeAll(Arrays.asList(4,5,6,7));
 System.out.println(numbers); // "[1, 2, 3]"
 numbers.retainAll(Arrays.asList(2,3,4,5));
 System.out.println(numbers); // "[2, 3]"

代码示例来源:origin: apache/incubator-shardingsphere

@Override
  public Collection<String> doSharding(final Collection<String> availableTargetNames, final Collection<ShardingValue> shardingValues) {
    Collection<String> shardingResult = shardingAlgorithm.doSharding(availableTargetNames, shardingValues.iterator().next());
    Collection<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    result.addAll(shardingResult);
    return result;
  }
}

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

public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
 this.cache = cache;
 this.cacheKey = cacheKey;
 this.chunkIndex = chunkIndex;
 this.regions = new TreeSet<>();
 this.lookupRegion = new Region(0, 0);
 synchronized (this) {
  NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
  // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
  // which is why a descending iterator is used here.
  Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
  while (spanIterator.hasNext()) {
   CacheSpan span = spanIterator.next();
   mergeSpan(span);
  }
 }
}

代码示例来源:origin: swagger-api/swagger-core

@Test(description = "it should maintain property names")
public void maintainPropertyNames() {
  final Map<String, Schema> schemas = readAll(ModelPropertyName.class);
  assertEquals(schemas.size(), 1);
  final String modelName = schemas.keySet().iterator().next();
  assertEquals(modelName, "ModelPropertyName");
  final Schema model = schemas.get(modelName);
  final Iterator<String> itr = new TreeSet(model.getProperties().keySet()).iterator();
  assertEquals(itr.next(), "gettersAndHaters");
  assertEquals(itr.next(), "is_persistent");
}

代码示例来源:origin: Alluxio/alluxio

/**
  * Prints usage for all commands.
  */
 protected void printUsage() {
  System.out.println("Usage: alluxio " + getShellName() + " [generic options]");
  SortedSet<String> sortedCmds = new TreeSet<>(mCommands.keySet());
  for (String cmd : sortedCmds) {
   System.out.format("%-60s%n", "\t [" + mCommands.get(cmd).getUsage() + "]");
  }
 }
}

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

public static void main(String[] args){
  Set<String> s1 = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
  s1.addAll(Arrays.asList(new String[] {"a", "b", "c"}));

  Set<String> s2 = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
  s2.addAll(Arrays.asList(new String[] {"A", "B", "C"}));

  System.out.println(s1.equals(s2));
}

代码示例来源:origin: lealone/Lealone

@Override
protected boolean isTargetEndpoint(Database db) {
  // boolean isTargetEndpoint = super.isTargetEndpoint(db);
  // if (session.isRoot() && isTargetEndpoint) {
  // return true;
  // }
  TreeSet<String> hostIds = new TreeSet<>(Arrays.asList(db.getHostIds()));
  NetEndpoint localEndpoint = NetEndpoint.getLocalTcpEndpoint();
  if (hostIds.iterator().next().equalsIgnoreCase(localEndpoint.getHostAndPort())) {
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: javax.enterprise/cdi-api

private static void findAllProviders() {
  ServiceLoader<CDIProvider> providerLoader;
  Set<CDIProvider> providers = new TreeSet<>(Comparator.comparingInt(CDIProvider::getPriority).reversed());
  providerLoader = ServiceLoader.load(CDIProvider.class, CDI.class.getClassLoader());
  if(! providerLoader.iterator().hasNext()) {
    throw new IllegalStateException("Unable to locate CDIProvider");
  }
  try {
    providerLoader.forEach(providers::add);
  } catch (ServiceConfigurationError e) {
    throw new IllegalStateException(e);
  }
  CDI.discoveredProviders = Collections.unmodifiableSet(providers);
}

代码示例来源: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: 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: stackoverflow.com

Set<Integer> set = new TreeSet<Integer>();
 set.add(1);
 set.add(2);
 set.add(3);
 //good way:
 Iterator<Integer> iterator = set.iterator();
 while(iterator.hasNext()) {
   Integer setElement = iterator.next();
   if(setElement==2) {
     iterator.remove();
   }
 }
 //bad way:
 for(Integer setElement:set) {
   if(setElement==2) {
     //might work or might throw exception, Java calls it indefined behaviour:
     set.remove(setElement);
   } 
 }

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

/**
 * @param args
 *            args
 */
public static void main(String[] args) {
  // TODO Auto-generated method stub
  Properties p = System.getProperties();
  SortedSet keys = new TreeSet(p.keySet());
  for (Iterator it = keys.iterator(); it.hasNext();) {
    String key = (String) it.next();
    System.out.println(key + " = " + p.getProperty(key));
  }
}

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

final SortedSet<String> sortedSet = new TreeSet<String>();
sortedSet.add("One");
sortedSet.add("Two");
sortedSet.add("One");
sortedSet.add("Three");
System.out.println(sortedSet.toString());
// Output: [One, Three, Two]
// (natural order, no duplicates)

代码示例来源:origin: hankcs/HanLP

/**
 * 添加一个匹配到的模式串(这个状态对应着这个模式串)
 * @param keyword
 */
public void addEmit(int keyword)
{
  if (this.emits == null)
  {
    this.emits = new TreeSet<Integer>(Collections.reverseOrder());
  }
  this.emits.add(keyword);
}

相关文章