java.util.HashSet.contains()方法的使用及代码示例

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

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

HashSet.contains介绍

[英]Searches this HashSet for the specified object.
[中]在该哈希集中搜索指定的对象。

代码示例

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

private static void addNamedGroups(Pattern pattern, HashSet<String> variables)
{
  Matcher matcher = NAMED_GROUPS_PATTERN.matcher(pattern.toString());
  while (matcher.find()) {
    String name = matcher.group(1);
    checkArgument(!variables.contains(name), "Multiple definitions found for variable ${" + name + "}");
    variables.add(name);
  }
}

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

public StringValidator(Map<String, Object> params) {
  this.acceptedValues =
    new HashSet<String>(Arrays.asList((String[]) params.get(ConfigValidationAnnotations.ValidatorParams.ACCEPTED_VALUES)));
  if (this.acceptedValues.isEmpty() || (this.acceptedValues.size() == 1 && this.acceptedValues.contains(""))) {
    this.acceptedValues = null;
  }
}

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

@Override
protected int act(List<Run<?, ?>> builds) throws IOException {
  job.checkPermission(Run.DELETE);
  final HashSet<Integer> hsBuilds = new HashSet<>();
  for (Run<?, ?> build : builds) {
    if (!hsBuilds.contains(build.number)) {
      build.delete();
      hsBuilds.add(build.number);
    }
  }
  stdout.println("Deleted "+hsBuilds.size()+" builds");
  return 0;
}

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

@Override
public Collection<Node> takeNodes(int nodesNeeded) {
  LOG.debug("Taking {} from {}", nodesNeeded, this);
  HashSet<Node> ret = new HashSet<>();
  for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) {
    if (!_isolated.contains(entry.getKey())) {
      Iterator<Node> it = entry.getValue().iterator();
      while (it.hasNext()) {
        if (nodesNeeded <= 0) {
          return ret;
        }
        Node n = it.next();
        it.remove();
        n.freeAllSlots(_cluster);
        ret.add(n);
        nodesNeeded--;
        _usedNodes--;
      }
    }
  }
  return ret;
}

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

private static void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) {
 LinkedList<DirectNode> stackNode = new LinkedList<>();
 LinkedList<Integer> stackIndex = new LinkedList<>();
 HashSet<DirectNode> setVisited = new HashSet<>();
 stackNode.add(root);
 stackIndex.add(0);
 while (!stackNode.isEmpty()) {
  DirectNode node = stackNode.getLast();
  int index = stackIndex.removeLast();
  setVisited.add(node);
  for (; index < node.succs.size(); index++) {
   DirectNode succ = node.succs.get(index);
   if (!setVisited.contains(succ)) {
    stackIndex.add(index + 1);
    stackNode.add(succ);
    stackIndex.add(0);
    break;
   }
  }
  if (index == node.succs.size()) {
   lst.add(0, node);
   stackNode.removeLast();
  }
 }
}

代码示例来源:origin: h2oai/h2o-3

/**
 * Get the non-ignored columns that are not in the filter; do not include the response.
 * @param filterThese remove these columns
 * @return an int[] of the non-ignored column indexes
 */
public int[] diffCols(int[] filterThese) {
 HashSet<Integer> filter = new HashSet<>();
 for(int i:filterThese)filter.add(i);
 ArrayList<Integer> res = new ArrayList<>();
 for(int i=0;i<_cols.length;++i) {
  if( _cols[i]._ignored || _cols[i]._response || filter.contains(i) ) continue;
  res.add(i);
 }
 return intListToA(res);
}

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

HashSet<Node> addedNodes = new HashSet<Node>();
for (Node node : startNodes) {
 addedNodes.add(node);
     (Operator<? extends OperatorDesc>) child;
   if (!addedNodes.contains(child) &&
     (childOP.getParentOperators() == null ||
     addedNodes.containsAll(childOP.getParentOperators()))) {
    toWalk.add(child);
    addedNodes.add(child);
 if (!nodeTypes.isEmpty() && !nodeTypes.contains(nd.getClass())) {
  continue;

代码示例来源:origin: hibernate/hibernate-orm

private static void appendTokens(StringBuilder buf, Iterator iter) {
  boolean lastSpaceable = true;
  boolean lastQuoted = false;
  while ( iter.hasNext() ) {
    String token = (String) iter.next();
    boolean spaceable = !DONT_SPACE_TOKENS.contains( token );
    boolean quoted = token.startsWith( "'" );
    if ( spaceable && lastSpaceable ) {
      if ( !quoted || !lastQuoted ) {
        buf.append( ' ' );
      }
    }
    lastSpaceable = spaceable;
    buf.append( token );
    lastQuoted = token.endsWith( "'" );
  }
}

代码示例来源:origin: alipay/sofa-rpc

for (String filterAlias : filterAliases) {
    if (startsWithExcludePrefix(filterAlias)) { // 排除用的特殊字符
      excludes.add(filterAlias.substring(1));
    } else {
      ExtensionClass<Filter> filter = EXTENSION_LOADER.getExtensionClass(filterAlias);
      if (filter != null) {
        extensionFilters.add(filter);
if (!excludes.contains(StringUtils.ALL) && !excludes.contains(StringUtils.DEFAULT)) { // 配了-*和-default表示不加载内置
  for (Map.Entry<String, ExtensionClass<Filter>> entry : autoActiveFilters.entrySet()) {
    if (!excludes.contains(entry.getKey())) {
      extensionFilters.add(entry.getValue());
  actualFilters.add(extensionFilter.getExtInstance());

代码示例来源:origin: scouter-project/scouter

private void add(String objName, ObjectName mbean, String type, byte decimal, String attrName, String counterName) {
  if (errors.contains(attrName))
    return;
  MBeanObj cObj = new MBeanObj(objName, mbean, type, ValueEnum.DECIMAL, attrName, counterName);
  beanList.add(cObj);
}

代码示例来源:origin: medcl/elasticsearch-analysis-pinyin

void addCandidate(TermItem item) {
  String term = item.term;
  if (config.lowercase) {
    term = term.toLowerCase();
  }
  if (config.trimWhitespace) {
    term = term.trim();
  }
  item.term = term;
  if (term.length() == 0) {
    return;
  }
  //remove same term with same position
  String fr=term+item.position;
  //remove same term, regardless position
  if (config.removeDuplicateTerm) {
    fr=term;
  }
  if (termsFilter.contains(fr)) {
    return;
  }
  termsFilter.add(fr);
  candidate.add(item);
}

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

/**
 * Returns a new list containing all elements that are contained in
 * both given lists.
 *
 * @param <E> the element type
 * @param list1  the first list
 * @param list2  the second list
 * @return  the intersection of those two lists
 * @throws NullPointerException if either list is null
 */
public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) {
  final List<E> result = new ArrayList<>();
  List<? extends E> smaller = list1;
  List<? extends E> larger = list2;
  if (list1.size() > list2.size()) {
    smaller = list2;
    larger = list1;
  }
  final HashSet<E> hashSet = new HashSet<>(smaller);
  for (final E e : larger) {
    if (hashSet.contains(e)) {
      result.add(e);
      hashSet.remove(e);
    }
  }
  return result;
}

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

protected List<Integer> getBucketColIDs(List<String> bucketCols, List<FieldSchema> cols) {
 ArrayList<Integer> result = new ArrayList<>(bucketCols.size());
 HashSet<String> bucketSet = new HashSet<>(bucketCols);
 for (int i = 0; i < cols.size(); i++) {
  if (bucketSet.contains(cols.get(i).getName())) {
   result.add(i);
  }
 }
 return result;
}

代码示例来源:origin: medcl/elasticsearch-analysis-pinyin

void addCandidate(TermItem item) {
  String term = item.term;
  if (config.lowercase) {
    term = term.toLowerCase();
  }
  if (config.trimWhitespace) {
    term = term.trim();
  }
  item.term = term;
  if (term.length() == 0) {
    return;
  }
  //remove same term with same position
  String fr=term+item.position;
  //remove same term, regardless position
  if (config.removeDuplicateTerm) {
     fr=term;
  }
  if (termsFilter.contains(fr)) {
    return;
  }
  termsFilter.add(fr);
  candidate.add(item);
}

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

@Override
public Collection<Node> takeNodes(int nodesNeeded) {
  LOG.debug("Taking {} from {}", nodesNeeded, this);
  HashSet<Node> ret = new HashSet<>();
  for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) {
    if (!_isolated.contains(entry.getKey())) {
      Iterator<Node> it = entry.getValue().iterator();
      while (it.hasNext()) {
        if (nodesNeeded <= 0) {
          return ret;
        }
        Node n = it.next();
        it.remove();
        n.freeAllSlots(_cluster);
        ret.add(n);
        nodesNeeded--;
        _usedNodes--;
      }
    }
  }
  return ret;
}

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

/**
 * Takes in a collection of executions belonging to the same process instance. Orders the executions in a list, first elements are the leaf, last element is the root elements.
 */
public static List<ExecutionEntity> orderFromRootToLeaf(Collection<ExecutionEntity> executions) {
 List<ExecutionEntity> orderedList = new ArrayList<ExecutionEntity>(executions.size());
 // Root elements
 HashSet<String> previousIds = new HashSet<String>();
 for (ExecutionEntity execution : executions) {
  if (execution.getParentId() == null) {
   orderedList.add(execution);
   previousIds.add(execution.getId());
  }
 }
 // Non-root elements
 while (orderedList.size() < executions.size()) {
  for (ExecutionEntity execution : executions) {
   if (!previousIds.contains(execution.getId()) && previousIds.contains(execution.getParentId())) {
    orderedList.add(execution);
    previousIds.add(execution.getId());
   }
  }
 }
 return orderedList;
}

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

public ReplyToAddresses getRecipientsToReplyAllTo(Message message, Account account) {
  List<Address> replyToAddresses = Arrays.asList(getRecipientsToReplyTo(message, account).to);
  HashSet<Address> alreadyAddedAddresses = new HashSet<>(replyToAddresses);
  ArrayList<Address> toAddresses = new ArrayList<>(replyToAddresses);
  ArrayList<Address> ccAddresses = new ArrayList<>();
  for (Address address : message.getFrom()) {
    if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
      toAddresses.add(address);
      alreadyAddedAddresses.add(address);
    }
  }
  for (Address address : message.getRecipients(RecipientType.TO)) {
    if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
      toAddresses.add(address);
      alreadyAddedAddresses.add(address);
    }
  }
  for (Address address : message.getRecipients(RecipientType.CC)) {
    if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
      ccAddresses.add(address);
      alreadyAddedAddresses.add(address);
    }
  }
  return new ReplyToAddresses(toAddresses, ccAddresses);
}

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

HashSet<Node> addedNodes = new HashSet<Node>();
for (Node node : startNodes) {
 addedNodes.add(node);
     (Operator<? extends OperatorDesc>) child;
   if (!addedNodes.contains(child) &&
     (childOP.getParentOperators() == null ||
     addedNodes.containsAll(childOP.getParentOperators()))) {
    toWalk.add(child);
    addedNodes.add(child);
 if (!nodeTypes.isEmpty() && !nodeTypes.contains(nd.getClass())) {
  continue;

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

public Map<Attribute, Object> getAttributes() {
  Map<Attribute, Object> result = new HashMap<Attribute, Object>(
      (attrString.attributeMap.size() * 4 / 3) + 1);
  Iterator<Map.Entry<Attribute, List<Range>>> it = attrString.attributeMap
      .entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry<Attribute, List<Range>> entry = it.next();
    if (attributesAllowed == null
        || attributesAllowed.contains(entry.getKey())) {
      Object value = currentValue(entry.getValue());
      if (value != null) {
        result.put(entry.getKey(), value);
      }
    }
  }
  return result;
}

代码示例来源:origin: alipay/sofa-rpc

for (String routerAlias : routerAliases) {
    if (startsWithExcludePrefix(routerAlias)) { // 排除用的特殊字符
      excludes.add(routerAlias.substring(1));
    } else {
      extensionRouters.add(EXTENSION_LOADER.getExtensionClass(routerAlias));
if (!excludes.contains(StringUtils.ALL) && !excludes.contains(StringUtils.DEFAULT)) { // 配了-*和-default表示不加载内置
  for (Map.Entry<String, ExtensionClass<Router>> entry : CONSUMER_AUTO_ACTIVES.entrySet()) {
    if (!excludes.contains(entry.getKey())) {
      extensionRouters.add(entry.getValue());
for (ExtensionClass<Router> extensionRouter : extensionRouters) {
  Router actualRoute = extensionRouter.getExtInstance();
  actualRouters.add(actualRoute);

相关文章