@Override public Set<V> values() { Set<V> result = values; return (result == null) ? values = Collections.unmodifiableSet(delegate.values()) : result; }
@Override public Set<N> adjacentNodes() { return Collections.unmodifiableSet(((BiMap<E, N>) incidentEdgeMap).values()); }
@Override public Set<N> predecessors() { return Collections.unmodifiableSet(((BiMap<E, N>) inEdgeMap).values()); }
@Override public Set<N> successors() { return Collections.unmodifiableSet(((BiMap<E, N>) outEdgeMap).values()); }
@Override public Set<N> predecessors() { return Collections.unmodifiableSet(((BiMap<E, N>) inEdgeMap).values()); }
@Override public Set<N> successors() { return Collections.unmodifiableSet(((BiMap<E, N>) outEdgeMap).values()); }
@Override public Set<N> adjacentNodes() { return Collections.unmodifiableSet(((BiMap<E, N>) incidentEdgeMap).values()); }
@Override public Set<V> create(Object... elements) { @SuppressWarnings("unchecked") V[] valuesArray = (V[]) elements; // Start with a suitably shaped collection of entries Collection<Entry<K, V>> originalEntries = mapGenerator.getSampleElements(elements.length); // Create a copy of that, with the desired value for each value Collection<Entry<K, V>> entries = new ArrayList<>(elements.length); int i = 0; for (Entry<K, V> entry : originalEntries) { entries.add(Helpers.mapEntry(entry.getKey(), valuesArray[i++])); } return mapGenerator.create(entries.toArray()).values(); }
@Override public <T extends Biome> List<T> getBiomes(Class<T> biomeClass) { ImmutableList.Builder<T> builder = ImmutableList.builder(); biomeIdMap.values().stream().filter(biome -> biomeClass.isAssignableFrom(biome.getClass())).forEach(biome -> builder.add(biomeClass.cast(biome))); return builder.build(); }
@Override public Set<V> values() { synchronized (mutex) { if (valueSet == null) { valueSet = set(delegate().values(), mutex); } return valueSet; } }
@Override public Set<V> values() { assertTrue(Thread.holdsLock(mutex)); return delegate.values(); }
private PlanWithProperties plan(PlanNode node, HashComputationSet parentPreference) { PlanWithProperties result = node.accept(this, parentPreference); checkState( result.getNode().getOutputSymbols().containsAll(result.getHashSymbols().values()), "Node %s declares hash symbols not in the output", result.getNode().getClass().getSimpleName()); return result; } }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testRemoveFromInverseValuesRemovesFromInverse() { getMap().inverse().values().remove(k0()); expectMissing(e0()); }
@MapFeature.Require(SUPPORTS_REMOVE) public void testClearInverseValuesClears() { BiMap<V, K> inv = getMap().inverse(); inv.values().clear(); assertTrue(getMap().isEmpty()); assertTrue(inv.isEmpty()); } }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testRemoveFromValuesRemovesFromInverse() { getMap().values().remove(v0()); expectMissing(e0()); }
@MapFeature.Require(SUPPORTS_REMOVE) public void testValuesClearClearsInverse() { BiMap<V, K> inv = getMap().inverse(); getMap().values().clear(); assertTrue(getMap().isEmpty()); assertTrue(inv.isEmpty()); }
@Override public void testValues() { BiMap<String, Integer> map = create(); Set<Integer> values = map.values(); assertTrue(values instanceof SynchronizedSet); assertSame(mutex, ((SynchronizedSet<?>) values).mutex); } }
public void testValuesIteratorRemove() { // The enum orderings are alphabetical, leading to the bimap and its inverse // having inconsistent iteration orderings. Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); Iterator<Currency> iter = bimap.keySet().iterator(); assertEquals(Currency.DOLLAR, iter.next()); assertEquals(Currency.FRANC, iter.next()); iter.remove(); // forward map ordered by currency assertThat(bimap.keySet()).containsExactly(Currency.DOLLAR, Currency.PESO).inOrder(); // forward map ordered by currency (even for country values) assertThat(bimap.values()).containsExactly(Country.CANADA, Country.CHILE).inOrder(); // backward map ordered by country assertThat(bimap.inverse().keySet()).containsExactly(Country.CANADA, Country.CHILE).inOrder(); // backward map ordered by country (even for currency values) assertThat(bimap.inverse().values()).containsExactly(Currency.DOLLAR, Currency.PESO).inOrder(); }
public void testKeySetIteratorRemove() { // The enum orderings are alphabetical, leading to the bimap and its inverse // having inconsistent iteration orderings. Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); Iterator<Currency> iter = bimap.keySet().iterator(); assertEquals(Currency.DOLLAR, iter.next()); iter.remove(); // forward map ordered by currency assertThat(bimap.keySet()).containsExactly(Currency.FRANC, Currency.PESO).inOrder(); // forward map ordered by currency (even for country values) assertThat(bimap.values()).containsExactly(Country.SWITZERLAND, Country.CHILE).inOrder(); // backward map ordered by country assertThat(bimap.inverse().keySet()) .containsExactly(Country.CHILE, Country.SWITZERLAND) .inOrder(); // backward map ordered by country (even for currency values) assertThat(bimap.inverse().values()).containsExactly(Currency.PESO, Currency.FRANC).inOrder(); }
public void testIterationOrder() { // The enum orderings are alphabetical, leading to the bimap and its inverse // having inconsistent iteration orderings. Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); // forward map ordered by currency assertThat(bimap.keySet()) .containsExactly(Currency.DOLLAR, Currency.FRANC, Currency.PESO) .inOrder(); // forward map ordered by currency (even for country values) assertThat(bimap.values()) .containsExactly(Country.CANADA, Country.SWITZERLAND, Country.CHILE) .inOrder(); // backward map ordered by country assertThat(bimap.inverse().keySet()) .containsExactly(Country.CANADA, Country.CHILE, Country.SWITZERLAND) .inOrder(); // backward map ordered by country (even for currency values) assertThat(bimap.inverse().values()) .containsExactly(Currency.DOLLAR, Currency.PESO, Currency.FRANC) .inOrder(); }