void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
@GuardedBy("monitor") void checkHealthy() { if (states.count(RUNNING) != numberOfServices) { IllegalStateException exception = new IllegalStateException( "Expected to be healthy after starting. The following services are not running: " + Multimaps.filterKeys(servicesByState, not(equalTo(RUNNING)))); for (Service service : servicesByState.get(State.FAILED)) { exception.addSuppressed(new FailedService(service)); } throw exception; } } }
@Override ListMultimap<String, Integer> filter(ListMultimap<String, Integer> multimap) { multimap.put("foo", 17); multimap.put("bar", 32); multimap.put("foo", 16); multimap = Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo"))); return Multimaps.filterKeys( multimap, Predicates.not(Predicates.equalTo("bar"))); } })
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
@Override ListMultimap<String, Integer> filter(ListMultimap<String, Integer> multimap) { multimap.put("foo", 17); multimap.put("bar", 32); multimap.put("foo", 16); return Multimaps.filterKeys( multimap, Predicates.not(Predicates.in(ImmutableSet.of("foo", "bar")))); } })
@GuardedBy("monitor") void checkHealthy() { if (states.count(RUNNING) != numberOfServices) { IllegalStateException exception = new IllegalStateException( "Expected to be healthy after starting. The following services are not running: " + Multimaps.filterKeys(servicesByState, not(equalTo(RUNNING)))); throw exception; } } }
@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { multimap.put("foo", 17); multimap.put("bar", 32); multimap.put("foo", 16); return Multimaps.filterKeys( multimap, Predicates.not(Predicates.in(ImmutableSet.of("foo", "bar")))); } })
void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { ImmutableSetMultimap<String, Integer> badEntries = ImmutableSetMultimap.of("foo", 314, "bar", 358); multimap.putAll(badEntries); multimap = Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo"))); multimap = Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("bar"))); return multimap; } })
Multimap<K, V> unfiltered, final Predicate<? super K> keyPredicate) { if (unfiltered instanceof SetMultimap) { return filterKeys((SetMultimap<K, V>) unfiltered, keyPredicate); } else if (unfiltered instanceof ListMultimap) { return filterKeys((ListMultimap<K, V>) unfiltered, keyPredicate); } else if (unfiltered instanceof FilteredKeyMultimap) { FilteredKeyMultimap<K, V> prev = (FilteredKeyMultimap<K, V>) unfiltered;
void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { ImmutableSetMultimap<String, Integer> badEntries = ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358); multimap.putAll(badEntries); multimap = Multimaps.filterEntries( multimap, Predicates.not( Predicates.in(ImmutableMap.of("one", 159, "two", 265).entrySet()))); return Multimaps.filterKeys( multimap, Predicates.not(Predicates.in(ImmutableSet.of("foo", "bar")))); } })
public void testFilterKeys() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE); assertEquals(1, filtered.size()); assertTrue(filtered.containsEntry("foo", 55556)); }
public void testFilteredKeysSetMultimapReplaceValues() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys(multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); assertEquals(ImmutableSet.of(), filtered.replaceValues("baz", ImmutableSet.<Integer>of())); try { filtered.replaceValues("baz", ImmutableSet.of(5)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { ImmutableSetMultimap<String, Integer> badEntries = ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358); multimap.putAll(badEntries); multimap = Multimaps.filterKeys( multimap, Predicates.not(Predicates.in(ImmutableSet.of("foo", "bar")))); return Multimaps.filterEntries( multimap, Predicates.not(Predicates.in(badEntries.entries()))); } })
public void testFilterFiltered() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); unfiltered.put("foo", 1); Multimap<String, Integer> keyFiltered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE); Multimap<String, Integer> filtered = Multimaps.filterValues(keyFiltered, VALUE_PREDICATE); assertEquals(1, filtered.size()); assertTrue(filtered.containsEntry("foo", 1)); assertTrue(filtered.keySet().retainAll(Arrays.asList("cat", "dog"))); assertEquals(0, filtered.size()); }
public void testFilteredKeysSetMultimapGetBadValue() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys(multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); Set<Integer> bazSet = filtered.get("baz"); assertThat(bazSet).isEmpty(); try { bazSet.add(5); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { bazSet.addAll(ImmutableSet.of(6, 7)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
Multimaps.filterKeys(multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); List<Integer> bazList = filtered.get("baz"); assertThat(bazList).isEmpty();