/** * A sensible definition of {@link #isEmpty} in terms of the {@code iterator} method of {@link * #entrySet}. If you override {@link #entrySet}, you may wish to override {@link #isEmpty} to * forward to this implementation. * * @since 7.0 */ protected boolean standardIsEmpty() { return !entrySet().iterator().hasNext(); }
/** * Called after {@link #successorIterator} is exhausted. Advances {@link #node} to the next node * and updates {@link #successorIterator} to iterate through the successors of {@link #node}. */ protected final boolean advance() { checkState(!successorIterator.hasNext()); if (!nodeIterator.hasNext()) { return false; } node = nodeIterator.next(); successorIterator = graph.successors(node).iterator(); return true; }
@Override public void testRunFinished(Result result) throws Exception { Thread.setDefaultUncaughtExceptionHandler(oldDefaultUncaughtExceptionHandler); System.err.println("Uninstalled aggressive uncaught exception handler"); synchronized (exceptions) { if (!exceptions.isEmpty()) { throw Throwables.rethrowAsException(exceptions.keySet().iterator().next()); } } } }
@Override public String toString() { Iterator<Map.Entry<String, Object>> entries = entrySet().iterator(); StringBuilder sb = new StringBuilder("{"); while (entries.hasNext()) { Map.Entry<String, Object> entry = entries.next(); sb.append(entry.getKey()); sb.append('='); sb.append(valueToString(entry.getValue())); sb.append(entries.hasNext() ? ", " : ""); } sb.append("}"); return sb.toString(); }
static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) { if (map instanceof EnumBiMap) { return ((EnumBiMap<K, ?>) map).keyType(); } if (map instanceof EnumHashBiMap) { return ((EnumHashBiMap<K, ?>) map).keyType(); } checkArgument(!map.isEmpty()); return map.keySet().iterator().next().getDeclaringClass(); }
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()); }
public void testEntrySetSetValueSameValue() { // TODO: Investigate the extent to which, in practice, maps that support // put() also support Entry.setValue(). if (!supportsPut) { return; } final Map<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } Set<Entry<K, V>> entrySet = map.entrySet(); Entry<K, V> entry = entrySet.iterator().next(); final V oldValue = entry.getValue(); final V returnedValue = entry.setValue(oldValue); assertEquals(oldValue, returnedValue); assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue))); assertEquals(oldValue, map.get(entry.getKey())); assertInvariants(map); }
@MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE}) @CollectionSize.Require(SEVERAL) public void testRemovePresentConcurrentWithKeySetIteration() { try { Iterator<K> iterator = getMap().keySet().iterator(); getMap().remove(k0()); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }