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")); }
private static Set<Feature<?>> computeKeySetFeatures(Set<Feature<?>> mapFeatures) { Set<Feature<?>> keySetFeatures = computeCommonDerivedCollectionFeatures(mapFeatures); // TODO(lowasser): make this trigger only if the map is a submap // currently, the KeySetGenerator won't work properly for a subset of a keyset of a submap keySetFeatures.add(CollectionFeature.SUBSET_VIEW); if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) { keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES); } else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) { keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES); } return keySetFeatures; }
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; }
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; }
public void testNewIdentityHashSet() { Set<Integer> set = Sets.newIdentityHashSet(); Integer value1 = new Integer(12357); Integer value2 = new Integer(12357); assertTrue(set.add(value1)); assertFalse(set.contains(value2)); assertTrue(set.contains(value1)); assertTrue(set.add(value2)); assertEquals(2, set.size()); }
static <K, V> Iterator<Entry<K, V>> asMapEntryIterator( Set<K> set, final Function<? super K, V> function) { return new TransformedIterator<K, Entry<K, V>>(set.iterator()) { @Override Entry<K, V> transform(final K key) { return immutableEntry(key, function.apply(key)); } }; }
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) { assertTrue(multiset.isEmpty()); assertEquals(0, multiset.size()); assertEquals(0, multiset.toArray().length); assertTrue(multiset.entrySet().isEmpty()); assertFalse(multiset.iterator().hasNext()); assertEquals(0, multiset.entrySet().size()); assertEquals(0, multiset.entrySet().toArray().length); assertFalse(multiset.entrySet().iterator().hasNext()); }
static Set<Feature<?>> computeElementSetFeatures(Set<Feature<?>> features) { Set<Feature<?>> derivedFeatures = new HashSet<>(); derivedFeatures.addAll(features); derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE); derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD); if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) { derivedFeatures.remove(CollectionFeature.SERIALIZABLE); } return derivedFeatures; }
/** * Return whether the given profile is active, or if active profiles are empty * whether the profile should be active by default. * @throws IllegalArgumentException per {@link #validateProfile(String)} */ protected boolean isProfileActive(String profile) { validateProfile(profile); Set<String> currentActiveProfiles = doGetActiveProfiles(); return (currentActiveProfiles.contains(profile) || (currentActiveProfiles.isEmpty() && doGetDefaultProfiles().contains(profile))); }
@CollectionSize.Require(ONE) @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) public void testEntrySetIteratorRemove() { Set<Entry<K, V>> entrySet = getMap().entrySet(); Iterator<Entry<K, V>> entryItr = entrySet.iterator(); assertEquals(e0(), entryItr.next()); entryItr.remove(); assertTrue(getMap().isEmpty()); assertFalse(entrySet.contains(e0())); }
/** * return true when globalMutex hold the reference of writerLock */ private boolean doesWriterOwnThisLock() { return globalMutex.contains(writerLock); }
@Override public @Nullable E edgeConnectingOrNull(N nodeU, N nodeV) { Set<E> edgesConnecting = edgesConnecting(nodeU, nodeV); switch (edgesConnecting.size()) { case 0: return null; case 1: return edgesConnecting.iterator().next(); default: throw new IllegalArgumentException(String.format(MULTIPLE_EDGES_CONNECTING, nodeU, nodeV)); } }
private static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) { Set<Annotation> result = null; for (Annotation annotation : annotations) { if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) { if (result == null) result = new LinkedHashSet<>(); result.add(annotation); } } return result != null ? unmodifiableSet(result) : Collections.<Annotation>emptySet(); } }