Tabnine Logo
Set.add
Code IndexAdd Tabnine to your IDE (free)

How to use
add
method
in
java.util.Set

Best Java code snippets using java.util.Set.add (Showing top 20 results out of 207,927)

Refine searchRefine arrow

  • Set.contains
  • Map.get
  • Map.put
  • Set.size
  • List.add
  • List.size
  • Map.containsKey
canonical example by Tabnine

private void mappingWordsLength(List<String> wordsList) {
 Map<Integer, Set<String>> mapping = new HashMap<>();
 for (String word : wordsList) {
  mapping.computeIfAbsent(word.length(), HashSet::new).add(word);
 }
 List<Integer> lengths = new LinkedList<>(mapping.keySet());
 Collections.sort(lengths);
 lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars"));
}
origin: google/guava

private static Set<Feature<?>> computeValuesSetFeatures(Set<Feature<?>> mapFeatures) {
 Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
 valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
 if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
  valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
 }
 valuesCollectionFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
 return valuesCollectionFeatures;
}
origin: square/okhttp

public BasicCertificateChainCleaner(X509Certificate... caCerts) {
 subjectToCaCerts = new LinkedHashMap<>();
 for (X509Certificate caCert : caCerts) {
  X500Principal subject = caCert.getSubjectX500Principal();
  Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(subject);
  if (subjectCaCerts == null) {
   subjectCaCerts = new LinkedHashSet<>(1);
   subjectToCaCerts.put(subject, subjectCaCerts);
  }
  subjectCaCerts.add(caCert);
 }
}
origin: spring-projects/spring-framework

private void addToClassHierarchy(int index, Class<?> type, boolean asArray,
    List<Class<?>> hierarchy, Set<Class<?>> visited) {
  if (asArray) {
    type = Array.newInstance(type, 0).getClass();
  }
  if (visited.add(type)) {
    hierarchy.add(index, type);
  }
}
origin: ctripcorp/apollo

/**
 * Delete existed property
 */
public void deleteProperty(String namespace, String someKey) {
 if (deletedKeysOfNamespace.containsKey(namespace)) {
  deletedKeysOfNamespace.get(namespace).add(someKey);
 } else {
  deletedKeysOfNamespace.put(namespace, ImmutableSet.of(someKey));
 }
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void setCollectionPropertyWithArrayValue() {
  IndexedTestBean target = new IndexedTestBean();
  AbstractPropertyAccessor accessor = createAccessor(target);
  Collection<String> coll = new HashSet<>();
  coll.add("coll1");
  accessor.setPropertyValue("collection", coll.toArray());
  List<String> set = new LinkedList<>();
  set.add("set1");
  accessor.setPropertyValue("set", set.toArray());
  List<String> sortedSet = new ArrayList<>();
  sortedSet.add("sortedSet1");
  accessor.setPropertyValue("sortedSet", sortedSet.toArray());
  Set<String> list = new HashSet<>();
  list.add("list1");
  accessor.setPropertyValue("list", list.toArray());
  assertEquals(1, target.getCollection().size());
  assertTrue(target.getCollection().containsAll(coll));
  assertEquals(1, target.getSet().size());
  assertTrue(target.getSet().containsAll(set));
  assertEquals(1, target.getSortedSet().size());
  assertTrue(target.getSortedSet().containsAll(sortedSet));
  assertEquals(1, target.getList().size());
  assertTrue(target.getList().containsAll(list));
}
origin: apache/storm

public static List<String> getRepeat(List<String> list) {
  List<String> rtn = new ArrayList<String>();
  Set<String> idSet = new HashSet<String>();
  for (String id : list) {
    if (idSet.contains(id)) {
      rtn.add(id);
    } else {
      idSet.add(id);
    }
  }
  return rtn;
}
origin: spring-projects/spring-framework

Enumeration<String> parameterEnum = request.getParameterNames();
while (parameterEnum.hasMoreElements()) {
  parameterNames.add(parameterEnum.nextElement());
assertEquals(3, parameterNames.size());
assertTrue(parameterNames.contains("field3"));
assertTrue(parameterNames.contains("field4"));
assertTrue(parameterNames.contains("getField"));
assertEquals("value3", request.getParameter("field3"));
List<String> parameterValues = Arrays.asList(request.getParameterValues("field3"));
assertEquals(1, parameterValues.size());
assertTrue(parameterValues.contains("value3"));
assertEquals("value4", request.getParameter("field4"));
parameterValues = Arrays.asList(request.getParameterValues("field4"));
assertEquals(2, parameterValues.size());
assertTrue(parameterValues.contains("value4"));
assertTrue(parameterValues.contains("value5"));
for (Object o : request.getParameterMap().keySet()) {
  String key = (String) o;
  parameterMapKeys.add(key);
  parameterMapValues.add(request.getParameterMap().get(key));
assertEquals(3, parameterMapKeys.size());
assertEquals(3, parameterMapValues.size());
int field3Index = parameterMapKeys.indexOf("field3");
origin: google/guava

 @Override
 public Iterable<Entry<E>> order(List<Entry<E>> insertionOrder) {
  // We mimic the order from gen.
  Map<E, Entry<E>> map = new LinkedHashMap<>();
  for (Entry<E> entry : insertionOrder) {
   map.put(entry.getElement(), entry);
  }
  Set<E> seen = new HashSet<>();
  List<Entry<E>> order = new ArrayList<>();
  for (E e : gen.order(new ArrayList<E>(map.keySet()))) {
   if (seen.add(e)) {
    order.add(map.get(e));
   }
  }
  return order;
 }
}
origin: stanfordnlp/CoreNLP

protected void updateKeys(Set<Iterable<K>> keys, List<K> prefix) {
 if (children != null) {
  for (Entry<K, TrieMap<K, V>> kTrieMapEntry : children.entrySet()) {
   List<K> p = new ArrayList<>(prefix.size() + 1);
   p.addAll(prefix);
   p.add(kTrieMapEntry.getKey());
   kTrieMapEntry.getValue().updateKeys(keys, p);
  }
 }
 if (value != null) {
  keys.add(prefix);
 }
}
origin: stanfordnlp/CoreNLP

private static List<Sieve.MentionData> eliminateDuplicates(List<Sieve.MentionData> mentionCandidates)
{
 List<Sieve.MentionData> newList = new ArrayList<>();
 Set<String> seenText = new HashSet<>();
 for(int i = 0; i < mentionCandidates.size(); i++)
 {
  Sieve.MentionData mentionCandidate = mentionCandidates.get(i);
  String text = mentionCandidate.text;
  if(!seenText.contains(text) || mentionCandidate.type.equals("Pronoun"))
   newList.add(mentionCandidate);
  seenText.add(text);
 }
 return newList;
}
origin: spring-projects/spring-framework

public Collection<SourceClass> getAnnotationAttributes(String annType, String attribute) throws IOException {
  Map<String, Object> annotationAttributes = this.metadata.getAnnotationAttributes(annType, true);
  if (annotationAttributes == null || !annotationAttributes.containsKey(attribute)) {
    return Collections.emptySet();
  }
  String[] classNames = (String[]) annotationAttributes.get(attribute);
  Set<SourceClass> result = new LinkedHashSet<>();
  for (String className : classNames) {
    result.add(getRelated(className));
  }
  return result;
}
origin: skylot/jadx

/**
 * @return true if this value is duplicated
 */
public boolean put(Object value, FieldNode fld) {
  FieldNode prev = values.put(value, fld);
  if (prev != null) {
    values.remove(value);
    duplicates.add(value);
    return true;
  }
  if (duplicates.contains(value)) {
    values.remove(value);
    return true;
  }
  return false;
}
origin: org.testng/testng

private static List<ITestNGMethod> retrieve(Set<String> tracker, Map<String, List<ITestNGMethod>> map, String group) {
 if (tracker.contains(group)) {
  return Collections.EMPTY_LIST;
 }
 tracker.add(group);
 return map.get(group);
}
origin: hankcs/HanLP

private List<Set<K>> toResult(List<Cluster<K>> clusters_)
{
  List<Set<K>> result = new ArrayList<Set<K>>(clusters_.size());
  for (Cluster<K> c : clusters_)
  {
    Set<K> s = new HashSet<K>();
    for (Document<K> d : c.documents_)
    {
      s.add(d.id_);
    }
    result.add(s);
  }
  return result;
}
origin: spring-projects/spring-framework

if (valuesAlreadyReplaced.contains(attributeOverrideName)) {
  continue;
targetAttributeNames.add(attributeOverrideName);
valuesAlreadyReplaced.add(attributeOverrideName);
List<String> aliases = AnnotationUtils.getAttributeAliasMap(targetAnnotationType).get(attributeOverrideName);
if (aliases != null) {
  for (String alias : aliases) {
    if (!valuesAlreadyReplaced.contains(alias)) {
      targetAttributeNames.add(alias);
      valuesAlreadyReplaced.add(alias);
origin: apache/incubator-dubbo

private Set<String> resolvePackagesToScan(Set<String> packagesToScan) {
  Set<String> resolvedPackagesToScan = new LinkedHashSet<String>(packagesToScan.size());
  for (String packageToScan : packagesToScan) {
    if (StringUtils.hasText(packageToScan)) {
      String resolvedPackageToScan = environment.resolvePlaceholders(packageToScan.trim());
      resolvedPackagesToScan.add(resolvedPackageToScan);
    }
  }
  return resolvedPackagesToScan;
}
origin: spring-projects/spring-framework

/**
 * Add the given singleton factory for building the specified singleton
 * if necessary.
 * <p>To be called for eager registration of singletons, e.g. to be able to
 * resolve circular references.
 * @param beanName the name of the bean
 * @param singletonFactory the factory for the singleton object
 */
protected void addSingletonFactory(String beanName, ObjectFactory<?> singletonFactory) {
  Assert.notNull(singletonFactory, "Singleton factory must not be null");
  synchronized (this.singletonObjects) {
    if (!this.singletonObjects.containsKey(beanName)) {
      this.singletonFactories.put(beanName, singletonFactory);
      this.earlySingletonObjects.remove(beanName);
      this.registeredSingletons.add(beanName);
    }
  }
}
origin: google/guava

@Override
public Map<K, Collection<V>> create(Object... elements) {
 Set<K> keySet = new HashSet<>();
 List<Entry<K, V>> builder = new ArrayList<>();
 for (Object o : elements) {
  Entry<K, Collection<V>> entry = (Entry<K, Collection<V>>) o;
  keySet.add(entry.getKey());
  for (V v : entry.getValue()) {
   builder.add(mapEntry(entry.getKey(), v));
  }
 }
 checkArgument(keySet.size() == elements.length, "Duplicate keys");
 return multimapGenerator.create(builder.toArray()).asMap();
}
origin: spring-projects/spring-framework

/**
 * Add the given singleton object to the singleton cache of this factory.
 * <p>To be called for eager registration of singletons.
 * @param beanName the name of the bean
 * @param singletonObject the singleton object
 */
protected void addSingleton(String beanName, Object singletonObject) {
  synchronized (this.singletonObjects) {
    this.singletonObjects.put(beanName, singletonObject);
    this.singletonFactories.remove(beanName);
    this.earlySingletonObjects.remove(beanName);
    this.registeredSingletons.add(beanName);
  }
}
java.utilSetadd

Javadoc

Adds the specified object to this set. The set is not modified if it already contains the object.

Popular methods of Set

  • contains
    Returns true if this set contains the specified element. More formally, returns true if and only if
  • iterator
    Returns an iterator over the elements in this set. The elements are returned in no particular order
  • size
  • isEmpty
    Returns true if this set contains no elements.
  • addAll
    Adds all of the elements in the specified collection to this set if they're not already present (opt
  • remove
    Removes the specified element from this set if it is present (optional operation). More formally, re
  • toArray
    Returns an array containing all of the elements in this set; the runtime type of the returned array
  • stream
  • clear
    Removes all of the elements from this set (optional operation). The set will be empty after this cal
  • removeAll
    Removes from this set all of its elements that are contained in the specified collection (optional o
  • forEach
  • equals
    Compares the specified object with this set for equality. Returnstrue if the specified object is als
  • forEach,
  • equals,
  • containsAll,
  • retainAll,
  • hashCode,
  • removeIf,
  • parallelStream,
  • spliterator,
  • of

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • setContentView (Activity)
  • getSharedPreferences (Context)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now