本文整理汇总了Java中com.google.common.collect.Multimaps类的典型用法代码示例。如果您正苦于以下问题:Java Multimaps类的具体用法?Java Multimaps怎么用?Java Multimaps使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Multimaps类属于com.google.common.collect包,在下文中一共展示了Multimaps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LongPositions
import com.google.common.collect.Multimaps; //导入依赖的package包/类
LongPositions(Iterable<? extends Object> elements, final int bitPerLong) {
this.elements = ImmutableList.copyOf(elements);
checkArgument(bitPerLong <= BITS_IN_LONG, bitPerLong);
for (int i = 0; i < this.elements.size(); i++) {
positions.put(
this.elements.get(i),
new BitPosition(
i / bitPerLong,
i % bitPerLong));
}
this.longPositions = ImmutableSortedMap.copyOf(
Maps.transformEntries(
Multimaps.index(positions.values(), ToLongIndex.FUNCTION).asMap(),
new Maps.EntryTransformer<Integer, Collection<BitPosition>, LongSet>() {
@Override
public LongSet transformEntry(Integer key, Collection<BitPosition> position) {
return new LongSet(key, position);
}
}));
}
示例2: runTasks
import com.google.common.collect.Multimaps; //导入依赖的package包/类
public void runTasks() {
Multimaps.asMap(ImmutableListMultimap.copyOf(taskQueue)).values().forEach(tasks -> {
int size = tasks.size();
while (size > 0) {
int last = size - 1;
Task<?> current = tasks.get(last);
if (current.done()) {
taskQueue.get(current.getClass()).remove(last);
size--;
continue;
}
current.tick();
return;
}
});
}
示例3: runImpactAnalysis
import com.google.common.collect.Multimaps; //导入依赖的package包/类
private static Multimap<String, SecurityIndex> runImpactAnalysis(Network network, Set<String> contingencyIds,
ComputationManager computationManager, SimulatorFactory simulatorFactory,
ContingenciesProvider contingenciesProvider,
PrintStream out) throws Exception {
Stabilization stabilization = simulatorFactory.createStabilization(network, computationManager, 0);
ImpactAnalysis impactAnalysis = simulatorFactory.createImpactAnalysis(network, computationManager, 0, contingenciesProvider);
Map<String, Object> initContext = new HashMap<>();
SimulationParameters simulationParameters = SimulationParameters.load();
stabilization.init(simulationParameters, initContext);
impactAnalysis.init(simulationParameters, initContext);
out.println("running stabilization simulation...");
StabilizationResult sr = stabilization.run();
out.println("stabilization status: " + sr.getStatus());
out.println("stabilization metrics: " + sr.getMetrics());
if (sr.getStatus() == StabilizationStatus.COMPLETED) {
out.println("running impact analysis...");
ImpactAnalysisResult iar = impactAnalysis.run(sr.getState(), contingencyIds);
out.println("impact analysis metrics: " + iar.getMetrics());
return Multimaps.index(iar.getSecurityIndexes(), securityIndex -> securityIndex.getId().getContingencyId());
}
return null;
}
示例4: filterForAssessment
import com.google.common.collect.Multimaps; //导入依赖的package包/类
public final CorpusQueryAssessments filterForAssessment(final Set<QueryAssessment2016> assessment2016) {
final ImmutableSet.Builder<QueryResponse2016> matchingQueriesB = ImmutableSet.builder();
for (final QueryResponse2016 queryResponse2016 : assessments().keySet()) {
if (assessment2016.contains(assessments().get(queryResponse2016))) {
matchingQueriesB.add(queryResponse2016);
}
}
final ImmutableSet<QueryResponse2016> matchingQueries = matchingQueriesB.build();
final CorpusQueryAssessments.Builder ret = CorpusQueryAssessments.builder();
ret.queryReponses(matchingQueries);
ret.putAllQueryResponsesToSystemIDs(
Multimaps.filterKeys(queryResponsesToSystemIDs(), in(matchingQueries)));
ret.putAllMetadata(Maps.filterKeys(metadata(), in(matchingQueries)));
ret.putAllAssessments(Maps.filterKeys(assessments(), in(matchingQueries)));
return ret.build();
}
示例5: linkResponses
import com.google.common.collect.Multimaps; //导入依赖的package包/类
private ResponseLinking linkResponses(final Symbol docId,
final Iterable<Response> responses) {
final Predicate<Response> HasRelevantRealis =
compose(in(realisesWhichMustBeAligned), ResponseFunctions.realis());
final ImmutableSet<Response> systemResponsesAlignedRealis =
FluentIterable.from(responses).filter(HasRelevantRealis).toSet();
final Multimap<Symbol, Response> responsesByEventType =
Multimaps.index(systemResponsesAlignedRealis, ResponseFunctions.type());
final ImmutableSet.Builder<ResponseSet> ret = ImmutableSet.builder();
for (final Collection<Response> responseSet : responsesByEventType.asMap().values()) {
ret.add(ResponseSet.from(responseSet));
}
return ResponseLinking.builder().docID(docId).addAllResponseSets(ret.build()).build();
}
示例6: inferThriftFieldIds
import com.google.common.collect.Multimaps; //导入依赖的package包/类
/**
* Assigns all fields an id if possible. Fields are grouped by name and for each group, if there
* is a single id, all fields in the group are assigned this id. If the group has multiple ids,
* an error is reported.
*/
protected final Set<String> inferThriftFieldIds()
{
Set<String> fieldsWithConflictingIds = new HashSet<>();
// group fields by explicit name or by name extracted from field, method or property
Multimap<String, FieldMetadata> fieldsByExplicitOrExtractedName = Multimaps.index(fields, FieldMetadata::getOrExtractThriftFieldName);
inferThriftFieldIds(fieldsByExplicitOrExtractedName, fieldsWithConflictingIds);
// group fields by name extracted from field, method or property
// this allows thrift name to be set explicitly without having to duplicate the name on getters and setters
// todo should this be the only way this works?
Multimap<String, FieldMetadata> fieldsByExtractedName = Multimaps.index(fields, FieldMetadata::extractName);
inferThriftFieldIds(fieldsByExtractedName, fieldsWithConflictingIds);
return fieldsWithConflictingIds;
}
示例7: computeToString
import com.google.common.collect.Multimaps; //导入依赖的package包/类
private String computeToString() {
StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
if (!parameters.isEmpty()) {
builder.append("; ");
Multimap<String, String> quotedParameters =
Multimaps.transformValues(
parameters,
new Function<String, String>() {
@Override
public String apply(String value) {
return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
}
});
PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
}
return builder.toString();
}
示例8: getExtensionMap
import com.google.common.collect.Multimaps; //导入依赖的package包/类
private SetMultimap<String, IntegrationSessionExtension> getExtensionMap()
{
if( extensionMap == null )
{
synchronized( this )
{
if( extensionMap == null )
{
final SetMultimap<String, IntegrationSessionExtension> map = HashMultimap
.<String, IntegrationSessionExtension>create();
for( Extension ext : resultsTracker.getExtensions() )
{
final IntegrationSessionExtension integExtension = resultsTracker.getBeanByExtension(ext);
for( Parameter parameter : ext.getParameters("type") )
{
map.put(parameter.valueAsString(), integExtension);
}
}
extensionMap = Multimaps.unmodifiableSetMultimap(map);
}
}
}
return extensionMap;
}
示例9: activate
import com.google.common.collect.Multimaps; //导入依赖的package包/类
@Activate
public void activate() {
ribTable4 = new ConcurrentInvertedRadixTree<>(
new DefaultByteArrayNodeFactory());
ribTable6 = new ConcurrentInvertedRadixTree<>(
new DefaultByteArrayNodeFactory());
routesWaitingOnArp = Multimaps.synchronizedSetMultimap(
HashMultimap.create());
coreService.registerApplication(ROUTER_APP_ID);
bgpUpdatesExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder()
.setNameFormat("rib-updates-%d").build());
}
示例10: RemoteConfigLongPollService
import com.google.common.collect.Multimaps; //导入依赖的package包/类
/**
* Constructor.
*/
public RemoteConfigLongPollService() {
m_longPollFailSchedulePolicyInSecond = new ExponentialSchedulePolicy(1, 120); //in second
m_longPollingStopped = new AtomicBoolean(false);
m_longPollingService = Executors.newSingleThreadExecutor(
ApolloThreadFactory.create("RemoteConfigLongPollService", true));
m_longPollStarted = new AtomicBoolean(false);
m_longPollNamespaces =
Multimaps.synchronizedSetMultimap(HashMultimap.<String, RemoteConfigRepository>create());
m_notifications = Maps.newConcurrentMap();
m_remoteNotificationMessages = Maps.newConcurrentMap();
m_responseType = new TypeToken<List<ApolloConfigNotification>>() {
}.getType();
gson = new Gson();
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
m_httpUtil = ApolloInjector.getInstance(HttpUtil.class);
m_serviceLocator = ApolloInjector.getInstance(ConfigServiceLocator.class);
m_longPollRateLimiter = RateLimiter.create(m_configUtil.getLongPollQPS());
}
示例11: registerNotificationListener
import com.google.common.collect.Multimaps; //导入依赖的package包/类
@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {
@Override
protected void removeRegistration() {
final ListenerRegistration<T> me = this;
synchronized (DOMNotificationRouter.this) {
replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != me)));
}
}
};
if (!types.isEmpty()) {
final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
b.putAll(listeners);
for (final SchemaPath t : types) {
b.put(t, reg);
}
replaceListeners(b.build());
}
return reg;
}
示例12: getHosts
import com.google.common.collect.Multimaps; //导入依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getHosts() {
return storage.read(storeProvider -> {
Multimap<MaintenanceMode, String> hostsByMode =
Multimaps.transformValues(
Multimaps.index(
storeProvider.getAttributeStore().getHostAttributes(),
IHostAttributes::getMode),
IHostAttributes::getHost);
Map<MaintenanceMode, Object> hosts = ImmutableMap.of(
DRAINED, ImmutableSet.copyOf(hostsByMode.get(DRAINED)),
SCHEDULED, ImmutableSet.copyOf(hostsByMode.get(SCHEDULED)),
DRAINING, getTasksByHosts(storeProvider, hostsByMode.get(DRAINING)).asMap());
return Response.ok(hosts).build();
});
}
示例13: buildInitialState
import com.google.common.collect.Multimaps; //导入依赖的package包/类
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);
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();
}
示例14: getRoleSummary
import com.google.common.collect.Multimaps; //导入依赖的package包/类
@Override
public Response getRoleSummary() {
Multimap<String, IJobKey> jobsByRole = storage.read(
storeProvider ->
Multimaps.index(storeProvider.getTaskStore().getJobKeys(), IJobKey::getRole));
Multimap<String, IJobKey> cronJobsByRole = Multimaps.index(
Iterables.transform(Storage.Util.fetchCronJobs(storage), IJobConfiguration::getKey),
IJobKey::getRole);
Set<RoleSummary> summaries = FluentIterable.from(
Sets.union(jobsByRole.keySet(), cronJobsByRole.keySet()))
.transform(role -> new RoleSummary(
role,
jobsByRole.get(role).size(),
cronJobsByRole.get(role).size()))
.toSet();
return ok(Result.roleSummaryResult(new RoleSummaryResult(summaries)));
}
示例15: enrichStructuralVariants
import com.google.common.collect.Multimaps; //导入依赖的package包/类
@NotNull
private static List<EnrichedStructuralVariant> enrichStructuralVariants(@NotNull List<StructuralVariant> variants,
@NotNull DatabaseAccess dbAccess, @NotNull String tumorSample) {
final PurityContext purityContext = dbAccess.readPurityContext(tumorSample);
if (purityContext == null) {
LOGGER.warn("Unable to retrieve purple data. Enrichment may be incomplete.");
}
final PurityAdjuster purityAdjuster = purityContext == null
? new PurityAdjuster(Gender.FEMALE, 1, 1)
: new PurityAdjuster(purityContext.gender(), purityContext.bestFit().purity(), purityContext.bestFit().normFactor());
final List<PurpleCopyNumber> copyNumberList = dbAccess.readCopynumbers(tumorSample);
final Multimap<String, PurpleCopyNumber> copyNumbers = Multimaps.index(copyNumberList, PurpleCopyNumber::chromosome);
return EnrichedStructuralVariantFactory.enrich(variants, purityAdjuster, copyNumbers);
}