@Override public boolean isEmpty() { return size() == 0; }
@Override public int size() { return 1 << inputSet.size(); }
@Override public int size() { return map.size(); }
@Override public int size() { return keyIndex.size(); }
@Override public int size() { return map.size(); }
@Override public int size() { return map().size(); }
@Override public int size() { return map.size(); }
@Override public int hashCode() { /* * The sum of the sums of the hash codes in each subset is just the sum of * each input element's hash code times the number of sets that element * appears in. Each element appears in exactly half of the 2^n sets, so: */ return inputSet.keySet().hashCode() << (inputSet.size() - 1); }
@Override public int size() { return IntMath.binomial(index.size(), size); }
@Override public int size() { return map().size(); }
private boolean isFull() { return size == keyToIndex().size(); }
@Override UnmodifiableIterator<Entry<K, V>> entryIterator() { return new AbstractIterator<Entry<K, V>>() { private int index = -1; private final int maxIndex = keyToIndex().size(); @Override protected Entry<K, V> computeNext() { for (index++; index < maxIndex; index++) { V value = getValue(index); if (value != null) { return Maps.immutableEntry(getKey(index), value); } } return endOfData(); } }; } }
public void testAllHashFunctionsHaveKnownHashes() throws Exception { // The following legacy hashing function methods have been covered by unit testing already. List<String> legacyHashingMethodNames = ImmutableList.of("murmur2_64", "fprint96"); for (Method method : Hashing.class.getDeclaredMethods()) { if (method.getReturnType().equals(HashFunction.class) // must return HashFunction && Modifier.isPublic(method.getModifiers()) // only the public methods && method.getParameterTypes().length == 0 // only the seed-less grapes^W hash functions && !legacyHashingMethodNames.contains(method.getName())) { HashFunction hashFunction = (HashFunction) method.invoke(Hashing.class); assertTrue( "There should be at least 3 entries in KNOWN_HASHES for " + hashFunction, KNOWN_HASHES.row(hashFunction).size() >= 3); } } }
/** * Returns a multimap view of the map. * * @since 14.0 */ public ImmutableSetMultimap<K, V> asMultimap() { if (isEmpty()) { return ImmutableSetMultimap.of(); } ImmutableSetMultimap<K, V> result = multimapView; return (result == null) ? (multimapView = new ImmutableSetMultimap<>(new MapViewOfValuesAsSingletonSets(), size(), null)) : result; }
public void testAsMultimapCaches() { ImmutableMap<String, Integer> map = ImmutableMap.of("one", 1); ImmutableSetMultimap<String, Integer> multimap1 = map.asMultimap(); ImmutableSetMultimap<String, Integer> multimap2 = map.asMultimap(); assertEquals(1, multimap1.asMap().size()); assertSame(multimap1, multimap2); }
public void testServiceStartupTimes() { Service a = new NoOpDelayedService(150); Service b = new NoOpDelayedService(353); ServiceManager serviceManager = new ServiceManager(asList(a, b)); serviceManager.startAsync().awaitHealthy(); ImmutableMap<Service, Long> startupTimes = serviceManager.startupTimes(); assertEquals(2, startupTimes.size()); // TODO(kak): Use assertThat(startupTimes.get(a)).isAtLeast(150); assertTrue(startupTimes.get(a) >= 150); // TODO(kak): Use assertThat(startupTimes.get(b)).isAtLeast(353); assertTrue(startupTimes.get(b) >= 353); }
segment.count = originalCount; ImmutableMap<Object, Object> originalMap = ImmutableMap.copyOf(map); assertEquals(originalCount, originalMap.size()); assertEquals(originalMap, map);
segment.count = originalCount; ImmutableMap<Object, Object> originalMap = ImmutableMap.copyOf(map); assertEquals(originalCount, originalMap.size()); assertEquals(originalMap, map);