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

x33g5p2x  于2022-01-16 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(196)

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

Set.remove介绍

[英]Removes the specified object from this set.
[中]从此集中删除指定的对象。

代码示例

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

private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> features) {
 Set<Feature<?>> derivedFeatures = new HashSet<>();
 derivedFeatures.addAll(features);
 derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE);
 derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD);
 derivedFeatures.remove(CollectionFeature.ALLOWS_NULL_VALUES);
 derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
 if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
  derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
 }
 return derivedFeatures;
}

代码示例来源:origin: iluwatar/java-design-patterns

public synchronized void checkIn(T instance) {
 inUse.remove(instance);
 available.add(instance);
}

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

public void removeListener(String key, ConfigurationListener configurationListener) {
  Set<ConfigurationListener> listeners = this.keyListeners.get(key);
  if (listeners != null) {
    listeners.remove(configurationListener);
  }
}

代码示例来源:origin: prestodb/presto

private void addOrReplaceExpressionCoercion(Expression expression, Type type, Type superType)
  {
    NodeRef<Expression> ref = NodeRef.of(expression);
    expressionCoercions.put(ref, superType);
    if (typeManager.isTypeOnlyCoercion(type, superType)) {
      typeOnlyCoercions.add(ref);
    }
    else if (typeOnlyCoercions.contains(ref)) {
      typeOnlyCoercions.remove(ref);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Remove the given prefix from this context.
 * @param prefix the prefix to be removed
 */
public void removeBinding(@Nullable String prefix) {
  if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
    this.defaultNamespaceUri = "";
  }
  else if (prefix != null) {
    String namespaceUri = this.prefixToNamespaceUri.remove(prefix);
    if (namespaceUri != null) {
      Set<String> prefixes = this.namespaceUriToPrefixes.get(namespaceUri);
      if (prefixes != null) {
        prefixes.remove(prefix);
        if (prefixes.isEmpty()) {
          this.namespaceUriToPrefixes.remove(namespaceUri);
        }
      }
    }
  }
}

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

/**
 * connect adds an edge between a and b. Both nodes have
 * to be added prior to calling connect.
 * @param
 */
public void connect(BaseWork a, BaseWork b, SparkEdgeProperty edgeProp) {
 workGraph.get(a).add(b);
 invertedWorkGraph.get(b).add(a);
 roots.remove(b);
 leaves.remove(a);
 ImmutablePair<BaseWork, BaseWork> workPair = new ImmutablePair<BaseWork, BaseWork>(a, b);
 edgeProperties.put(workPair, edgeProp);
}

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

@SuppressWarnings({"unchecked"})
public List<Modification> getModificationsForPipelineRange(final String pipelineName,
                              final Integer fromCounter,
                              final Integer toCounter) {
  return (List<Modification>) getHibernateTemplate().execute((HibernateCallback) session -> {
    final List<Long> fromInclusiveModificationList = fromInclusiveModificationsForPipelineRange(session, pipelineName, fromCounter, toCounter);
    final Set<Long> fromModifications = new TreeSet<>(fromInclusiveModificationsForPipelineRange(session, pipelineName, fromCounter, fromCounter));
    final Set<Long> fromExclusiveModificationList = new HashSet<>();
    for (Long modification : fromInclusiveModificationList) {
      if (fromModifications.contains(modification)) {
        fromModifications.remove(modification);
      } else {
        fromExclusiveModificationList.add(modification);
      }
    }
    SQLQuery query = session.createSQLQuery("SELECT * FROM modifications WHERE id IN (:ids) ORDER BY materialId ASC, id DESC");
    query.addEntity(Modification.class);
    query.setParameterList("ids", fromExclusiveModificationList.isEmpty() ? fromInclusiveModificationList : fromExclusiveModificationList);
    return query.list();
  });
}

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

private void merge(Group g1, Group g2) {
  Group newGroup = new Group(g1, g2);
  currGroups.remove(g1);
  currGroups.remove(g2);
  currGroups.add(newGroup);
  for (Node n : newGroup.nodes) {
    groupIndex.put(n, newGroup);
  }
}

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

private static Set<Feature<?>> computeAsMapFeatures(Set<Feature<?>> multimapFeatures) {
 Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
 derivedFeatures.remove(MapFeature.GENERAL_PURPOSE);
 derivedFeatures.remove(MapFeature.SUPPORTS_PUT);
 derivedFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);
 derivedFeatures.add(MapFeature.ALLOWS_NULL_VALUE_QUERIES);
 derivedFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);
 if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
  derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
 }
 return derivedFeatures;
}

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

private void updateToLoadAndDrop(
  List<Notice> notices,
  Map<String, LookupExtractorFactoryContainer> lookupsToLoad,
  Set<String> lookupsToDrop
)
{
 for (Notice notice : notices) {
  if (notice instanceof LoadNotice) {
   LoadNotice loadNotice = (LoadNotice) notice;
   lookupsToLoad.put(loadNotice.lookupName, loadNotice.lookupExtractorFactoryContainer);
   lookupsToDrop.remove(loadNotice.lookupName);
  } else if (notice instanceof DropNotice) {
   DropNotice dropNotice = (DropNotice) notice;
   lookupsToDrop.add(dropNotice.lookupName);
   lookupsToLoad.remove(dropNotice.lookupName);
  } else {
   throw new ISE("Unknown Notice type [%s].", notice.getClass().getName());
  }
 }
}

代码示例来源:origin: fesh0r/fernflower

private void buildDominatorTree() {
 VBStyleCollection<Integer, Integer> orderedIDoms = domEngine.getOrderedIDoms();
 List<Integer> lstKeys = orderedIDoms.getLstKeys();
 for (int index = lstKeys.size() - 1; index >= 0; index--) {
  Integer key = lstKeys.get(index);
  Integer idom = orderedIDoms.get(index);
  mapTreeBranches.computeIfAbsent(idom, k -> new HashSet<>()).add(key);
 }
 Integer firstid = statement.getFirst().id;
 mapTreeBranches.get(firstid).remove(firstid);
}

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * Checkout object from pool
 */
public synchronized T checkOut() {
 if (available.isEmpty()) {
  available.add(create());
 }
 T instance = available.iterator().next();
 available.remove(instance);
 inUse.add(instance);
 return instance;
}

代码示例来源:origin: spring-projects/spring-framework

public static Method[] getPropertyMethods(PropertyDescriptor[] properties, boolean read, boolean write) {
  Set methods = new HashSet();
  for (int i = 0; i < properties.length; i++) {
    PropertyDescriptor pd = properties[i];
    if (read) {
      methods.add(pd.getReadMethod());
    }
    if (write) {
      methods.add(pd.getWriteMethod());
    }
  }
  methods.remove(null);
  return (Method[]) methods.toArray(new Method[methods.size()]);
}

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

/**
 * After each partition is parsed, we update the current metric totals with the total bytes
 * and number of records parsed. After all partitions have reported, we write the metric.
 */
public void record(TopicPartition partition, int bytes, int records) {
  this.unrecordedPartitions.remove(partition);
  this.fetchMetrics.increment(bytes, records);
  // collect and aggregate per-topic metrics
  String topic = partition.topic();
  FetchMetrics topicFetchMetric = this.topicFetchMetrics.get(topic);
  if (topicFetchMetric == null) {
    topicFetchMetric = new FetchMetrics();
    this.topicFetchMetrics.put(topic, topicFetchMetric);
  }
  topicFetchMetric.increment(bytes, records);
  if (this.unrecordedPartitions.isEmpty()) {
    // once all expected partitions from the fetch have reported in, record the metrics
    this.sensors.bytesFetched.record(this.fetchMetrics.fetchBytes);
    this.sensors.recordsFetched.record(this.fetchMetrics.fetchRecords);
    // also record per-topic metrics
    for (Map.Entry<String, FetchMetrics> entry: this.topicFetchMetrics.entrySet()) {
      FetchMetrics metric = entry.getValue();
      this.sensors.recordTopicFetchMetrics(entry.getKey(), metric.fetchBytes, metric.fetchRecords);
    }
  }
}

代码示例来源:origin: pxb1988/dex2jar

private void replacePhi(List<LabelStmt> phiLabels, Map<Local, Local> toReplace, Set<Value> set) {
  if (phiLabels != null) {
    for (LabelStmt labelStmt : phiLabels) {
      for (AssignStmt phi : labelStmt.phis) {
        Value[] ops = phi.getOp2().getOps();
        for (Value op : ops) {
          Value n = toReplace.get(op);
          if (n != null) {
            set.add(n);
          } else {
            set.add(op);
          }
        }
        set.remove(phi.getOp1());
        phi.getOp2().setOps(set.toArray(new Value[set.size()]));
        set.clear();
      }
    }
  }
}

代码示例来源:origin: codingapi/tx-lcn

@Override
public void removeAttachments(String groupId, String unitId) {
  GroupCache groupCache = transactionInfoMap.get(groupId);
  if (Objects.isNull(groupCache)) {
    return;
  }
  groupCache.getUnits().remove(unitId);
  if (groupCache.getUnits().size() == 0) {
    transactionInfoMap.remove(groupId);
  }
}

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

public void removePluginInterests(String pluginId) {
  for (String key : notificationNameToPluginsInterestedMap.keySet()) {
    if (notificationNameToPluginsInterestedMap.get(key).contains(pluginId)) {
      notificationNameToPluginsInterestedMap.get(key).remove(pluginId);
    }
  }
}

代码示例来源:origin: ben-manes/caffeine

/**
 * KeySet.remove removes an element
 */
public void testRemove() {
  Set full = populatedSet(3);
  full.remove(one);
  assertFalse(full.contains(one));
  assertEquals(2, full.size());
}

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

Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
 Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
 for (Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
  if (derivedFeatures.contains(entry.getKey())) {
   derivedFeatures.add(entry.getValue());
  }
 }
 if (derivedFeatures.remove(MultimapFeature.VALUE_COLLECTIONS_SUPPORT_ITERATOR_REMOVE)) {
  derivedFeatures.add(CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
 }
 if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
  derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
 }
 derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
 return derivedFeatures;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Callback after singleton creation.
 * <p>The default implementation marks the singleton as not in creation anymore.
 * @param beanName the name of the singleton that has been created
 * @see #isSingletonCurrentlyInCreation
 */
protected void afterSingletonCreation(String beanName) {
  if (!this.inCreationCheckExclusions.contains(beanName) && !this.singletonsCurrentlyInCreation.remove(beanName)) {
    throw new IllegalStateException("Singleton '" + beanName + "' isn't currently in creation");
  }
}

相关文章