/** * Add a {@link Set} of entities to this EntityMap instance. * * @param vertex the vertex associated with the entity * @param entities the set of entities * * @return {@code true} if the entity was successfully added, otherwise * {@code false} */ public boolean putEntities(final Object vertex, final Set<Entity> entities) { return backingMap.putAll(vertex, entities); }
/** * It is implicitly assumed that all the services are NEW and that they will all remain NEW * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's * responsibility to only call {@link #markReady()} if all services were new at the time this * method was called and when all the listeners were installed. */ ServiceManagerState(ImmutableCollection<Service> services) { this.numberOfServices = services.size(); servicesByState.putAll(NEW, services); }
/** * Registers the given handler for the given class to receive events. * * @param handlers a map of handlers */ public synchronized void subscribeAll(Multimap<Class<?>, EventHandler> handlers) { checkNotNull(handlers); handlersByType.putAll(handlers); }
@Override public Iterable<ValueType> apply(@Nullable String typeName) { Set<ValueType> subtypes = subtyping.get(typeName); subtypeUsages.putAll(typeName, subtypes); /* for (ValueType subtype : subtypes) { subtypeUsages.put(subtype.typeAbstract().toString(), subtype); }*/ return subtypes; } };
public void addNode(ConnectorId connectorId, Iterable<Node> nodes) { remoteNodes.putAll(connectorId, nodes); List<Consumer<AllNodes>> listeners; synchronized (this) { listeners = ImmutableList.copyOf(this.listeners); } AllNodes allNodes = getAllNodes(); listeners.forEach(listener -> listener.accept(allNodes)); }
/** * It is implicitly assumed that all the services are NEW and that they will all remain NEW * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's * responsibility to only call {@link #markReady()} if all services were new at the time this * method was called and when all the listeners were installed. */ ServiceManagerState(ImmutableCollection<Service> services) { this.numberOfServices = services.size(); servicesByState.putAll(NEW, services); }
/** * It is implicitly assumed that all the services are NEW and that they will all remain NEW * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's * responsibility to only call {@link #markReady()} if all services were new at the time this * method was called and when all the listeners were installed. */ ServiceManagerState(ImmutableCollection<Service> services) { this.numberOfServices = services.size(); servicesByState.putAll(NEW, services); }
private static void populateMultimap(SetMultimap<Pattern, Pattern> multimap, String list) throws IOException { Splitter tokenSplitter = Splitter.on(",").omitEmptyStrings().trimResults(); Splitter partSplitter = Splitter.on(".").omitEmptyStrings().trimResults(); Splitter tableSplitter = Splitter.on("|").omitEmptyStrings().trimResults(); for (String token : tokenSplitter.split(list)) { if (!Strings.isNullOrEmpty(token)) { List<String> parts = partSplitter.splitToList(token); if (parts.size() > 2) { throw new IOException("Invalid token " + token); } Pattern databasePattern = Pattern.compile(parts.get(0).replace("*", ".*")); Set<Pattern> tablePatterns = Sets.newHashSet(); if (parts.size() == 2) { String tables = parts.get(1); for (String table : tableSplitter.split(tables)) { if (table.equals("*")) { // special case, must use ALL_TABLES due to use of set.contains(ALL_TABLES) in multimapContains tablePatterns.add(ALL_TABLES); } else { tablePatterns.add(Pattern.compile(table.replace("*", ".*"))); } } } else { tablePatterns.add(ALL_TABLES); } multimap.putAll(databasePattern, tablePatterns); } } }
@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")))); } })
@GwtIncompatible // SerializableTester public void testNewSetMultimapSerialization() { CountingSupplier<Set<Integer>> factory = new SetSupplier(); Map<Color, Collection<Integer>> map = Maps.newHashMap(); SetMultimap<Color, Integer> multimap = Multimaps.newSetMultimap(map, factory); multimap.putAll(Color.BLUE, asList(3, 1, 4)); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); SerializableTester.reserializeAndAssert(multimap); }
@Override public JsonElement serialize(BindsConfig bindsConfig, Type typeOfBindsConfig, JsonSerializationContext context) { JsonObject result = new JsonObject(); SetMultimap<Name, SimpleUri> bindingByModuleName = listBindingsByModuleName(bindsConfig); List<Name> sortedModuleNames = bindingByModuleName.keySet().stream().sorted().collect(toList()); for (Name moduleName : sortedModuleNames) { SetMultimap<String, Input> moduleBinds = HashMultimap.create(); for (SimpleUri bindingUri : bindingByModuleName.get(moduleName)) { moduleBinds.putAll(bindingUri.getObjectName().toString(), bindsConfig.uriBoundInputs.get(bindingUri)); } JsonElement map = context.serialize(moduleBinds, SetMultimap.class); result.add(moduleName.toString(), map); } return result; }
@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; } })
@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 testNewSetMultimap() { CountingSupplier<Set<Integer>> factory = new SetSupplier(); Map<Color, Collection<Integer>> map = Maps.newHashMap(); SetMultimap<Color, Integer> multimap = Multimaps.newSetMultimap(map, factory); assertEquals(0, factory.count); multimap.putAll(Color.BLUE, asList(3, 1, 4)); assertEquals(1, factory.count); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(2, factory.count); assertEquals(Sets.newHashSet(4, 3, 1), multimap.get(Color.BLUE)); }
@MapFeature.Require(SUPPORTS_PUT) public void testPutAllHandlesDuplicates() { @SuppressWarnings("unchecked") List<V> valuesToPut = Arrays.asList(v0(), v1(), v0()); for (K k : sampleKeys()) { resetContainer(); Set<V> expectedValues = copyToSet(multimap().get(k)); multimap().putAll(k, valuesToPut); expectedValues.addAll(valuesToPut); assertGet(k, expectedValues); } } }
@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); return Multimaps.filterEntries( multimap, Predicates.not(Predicates.in(badEntries.entries()))); } })
@Override public void registerQuery(Query query, final ListenableFuture future) { final String id = query.getId(); final List<String> datasources = query.getDataSource().getNames(); queries.put(id, future); queryDatasources.putAll(id, datasources); future.addListener( new Runnable() { @Override public void run() { queries.remove(id, future); for (String datasource : datasources) { queryDatasources.remove(id, datasource); } } }, Execs.directExecutor() ); }
protected SetMultimap<Integer, Integer> getNodePartitions(List<?> optNodes, List<?> optPartitions) { SetMultimap<Integer, Integer> nodePartitions = HashMultimap.create(); if(optPartitions != null && optNodes != null) { for(Object node: optNodes) { for(Object partition: optPartitions) nodePartitions.put((Integer) node, (Integer) partition); } } else if(optPartitions != null) { for(Object partition: optPartitions) { for(Integer node: getNodes((Integer) partition)) { nodePartitions.put(node, (Integer) partition); } } } else if(optNodes != null) { for(Object node: optNodes) { nodePartitions.putAll((Integer) node, getPartitions((Integer) node)); } } else throw new IllegalStateException(); return nodePartitions; }