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

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

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

HashSet.add介绍

[英]Adds the specified object to this HashSet if not already present.
[中]将指定的对象添加到此哈希集(如果尚未存在)。

代码示例

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

/**
 * Method that will add property name as one of properties that can
 * be ignored if not recognized.
 */
public void addIgnorable(String propName)
{
  if (_ignorableProps == null) {
    _ignorableProps = new HashSet<String>();
  }
  _ignorableProps.add(propName);
}

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

@Override
public Collection<Node> takeNodes(int nodesNeeded) {
  HashSet<Node> ret = new HashSet<>();
  Iterator<Node> it = _nodes.iterator();
  while (it.hasNext() && nodesNeeded > ret.size()) {
    Node n = it.next();
    ret.add(n);
    _totalSlots -= n.totalSlotsFree();
    it.remove();
  }
  return ret;
}

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

public Set<String> checkDupColumnNames(){
 HashSet<String> uniqueNames = new HashSet<String>();
 HashSet<String> conflictingNames = new HashSet<String>();
 if(_header){
  for(String n:_columnNames){
   if(!uniqueNames.contains(n)){
    uniqueNames.add(n);
   } else {
    conflictingNames.add(n);
   }
  }
 }
 return conflictingNames;
}
@Override public ParserSetup clone(){

代码示例来源:origin: oblac/jodd

/**
 * Counts profile properties. Note: this method is not
 * that easy on execution.
 */
public int countProfileProperties() {
  final HashSet<String> profileKeys = new HashSet<>();
  for (final Map<String, PropsEntry> map : profileProperties.values()) {
    for (final String key : map.keySet()) {
      if (!baseProperties.containsKey(key)) {
        profileKeys.add(key);
      }
    }
  }
  return profileKeys.size();
}

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

public static void addParameterizedSupertypes(TypeDecl t, HashSet processed, HashSet result) {
 if(!processed.contains(t)) {
  processed.add(t);
  if(t.isParameterizedType() /*&& !t.isRawType()*/)
   result.add(t);
  for(Iterator iter = directSupertypes(t).iterator(); iter.hasNext(); ) {
   TypeDecl typeDecl = (TypeDecl)iter.next();
   addParameterizedSupertypes(typeDecl, processed, result);
  }
 }
}

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

/**
 * generates randomly N distinct integers from 0 to Max.
 */
static int[] generateUniformHash(Random rand, int N, int Max) {
 if (N > Max)
  throw new RuntimeException("not possible");
 if (N > Max / 2) {
  return negate(generateUniformHash(rand, Max - N, Max), Max);
 }
 int[] ans = new int[N];
 HashSet<Integer> s = new HashSet<Integer>();
 while (s.size() < N)
  s.add(new Integer(rand.nextInt(Max)));
 Iterator<Integer> i = s.iterator();
 for (int k = 0; k < N; ++k)
  ans[k] = i.next().intValue();
 Arrays.sort(ans);
 return ans;
}

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

protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
  MultipartHttpServletRequest httpServletRequest = multipartResolver.resolveMultipart(request);
  Map<String, MultipartFile> map = httpServletRequest.getFileMap();
  MultipartFile multipartFile = map.values().iterator().next();
  receivedFiles.add(multipartFile.getOriginalFilename());
}

代码示例来源:origin: hamcrest/JavaHamcrest

@Override
  public Iterator<String> getPrefixes(String namespaceURI) {
    HashSet<String> prefixes = new HashSet<String>();
    String prefix = getPrefix(namespaceURI);
    if (prefix != null) {
      prefixes.add(prefix);
    }
    return prefixes.iterator();
  }
};

代码示例来源:origin: loklak/loklak_server

@Override
public boolean addQuery(String query, double score) {
  if (this.queryLimit > 0 && this.queries.size() > this.queryLimit)
    return false;
  if (queries.contains(query))
    return false;
  this.queries.add(query);
  return true;
}

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

private Command getRandomNode(HashSet<Command> seen) {
  while (true) {
    // 随机选择一个节点,但是不能跟前面选过的重复
    Command c = commands[random.nextInt(session.n)];
    if (seen.add(c)) {
      return c;
    }
    if (seen.size() == session.n)
      return null;
  }
}

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

private static <T> Set<T> collectIteratorToSet(Iterator<T> iterator) {
  HashSet<T> set = new HashSet<T>();
  for (; iterator.hasNext(); ) {
    T element = iterator.next();
    set.add(element);
  }
  return set;
}

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

private void validatePipelineUniqueness(ErrorCollection errors, String location) {
  HashSet<String> keys = new HashSet<>();
  for(String pipeline : pipelines)
  {
    String lowerCase = pipeline.toLowerCase();
    if(keys.contains(lowerCase))
      errors.addError(location,String.format(
          "Pipeline %s is defined more than once",pipeline));
    else
      keys.add(lowerCase);
  }
}

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

public String[] getPropertyGroups(String prefix) {
  Enumeration<?> keys = props.propertyNames();
  HashSet<String> groups = new HashSet<String>(10);
  if (!prefix.endsWith(".")) {
    prefix += ".";
  }
  while (keys.hasMoreElements()) {
    String key = (String) keys.nextElement();
    if (key.startsWith(prefix)) {
      String groupName = key.substring(prefix.length(), key.indexOf(
          '.', prefix.length()));
      groups.add(groupName);
    }
  }
  return (String[]) groups.toArray(new String[groups.size()]);
}

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

/**
 * Method that will add property name as one of properties that can
 * be ignored if not recognized.
 */
public void addIgnorable(String propName)
{
  if (_ignorableProps == null) {
    _ignorableProps = new HashSet<String>();
  }
  _ignorableProps.add(propName);
}

代码示例来源:origin: Tencent/tinker

@Override
  public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    String fieldDesc = className + ":" + name + ":" + desc;
    if (!refFieldSet.contains(fieldDesc)) {
      refFieldSet.add(fieldDesc);
      fieldCount++;
    }
    return super.visitField(access, name, desc, signature, value);
  }
};

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

private int getUniqueNodeCount(List<RebalanceTaskInfo> rebalanceInfoList,
                boolean isDonorBased) {
  HashSet<Integer> uniqueNodeSet = Sets.newHashSet();
  for(RebalanceTaskInfo partitionInfo: rebalanceInfoList) {
    int nodeId;
    if(isDonorBased) {
      nodeId = partitionInfo.getDonorId();
    } else {
      nodeId = partitionInfo.getStealerId();
    }
    if(!uniqueNodeSet.contains(nodeId)) {
      uniqueNodeSet.add(nodeId);
    }
  }
  return uniqueNodeSet.size();
}

代码示例来源:origin: naman14/Timber

@Override
  public void failure(RetrofitError error) {
    synchronized (sLock) {
      isUploading = false;
      //Max 500 scrobbles in Cache
      if (newquery != null && queries.size() <= 500)
        queries.add(newquery.toString());
      if (cachedirty)
        save();
    }
  }
});

代码示例来源:origin: facebook/stetho

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void putStringSet(
  SharedPreferences.Editor editor,
  String key,
  Iterator<String> remainingArgs) {
 HashSet<String> set = new HashSet<String>();
 while (remainingArgs.hasNext()) {
  set.add(remainingArgs.next());
 }
 editor.putStringSet(key, set);
}

相关文章