本文整理了Java中java.util.TreeSet
类的一些代码示例,展示了TreeSet
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeSet
类的具体详情如下:
包路径:java.util.TreeSet
类名称:TreeSet
[英]TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are supported. The elements can be any objects which are comparable to each other either using their natural order or a specified Comparator.
[中]TreeSet是SortedSet的一个实现。支持所有可选操作(添加和删除)。元素可以是使用其自然顺序或指定比较器彼此可比的任何对象。
代码示例来源:origin: google/guava
@Override
public SortedSet<V> get() {
return new TreeSet<V>(comparator);
}
}
代码示例来源: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/storm
public String getDescription() {
final int size = data.size();
if (size > 0) {
final TimeData first = data.first();
final TimeData last = data.last();
return "Total " + size + " items: " + first + " to " + last;
}
return "Total " + size + " items.";
}
代码示例来源:origin: apache/incubator-druid
public PartitionHolder(PartitionHolder partitionHolder)
{
this.holderSet = new TreeSet<>();
this.holderSet.addAll(partitionHolder.holderSet);
}
代码示例来源: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: stanfordnlp/CoreNLP
/**
* Returns the vertices that are "leftmost, rightmost" Note this requires that the IndexedFeatureLabels present actually have
* ordering information.
* TODO: can be done more efficiently?
*/
public static Pair<IndexedWord, IndexedWord> leftRightMostChildVertices(IndexedWord startNode, SemanticGraph sg) {
TreeSet<IndexedWord> vertices = new TreeSet<>();
for (IndexedWord vertex : sg.descendants(startNode)) {
vertices.add(vertex);
}
return Pair.makePair(vertices.first(), vertices.last());
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Returns the vertice that is "leftmost." Note this requires that the IndexedFeatureLabels present actually have
* ordering information.
* TODO: can be done more efficiently?
*/
public static IndexedWord leftMostChildVertice(IndexedWord startNode, SemanticGraph sg) {
TreeSet<IndexedWord> vertices = new TreeSet<>();
for (IndexedWord vertex : sg.descendants(startNode)) {
vertices.add(vertex);
}
return vertices.first();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns a list of plugins that should be shown in the "available" tab, grouped by category.
* A plugin with multiple categories will appear multiple times in the list.
*/
public PluginEntry[] getCategorizedAvailables() {
TreeSet<PluginEntry> entries = new TreeSet<PluginEntry>();
for (Plugin p : getAvailables()) {
if (p.categories==null || p.categories.length==0)
entries.add(new PluginEntry(p, getCategoryDisplayName(null)));
else
for (String c : p.categories)
entries.add(new PluginEntry(p, getCategoryDisplayName(c)));
}
return entries.toArray(new PluginEntry[entries.size()]);
}
代码示例来源:origin: jenkinsci/jenkins
public CategoryDataset build() {
DefaultCategoryDataset ds = new DefaultCategoryDataset();
TreeSet<Row> rowSet = new TreeSet<Row>(rows);
TreeSet<Column> colSet = new TreeSet<Column>(columns);
Comparable[] _rows = rowSet.toArray(new Comparable[rowSet.size()]);
Comparable[] _cols = colSet.toArray(new Comparable[colSet.size()]);
// insert rows and columns in the right order
for (Comparable r : _rows)
ds.setValue(null, r, _cols[0]);
for (Comparable c : _cols)
ds.setValue(null, _rows[0], c);
for( int i=0; i<values.size(); i++ )
ds.addValue( values.get(i), rows.get(i), columns.get(i) );
return ds;
}
}
代码示例来源:origin: google/ExoPlayer
public long[] getEventTimesUs() {
TreeSet<Long> eventTimeSet = new TreeSet<>();
getEventTimes(eventTimeSet, false);
long[] eventTimes = new long[eventTimeSet.size()];
int i = 0;
for (long eventTimeUs : eventTimeSet) {
eventTimes[i++] = eventTimeUs;
}
return eventTimes;
}
代码示例来源:origin: apache/incubator-druid
public void add(PartitionChunk<T> chunk)
{
holderSet.add(chunk);
}
代码示例来源:origin: google/guava
public void testNewTreeSetEmptyDerived() {
TreeSet<Derived> set = Sets.newTreeSet();
assertTrue(set.isEmpty());
set.add(new Derived("foo"));
set.add(new Derived("bar"));
assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder();
}
代码示例来源:origin: apache/kafka
private void processPartitionMovement(TopicPartition partition,
String newConsumer,
Map<String, List<TopicPartition>> currentAssignment,
TreeSet<String> sortedCurrentSubscriptions,
Map<TopicPartition, String> currentPartitionConsumer) {
String oldConsumer = currentPartitionConsumer.get(partition);
sortedCurrentSubscriptions.remove(oldConsumer);
sortedCurrentSubscriptions.remove(newConsumer);
partitionMovements.movePartition(partition, oldConsumer, newConsumer);
currentAssignment.get(oldConsumer).remove(partition);
currentAssignment.get(newConsumer).add(partition);
currentPartitionConsumer.put(partition, newConsumer);
sortedCurrentSubscriptions.add(newConsumer);
sortedCurrentSubscriptions.add(oldConsumer);
}
代码示例来源:origin: apache/storm
public synchronized void recordAckedOffset(FileOffset newOffset) {
if (newOffset == null) {
return;
}
offsets.add(newOffset);
FileOffset currHead = offsets.first();
if (currHead.isNextOffset(newOffset)) { // check is a minor optimization
trimHead();
}
}
代码示例来源: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: apache/storm
private synchronized void trimHead() {
if (offsets.size() <= 1) {
return;
}
FileOffset head = offsets.first();
FileOffset head2 = offsets.higher(head);
if (head.isNextOffset(head2)) {
offsets.pollFirst();
trimHead();
}
return;
}
代码示例来源:origin: prestodb/presto
private Optional<Object> getLowestValue()
{
return nonNullValues.size() > 0 ? Optional.of(nonNullValues.first()) : Optional.empty();
}
代码示例来源:origin: apache/flink
@Override
public int size() {
return treeSet.size();
}
代码示例来源:origin: prestodb/presto
private Optional<Object> getHighestValue()
{
return nonNullValues.size() > 0 ? Optional.of(nonNullValues.last()) : Optional.empty();
}
代码示例来源:origin: neo4j/neo4j
public Builder( User base )
{
name = base.name;
credential = base.credential;
flags.addAll( base.flags );
}
内容来源于网络,如有侵权,请联系作者删除!