List of usage examples for com.google.common.collect Multimap asMap
Map<K, Collection<V>> asMap();
From source file:org.bugkillers.bus.eventbus.SubscriberRegistry_.java
/** * Unregisters all subscribers on the given listener object. *//*from w w w.j a va 2 s.c o m*/ void unregister(Object listener) { Multimap<Class<?>, Subscriber_> listenerMethods = findAllSubscribers(listener); for (Map.Entry<Class<?>, Collection<Subscriber_>> entry : listenerMethods.asMap().entrySet()) { Class<?> eventType = entry.getKey(); Collection<Subscriber_> listenerMethodsForType = entry.getValue(); CopyOnWriteArraySet<Subscriber_> currentSubscribers = subscribers.get(eventType); if (currentSubscribers == null || !currentSubscribers.removeAll(listenerMethodsForType)) { // if removeAll returns true, all we really know is that at least one subscriber was // removed... however, barring something very strange we can assume that if at least one // subscriber was removed, all subscribers on listener for that event type were... after // all, the definition of subscribers on a particular class is totally static throw new IllegalArgumentException( "missing event subscriber for an annotated method. Is " + listener + " registered?"); } // don't try to remove the set if it's empty; that can't be done safely without a lock // anyway, if the set is empty it'll just be wrapping an array of length 0 } }
From source file:com.palantir.atlasdb.cleaner.KeyValueServiceScrubberStore.java
@Override public void queueCellsForScrubbing(Multimap<Cell, String> cellToTableNames, long scrubTimestamp, int batchSize) { Map<Cell, byte[]> values = Maps.newHashMap(); for (Map.Entry<Cell, Collection<String>> entry : cellToTableNames.asMap().entrySet()) { Cell cell = entry.getKey();/* w w w .ja va2 s .c om*/ Collection<String> tableNames = entry.getValue(); // Doing the join here is safe--queueCellsForScrubbing is only called once per transaction // so we'll have all the table names for a given scrubTimestamp String joined = StringUtils.join(tableNames, AtlasDbConstants.SCRUB_TABLE_SEPARATOR_CHAR); values.put(cell, PtBytes.toBytes(joined)); } for (List<Entry<Cell, byte[]>> batch : Iterables.partition(values.entrySet(), batchSize)) { Map<Cell, byte[]> batchMap = Maps.newHashMap(); for (Entry<Cell, byte[]> e : batch) { batchMap.put(e.getKey(), e.getValue()); } keyValueService.put(AtlasDbConstants.SCRUB_TABLE, batchMap, scrubTimestamp); } }
From source file:net.refractions.udig.catalog.PostgisService2.java
private Map<String, Collection<TableDescriptor>> lookupSchemasInDB(IProgressMonitor monitor) { String host = (String) params.get(HOST.key); Integer port = (Integer) params.get(PORT.key); String database = (String) params.get(DATABASE.key); String user = (String) params.get(USER.key); String pass = (String) params.get(PASSWD.key); PostgisLookUpSchemaRunnable runnable = new PostgisLookUpSchemaRunnable(host, port, user, pass, database); runnable.run(monitor);//from w w w . j av a2 s. c o m if (runnable.getError() != null) { message = new Exception(runnable.getError()); status = Status.BROKEN; return null; } Set<TableDescriptor> tables = runnable.getTableDescriptors(); Multimap<String, TableDescriptor> schemas = HashMultimap.create(); for (TableDescriptor schema : tables) { schemas.put(schema.schema, schema); } return schemas.asMap(); }
From source file:eu.itesla_project.iidm.eurostag.export.BranchParallelIndexes.java
public static BranchParallelIndexes build(Network network, EurostagEchExportConfig config) { Multimap<String, Identifiable> map = HashMultimap.create(); for (TwoTerminalsConnectable ttc : Iterables.concat(network.getLines(), network.getTwoWindingsTransformers())) { ConnectionBus bus1 = ConnectionBus.fromTerminal(ttc.getTerminal1(), config, EchUtil.FAKE_NODE_NAME1); ConnectionBus bus2 = ConnectionBus.fromTerminal(ttc.getTerminal2(), config, EchUtil.FAKE_NODE_NAME2); if (bus1.getId().compareTo(bus2.getId()) < 0) { map.put(bus1.getId() + bus2.getId(), ttc); } else {//from w w w . ja v a 2s . c om map.put(bus2.getId() + bus1.getId(), ttc); } } for (VoltageLevel vl : network.getVoltageLevels()) { for (Switch s : EchUtil.getSwitches(vl, config)) { Bus bus1 = EchUtil.getBus1(vl, s.getId(), config); Bus bus2 = EchUtil.getBus2(vl, s.getId(), config); if (bus1.getId().compareTo(bus2.getId()) < 0) { map.put(bus1.getId() + bus2.getId(), s); } else { map.put(bus2.getId() + bus1.getId(), s); } } } Map<String, Character> parallelIndexes = new HashMap<>(); for (Map.Entry<String, Collection<Identifiable>> entry : map.asMap().entrySet()) { List<Identifiable> eqs = new ArrayList<>(entry.getValue()); Collections.sort(eqs, (o1, o2) -> o1.getId().compareTo(o2.getId())); if (eqs.size() >= 2) { char index = '0'; for (Identifiable l : eqs) { index = incParallelIndex(index); parallelIndexes.put(l.getId(), index); } } } return new BranchParallelIndexes(parallelIndexes); }
From source file:fr.jcgay.maven.plugin.buildplan.ListPhaseMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { Multimap<String, MojoExecution> phases = Groups.ByPhase.of(calculateExecutionPlan().getMojoExecutions(), phase);//from w w w . j a va2 s. c o m if (!phases.isEmpty()) { TableDescriptor descriptor = ListPhaseTableDescriptor.of(phases.values()); for (Map.Entry<String, Collection<MojoExecution>> currentPhase : phases.asMap().entrySet()) { getLog().info(phaseTitleLine(descriptor, currentPhase.getKey())); for (MojoExecution execution : currentPhase.getValue()) { getLog().info(line(descriptor.rowFormat(), execution)); } } } else { getLog().warn("No plugin execution found within phase: " + phase); } }
From source file:com.b2international.snowowl.datastore.server.importer.AbstractTerminologyImportValidator.java
/** * Validates the metadata from the sheet. * //w ww . j av a 2 s. c om * @param sheetName * the name of the sheet. * @param metadata * the metadata to validate. */ protected void validateMetadata(final String sheetName, final Multimap<String, String> metadata) { for (final Entry<String, Collection<String>> entry : metadata.asMap().entrySet()) { final String displayName = entry.getKey(); final Set<String> keywords = Sets.newHashSet(); for (final String keyword : entry.getValue()) { validateNonEmptyAttribute(sheetName, keyword, MessageFormat.format("Keyword is empty in ''{0}'' group", displayName)); if (!keywords.add(keyword)) { addDefect(sheetName, DefectType.GROUP, MessageFormat .format("''{0}'' keyword is duplicated in group ''{1}''.", keyword, displayName)); } } } }
From source file:org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.java
private static Set<InstanceTaskConfig> buildInitialState(Map<Integer, ITaskConfig> tasks) { // Translate tasks into instance IDs. Multimap<ITaskConfig, Integer> instancesByConfig = HashMultimap.create(); Multimaps.invertFrom(Multimaps.forMap(tasks), instancesByConfig); // Reduce instance IDs into contiguous ranges. Map<ITaskConfig, Set<Range<Integer>>> rangesByConfig = Maps.transformValues(instancesByConfig.asMap(), Numbers::toRanges);/*from ww w . ja v a 2 s.c o m*/ ImmutableSet.Builder<InstanceTaskConfig> builder = ImmutableSet.builder(); for (Map.Entry<ITaskConfig, Set<Range<Integer>>> entry : rangesByConfig.entrySet()) { builder.add(new InstanceTaskConfig().setTask(entry.getKey().newBuilder()) .setInstances(IRange.toBuildersSet(convertRanges(entry.getValue())))); } return builder.build(); }
From source file:com.haulmont.cuba.core.sys.SecurityTokenManager.java
/** * Encrypt filtered data and write the result to the security token *///from w w w.jav a 2s. co m public void writeSecurityToken(Entity entity) { SecurityState securityState = getOrCreateSecurityState(entity); if (securityState != null) { JSONObject jsonObject = new JSONObject(); Multimap<String, Object> filtered = getFilteredData(securityState); if (filtered != null) { Set<Map.Entry<String, Collection<Object>>> entries = filtered.asMap().entrySet(); String[] filteredAttributes = new String[entries.size()]; int i = 0; for (Map.Entry<String, Collection<Object>> entry : entries) { MetaProperty metaProperty = entity.getMetaClass().getPropertyNN(entry.getKey()); if (metadata.getTools().isOwningSide(metaProperty)) { jsonObject.put(entry.getKey(), entry.getValue()); } filteredAttributes[i++] = entry.getKey(); } setFilteredAttributes(securityState, filteredAttributes); } if (!securityState.getReadonlyAttributes().isEmpty()) { jsonObject.put(READ_ONLY_ATTRIBUTES_KEY, securityState.getReadonlyAttributes()); } if (!securityState.getHiddenAttributes().isEmpty()) { jsonObject.put(HIDDEN_ATTRIBUTES_KEY, securityState.getHiddenAttributes()); } if (!securityState.getRequiredAttributes().isEmpty()) { jsonObject.put(REQUIRED_ATTRIBUTES_KEY, securityState.getRequiredAttributes()); } String json = jsonObject.toString(); byte[] encrypted; Cipher cipher = getCipher(Cipher.ENCRYPT_MODE); try { encrypted = cipher.doFinal(json.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { throw new RuntimeException("An error occurred while generating security token", e); } setSecurityToken(securityState, encrypted); } }
From source file:org.eclipse.xtext.serializer.sequencer.AssignmentFinder.java
protected Set<AbstractElement> findValidAssignmentsForContainmentRef(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, EObject value) { Multimap<ISerializationContext, AbstractElement> children = ArrayListMultimap.create(); for (Entry<AbstractElement, Collection<ISerializationContext>> e : assignments.asMap().entrySet()) { AbstractElement ele = e.getKey(); if (ele instanceof RuleCall) { EClassifier classifier = ((RuleCall) ele).getRule().getType().getClassifier(); if (!classifier.isInstance(value)) continue; }// w ww . j ava2 s . c o m for (ISerializationContext container : e.getValue()) { ISerializationContext child = SerializationContext.forChild(container, ele, value); children.put(child, ele); } } if (children.size() < 2) return Sets.newHashSet(children.values()); Set<ISerializationContext> found = contextFinder.findByContents(value, children.keySet()); Set<AbstractElement> result = Sets.newLinkedHashSet(); for (ISerializationContext ctx : children.keySet()) if (found.contains(ctx)) result.addAll(children.get(ctx)); return result; }
From source file:com.netflix.simianarmy.client.aws.chaos.TagsChaosCrawler.java
@Override public List<InstanceGroup> groups(String... names) { Multimap<String, Instance> instances = getInstancesGroupedByTags(tags); if (instances.isEmpty()) { return ImmutableList.of(); }//from w w w . ja v a2s. co m List<InstanceGroup> result = new ArrayList<>(instances.size()); for (Map.Entry<String, Collection<Instance>> group : instances.asMap().entrySet()) { if (names != null && indexOf(names, group.getKey()) < 0) continue; InstanceGroup instanceGroup = new BasicInstanceGroup(group.getKey(), Type.TAGGED_EC2, awsClient.region()); result.add(instanceGroup); for (Instance instance : group.getValue()) { instanceGroup.addInstance(instance.getInstanceId()); } } return result; }