List of usage examples for com.google.common.collect Maps uniqueIndex
public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:org.trancecode.xproc.PipelineConfiguration.java
private static Map<QName, StepProcessor> getDefaultStepProcessors() { final Map<QName, StepProcessor> processors = Maps.newHashMap(); final Map<QName, StepProcessor> availableProcessors = Maps .uniqueIndex(ServiceLoader.load(StepProcessor.class), stepProcessor -> stepProcessor.getStepType()); processors.putAll(availableProcessors); for (final QName stepType : Iterables.concat(XProcSteps.REQUIRED_STEPS, XProcSteps.OPTIONAL_STEPS)) { if (!processors.containsKey(stepType)) { processors.put(stepType, StepProcessors.unsupportedStepProcessor(stepType)); }/* w w w.j a va2s.c om*/ } return ImmutableMap.copyOf(processors); }
From source file:org.gradle.api.internal.project.taskfactory.DefaultTaskClassValidatorExtractor.java
public DefaultTaskClassValidatorExtractor( Iterable<? extends PropertyAnnotationHandler> customAnnotationHandlers) { Iterable<PropertyAnnotationHandler> allAnnotationHandlers = Iterables.concat(HANDLERS, customAnnotationHandlers);/* w ww . ja v a 2 s. c o m*/ this.annotationHandlers = Maps.uniqueIndex(allAnnotationHandlers, new Function<PropertyAnnotationHandler, Class<? extends Annotation>>() { @Override public Class<? extends Annotation> apply(PropertyAnnotationHandler handler) { return handler.getAnnotationType(); } }); this.annotationOverrides = collectAnnotationOverrides(allAnnotationHandlers); }
From source file:org.opennms.netmgt.dao.jaxb.WSManDataCollectionConfigDaoJaxb.java
@Override public List<Group> getGroupsForAgent(Collection collection, CollectionAgent agent, WsmanAgentConfig agentConfig, OnmsNode node) {//ww w . j a v a2 s. c o m // Fetch the system definitions for the given collection List<SystemDefinition> sysDefs = getSystemDefinitionsForCollection(collection); // Map all of the available groups by name for easy lookup final Map<String, Group> groupsByName = Maps.uniqueIndex(getConfig().getGroup(), g -> g.getName()); // Gather the groups from all of the supported system definitions final List<Group> groups = Lists.newArrayList(); for (SystemDefinition sysDef : sysDefs) { if (isAgentSupportedBySystemDefinition(sysDef, agent, agentConfig, node)) { for (String groupName : sysDef.getIncludeGroup()) { Group group = groupsByName.get(groupName); if (group == null) { LOG.warn("System definition with name {} includes group with name {}, " + "but no such group was found.", sysDef.getName(), groupName); continue; } groups.add(group); } } } return groups; }
From source file:de.adrodoc55.minecraft.mpl.compilation.MplCompiler.java
public static MplCompilationResult toResult(Orientation3D orientation, List<CommandBlockChain> chains) { List<MplBlock> blocks = chains.stream()// .flatMap(c -> c.getBlocks().stream())// .collect(toList());//from ww w . ja v a 2 s . c o m ImmutableMap<Coordinate3D, MplBlock> result = Maps.uniqueIndex(blocks, b -> b.getCoordinate()); return new MplCompilationResult(orientation, result); }
From source file:org.apache.curator.framework.schema.SchemaSet.java
/** * Define a schema set. Schemas are matched in a well defined order: * <ol>/*from www . j a v a 2 s . co m*/ * <li>Exact match on full path (i.e. non-regex)</li> * <li>Match on the first regex path, searched in the order given to this constructor</li> * </ol> * * @param schemas the schemas for the set. * @param useDefaultSchema if true, return a default schema when there is no match. Otherwise, an exception is thrown */ public SchemaSet(List<Schema> schemas, boolean useDefaultSchema) { schemas = Preconditions.checkNotNull(schemas, "schemas cannot be null"); this.useDefaultSchema = useDefaultSchema; this.schemas = Maps.uniqueIndex(schemas, new Function<Schema, String>() { @Override public String apply(Schema schema) { return schema.getName(); } }); ImmutableMap.Builder<String, Schema> pathBuilder = ImmutableMap.builder(); ImmutableList.Builder<Schema> regexBuilder = ImmutableList.builder(); for (Schema schema : schemas) { if (schema.getPath() != null) { pathBuilder.put(schema.getPath(), schema); } else { regexBuilder.add(schema); } } pathToSchemas = pathBuilder.build(); regexSchemas = regexBuilder.build(); }
From source file:io.prestosql.metadata.SessionPropertyManager.java
public void addConnectorSessionProperties(ConnectorId connectorId, List<PropertyMetadata<?>> properties) { requireNonNull(connectorId, "connectorId is null"); requireNonNull(properties, "properties is null"); Map<String, PropertyMetadata<?>> propertiesByName = Maps.uniqueIndex(properties, PropertyMetadata::getName); checkState(connectorSessionProperties.putIfAbsent(connectorId, propertiesByName) == null, "Session properties for connectorId '%s' are already registered", connectorId); }
From source file:org.sonar.server.qualityprofile.QProfileComparison.java
private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, QualityProfileDto profile) { return Maps.uniqueIndex(dbClient.activeRuleDao().selectByProfileKey(session, profile.getKey()), ActiveRuleToRuleKey.INSTANCE); }
From source file:org.onos.yangtools.yang.model.util.FilteringSchemaContextProxy.java
/** * Filters SchemaContext for yang modules * * @param delegate original SchemaContext * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports * *///from w ww. j a v a 2 s.c om public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection<ModuleId> rootModules, final Set<ModuleId> additionalModuleIds) { Preconditions.checkArgument(rootModules != null, "Base modules cannot be null."); Preconditions.checkArgument(additionalModuleIds != null, "Additional modules cannot be null."); final Builder<Module> filteredModulesBuilder = new Builder<>(); final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps .newSetMultimap(new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER); ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder(); //preparing map to get all modules with one name but difference in revision final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap(); nameToModulesAll.putAll(getStringModuleMap(delegate)); //in case there is a particular dependancy to view filteredModules/yang models //dependancy is checked for module name and imports processForRootModules(delegate, rootModules, filteredModulesBuilder); //adding additional modules processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder .addAll(getImportedModules(Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID), filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.filteredModules = filteredModulesBuilder.build(); for (final Module module : filteredModules) { nameMap.put(module.getName(), module); nsMap.put(module.getNamespace(), module); identifiersToSourcesBuilder.put(module, module.getSource()); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); identifiersToSources = identifiersToSourcesBuilder.build(); }
From source file:com.b2international.snowowl.snomed.datastore.index.change.DescriptionAcceptabilityChangeProcessor.java
public Map<String, Multimap<Acceptability, RefSetMemberChange>> process(ICDOCommitChangeSet commitChangeSet, RevisionSearcher searcher) throws IOException { final Multimap<String, RefSetMemberChange> preferredMemberChanges = HashMultimap.create(); final Multimap<String, RefSetMemberChange> acceptableMemberChanges = HashMultimap.create(); // add active new and active dirty members final Iterable<SnomedLanguageRefSetMember> newAndDirtyMembers = Iterables.concat( commitChangeSet.getNewComponents(SnomedLanguageRefSetMember.class), commitChangeSet.getDirtyComponents(SnomedLanguageRefSetMember.class)); for (SnomedLanguageRefSetMember member : newAndDirtyMembers) { if (member.isActive()) { final String uuid = member.getUuid(); final String refSetId = member.getRefSetIdentifierId(); final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.ADDED, member.isActive());/*from w ww . j a v a 2 s . co m*/ registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change); } } // remove dirty inactive (and/or changed in acceptability) members final Iterable<SnomedLanguageRefSetMember> dirtyMembers = commitChangeSet .getDirtyComponents(SnomedLanguageRefSetMember.class); final Iterable<Long> dirtyMemberStorageKeys = CDOIDUtils.createCdoIdToLong(CDOIDUtils.getIds(dirtyMembers)); final Iterable<Long> detachedMemberStorageKeys = CDOIDUtils.createCdoIdToLong( commitChangeSet.getDetachedComponents(SnomedRefSetPackage.Literals.SNOMED_LANGUAGE_REF_SET_MEMBER)); final Map<Long, SnomedRefSetMemberIndexEntry> currentRevisionsByStorageKey = Maps.uniqueIndex( searcher.get(SnomedRefSetMemberIndexEntry.class, Iterables.concat(dirtyMemberStorageKeys, detachedMemberStorageKeys)), new Function<SnomedRefSetMemberIndexEntry, Long>() { @Override public Long apply(SnomedRefSetMemberIndexEntry input) { return input.getStorageKey(); } }); for (SnomedLanguageRefSetMember member : dirtyMembers) { final String uuid = member.getUuid(); final String refSetId = member.getRefSetIdentifierId(); final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, member.isActive()); final SnomedRefSetMemberIndexEntry before = currentRevisionsByStorageKey .get(CDOIDUtil.getLong(member.cdoID())); if (before != null) { final String beforeAcceptabilityId = before.getAcceptabilityId(); final boolean beforeActive = before.isActive(); final boolean acceptabilityChanged = !member.getAcceptabilityId().equals(beforeAcceptabilityId); if (beforeActive && acceptabilityChanged) { registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, member.getReferencedComponentId(), change); } } if (!member.isActive()) { registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change); } } // remove earlier active detached members for (CDOID cdoid : commitChangeSet .getDetachedComponents(SnomedRefSetPackage.Literals.SNOMED_LANGUAGE_REF_SET_MEMBER)) { final SnomedRefSetMemberIndexEntry before = currentRevisionsByStorageKey.get(CDOIDUtil.getLong(cdoid)); if (before.isActive()) { final String uuid = before.getId(); final String refSetId = before.getReferenceSetId(); final String referencedComponentId = before.getReferencedComponentId(); final String beforeAcceptabilityId = before.getAcceptabilityId(); final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, before.isActive()); registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, referencedComponentId, change); } } final Map<String, Multimap<Acceptability, RefSetMemberChange>> changes = newHashMap(); for (String descriptionId : Iterables.concat(preferredMemberChanges.keySet(), acceptableMemberChanges.keySet())) { if (!changes.containsKey(descriptionId)) { changes.put(descriptionId, HashMultimap.<Acceptability, RefSetMemberChange>create()); } final Multimap<Acceptability, RefSetMemberChange> memberChanges = changes.get(descriptionId); memberChanges.putAll(Acceptability.PREFERRED, preferredMemberChanges.get(descriptionId)); memberChanges.putAll(Acceptability.ACCEPTABLE, acceptableMemberChanges.get(descriptionId)); } return changes; }
From source file:com.facebook.presto.util.GraphvizPrinter.java
public static String printLogical(List<PlanFragment> fragments) { Map<PlanFragmentId, PlanFragment> fragmentsById = Maps.uniqueIndex(fragments, PlanFragment::getId); PlanNodeIdGenerator idGenerator = new PlanNodeIdGenerator(); StringBuilder output = new StringBuilder(); output.append("digraph logical_plan {\n"); for (PlanFragment fragment : fragments) { printFragmentNodes(output, fragment, idGenerator); }/* w w w .j a va 2 s . c o m*/ for (PlanFragment fragment : fragments) { fragment.getRoot().accept(new EdgePrinter(output, fragmentsById, idGenerator), null); } output.append("}\n"); return output.toString(); }