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

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

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

TreeSet.remove介绍

[英]Removes an occurrence of the specified object from this TreeSet.
[中]从此树集中删除指定对象的引用。

代码示例

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

String s = entity.getEntityStr();
if(dict.contains(s)){
  set1.add(s);
}else{
  set1.add(s);
String s = entity.getEntityStr();
if(dict.contains(s)){
  set2.add(s);
}else{
  set2.add(s);
set1.remove(s);
set2.remove(s);

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

boolean rmv = set.remove(grp);
boolean add = set.add(grp);

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

/**
 * @return the consumer to which the given partition is assigned. The assignment should improve the overall balance
 * of the partition assignments to consumers.
 */
private String assignPartition(TopicPartition partition,
                TreeSet<String> sortedCurrentSubscriptions,
                Map<String, List<TopicPartition>> currentAssignment,
                Map<String, List<TopicPartition>> consumer2AllPotentialPartitions,
                Map<TopicPartition, String> currentPartitionConsumer) {
  for (String consumer: sortedCurrentSubscriptions) {
    if (consumer2AllPotentialPartitions.get(consumer).contains(partition)) {
      sortedCurrentSubscriptions.remove(consumer);
      currentAssignment.get(consumer).add(partition);
      currentPartitionConsumer.put(partition, consumer);
      sortedCurrentSubscriptions.add(consumer);
      return consumer;
    }
  }
  return null;
}

代码示例来源:origin: quartz-scheduler/quartz

if (tw == null)
    break;
  timeTriggers.remove(tw);
} catch (java.util.NoSuchElementException nsee) {
  break;
    timeTriggers.add(tw);
  timeTriggers.add(tw);
  break;

代码示例来源:origin: thinkaurelius/titan

public Map<Long, V> getLatestAccessedItems(int n) {
  Map<Long, V> result = new LinkedHashMap<Long, V>();
  if (n <= 0)
    return result;
  TreeSet<CacheEntry<Long, V>> tree = new TreeSet<CacheEntry<Long, V>>();
  // we need to grab the lock since we are changing lastAccessedCopy
  markAndSweepLock.lock();
  try {
    for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) {
      CacheEntry<Long, V> ce = entry.getValue();
      ce.lastAccessedCopy = ce.lastAccessed;
      if (tree.size() < n) {
        tree.add(ce);
      } else {
        if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) {
          tree.remove(tree.last());
          tree.add(ce);
        }
      }
    }
  } finally {
    markAndSweepLock.unlock();
  }
  for (CacheEntry<Long, V> e : tree) {
    result.put(e.key, e.value);
  }
  return result;
}

代码示例来源:origin: quartz-scheduler/quartz

if (tw == null)
    break;
  timeTriggers.remove(tw);
} catch (java.util.NoSuchElementException nsee) {
  break;
    timeTriggers.add(tw);
  timeTriggers.add(tw);
  break;

代码示例来源:origin: thinkaurelius/titan

ce.lastAccessedCopy = ce.lastAccessed;
if (tree.size() < n) {
  tree.add(ce);
} else {
  if (ce.lastAccessedCopy < tree.first().lastAccessedCopy) {
    tree.remove(tree.first());
    tree.add(ce);

代码示例来源:origin: Sable/soot

killBodies.remove(sn);
  killBodies.remove(nextNode);
  targetHeads.remove(nextNode);
if (sn.get_IndexSet().contains(defaultStr)) {
 sn.get_IndexSet().clear();
 sn.get_IndexSet().add(defaultStr);

代码示例来源:origin: JanusGraph/janusgraph

public Map<Long, V> getLatestAccessedItems(int n) {
  final Map<Long, V> result = new LinkedHashMap<>();
  if (n <= 0)
    return result;
  final TreeSet<CacheEntry<Long, V>> tree = new TreeSet<>();
  // we need to grab the lock since we are changing lastAccessedCopy
  markAndSweepLock.lock();
  try {
    for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) {
      final CacheEntry<Long, V> ce = entry.getValue();
      ce.lastAccessedCopy = ce.lastAccessed;
      if (tree.size() < n) {
        tree.add(ce);
      } else {
        if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) {
          tree.remove(tree.last());
          tree.add(ce);
        }
      }
    }
  } finally {
    markAndSweepLock.unlock();
  }
  for (CacheEntry<Long, V> e : tree) {
    result.put(e.key, e.value);
  }
  return result;
}

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

ackedPerShard.put(shardId, new TreeSet<BigInteger>());
ackedPerShard.get(shardId).add(sequenceNumber);
  emitted.remove(sequenceNumber);
  failedPerShard.get(shardId).remove(sequenceNumber);

代码示例来源:origin: JanusGraph/janusgraph

ce.lastAccessedCopy = ce.lastAccessed;
if (tree.size() < n) {
  tree.add(ce);
} else {
  if (ce.lastAccessedCopy < tree.first().lastAccessedCopy) {
    tree.remove(tree.first());
    tree.add(ce);

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

/**
 * Copies the given span with an updated last access time. Passed span becomes invalid after this
 * call.
 *
 * @param cacheSpan Span to be copied and updated.
 * @return a span with the updated last access time.
 * @throws CacheException If renaming of the underlying span file failed.
 */
public SimpleCacheSpan touch(SimpleCacheSpan cacheSpan) throws CacheException {
 SimpleCacheSpan newCacheSpan = cacheSpan.copyWithUpdatedLastAccessTime(id);
 if (!cacheSpan.file.renameTo(newCacheSpan.file)) {
  throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file
    + " failed.");
 }
 // Replace the in-memory representation of the span.
 Assertions.checkState(cachedSpans.remove(cacheSpan));
 cachedSpans.add(newCacheSpan);
 return newCacheSpan;
}

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

void fail (KinesisMessageId kinesisMessageId) {
  String shardId = kinesisMessageId.getShardId();
  BigInteger sequenceNumber = new BigInteger(kinesisMessageId.getSequenceNumber());
  LOG.debug("Fail received for shardId: {} sequenceNumber: {}", shardId, sequenceNumber);
  // for a failed message add it to failed set if it will be retried, otherwise ack it; remove from emitted either way
  if (kinesisConfig.getFailedMessageRetryHandler().failed(kinesisMessageId)) {
    if (!failedPerShard.containsKey(shardId)) {
      failedPerShard.put(shardId, new TreeSet<BigInteger>());
    }
    failedPerShard.get(shardId).add(sequenceNumber);
    TreeSet<BigInteger> emitted = emittedPerShard.get(shardId);
    emitted.remove(sequenceNumber);
  } else {
    ack(kinesisMessageId);
  }
  // keep committing when topology is deactivated since ack and fail keep getting called on deactivated topology
  if (deactivated) {
    commit();
  }
}

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

if (!canParticipateInReassignment(consumer, currentAssignment,
                 consumer2AllPotentialPartitions, partition2AllPotentialConsumers)) {
  sortedCurrentSubscriptions.remove(consumer);
  fixedAssignments.put(consumer, currentAssignment.remove(consumer));
String consumer = entry.getKey();
currentAssignment.put(consumer, entry.getValue());
sortedCurrentSubscriptions.add(consumer);

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

bestEntries.add(nextLoadReference);
if (!retainAll && (bestEntries.size() > count)) {
 bestEntries.remove(bestEntries.last());

代码示例来源:origin: k9mail/k-9

remainingIds.add(previousId);
List<ContiguousIdGroup> idGroups = new ArrayList<>();
long currentIdGroupStart = -1L;
  if (previousId + 1L == currentId) {
    if (currentIdGroupStart == -1L) {
      remainingIds.remove(previousId);
      currentIdGroupStart = previousId;
      currentIdGroupEnd = currentId;
      currentIdGroupStart = -1L;
    remainingIds.add(currentId);

代码示例来源:origin: ankidroid/Anki-Android

@Override
public TagsArrayAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,int viewType) {
  View v = LayoutInflater.from(parent.getContext())
      .inflate(R.layout.tags_item_list_dialog, parent, false);
  ViewHolder vh = new ViewHolder(v.findViewById(R.id.tags_dialog_tag_item));
  vh.mTagItemCheckedTextView.setOnClickListener(view -> {
    CheckedTextView ctv = (CheckedTextView) view;
    ctv.toggle();
    String tag = ctv.getText().toString();
    if (ctv.isChecked() && !mCurrentTags.contains(tag)) {
      mCurrentTags.add(tag);
    } else if (!ctv.isChecked() && mCurrentTags.contains(tag)) {
      mCurrentTags.remove(tag);
    }
  });
  return vh;
}

代码示例来源:origin: oracle/opengrok

@Override
  public void processStream(InputStream input) throws IOException {
    try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) {
      String line;
      while ((line = in.readLine()) != null) {
        String parts[] = line.split("  *");
        if (parts.length < 2) {
          throw new IOException("Tag line contains more than 2 columns: " + line);
        }
        // Grrr, how to parse tags with spaces inside?
        // This solution will loose multiple spaces;-/
        String tag = parts[0];
        for (int i = 1; i < parts.length - 1; ++i) {
          tag += " " + parts[i];
        }
        TagEntry tagEntry = new BazaarTagEntry(Integer.parseInt(parts[parts.length - 1]), tag);
        // Bazaar lists multiple tags on more lines. We need to merge those into single TagEntry
        TagEntry higher = entries.ceiling(tagEntry);
        if (higher != null && higher.equals(tagEntry)) {
          // Found in the tree, merge tags
          entries.remove(higher);
          tagEntry.setTags(higher.getTags() + ", " + tag);
        }
        entries.add(tagEntry);
      }
    }
  }
}

相关文章