List of usage examples for com.google.common.collect Maps transformValues
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap, Function<? super V1, V2> function)
From source file:org.apereo.portal.portlet.container.services.AbstractPortletPreferencesImpl.java
private final void initPrefs() { if (this.compositePreferencesView != null) { return;/*from w w w.j ava 2s . c o m*/ } final C initContext = this.getInitializationContext(); this.targetPortletPreferences = new LinkedHashMap<String, IPortletPreference>(); this.loadTargetPortletPreferences(initContext, this.targetPortletPreferences); this.basePortletPreferences = new LinkedHashMap<String, IPortletPreference>(); this.loadBasePortletPreferences(initContext, this.basePortletPreferences); this.compositePreferences = new LinkedHashMap<String, IPortletPreference>(this.basePortletPreferences); this.compositePreferences.putAll(this.targetPortletPreferences); this.compositePreferencesView = Maps.transformValues(this.compositePreferences, new Function<IPortletPreference, String[]>() { @Override public String[] apply(IPortletPreference input) { return input.getValues(); } }); }
From source file:com.facebook.buck.lua.LuaStandaloneBinary.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); buildableContext.recordArtifact(output); // Make sure the parent directory exists. steps.add(new MkdirStep(getProjectFilesystem(), output.getParent())); // Delete any other pex that was there (when switching between pex styles). steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.FORCED, RmStep.Mode.RECURSIVE)); steps.add(new ShellStep(getProjectFilesystem().getRootPath()) { @Override// ww w . ja v a 2s . c o m protected Optional<String> getStdin(ExecutionContext context) { try { return Optional.of(context.getObjectMapper() .writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, getResolver()::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, getResolver()::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, getResolver()::getAbsolutePath))))); } catch (IOException e) { throw new RuntimeException(e); } } @Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { ImmutableList.Builder<String> command = ImmutableList.builder(); command.addAll(builder.getCommandPrefix(getResolver())); command.addAll(builderArgs); command.add("--entry-point", mainModule); command.add("--interpreter"); if (starter.isPresent()) { command.add(getResolver().getAbsolutePath(starter.get()).toString()); } else { command.add(lua.getCommandPrefix(getResolver()).get(0)); } command.add(getProjectFilesystem().resolve(output).toString()); return command.build(); } @Override public String getShortName() { return "lua_package"; } }); return steps.build(); }
From source file:de.monticore.codegen.mc2cd.transl.MultiplicityTranslation.java
/** * Groups all the links with identical targets and maps them to their maximum Multiplicities */// w w w. j a v a2s. co m private Map<ASTCDAttribute, Multiplicity> mapCDAttributesToMaxMultiplicities( Set<Link<ASTNode, ASTCDAttribute>> cdAttributeLinks) { Map<ASTCDAttribute, List<Link<ASTNode, ASTCDAttribute>>> cdAttributesToLinks = cdAttributeLinks.stream() .collect(Collectors.groupingBy(Link::target)); return Maps.transformValues(cdAttributesToLinks, linkList -> linkList.stream() .map(link -> determineMultiplicity(link.rootLink().source(), link.source())) .reduce(BinaryOperator.maxBy(Multiplicity::compareTo)).get()); }
From source file:com.facebook.buck.core.rules.analysis.impl.RuleAnalysisTransformer.java
/** * Performs the rule analysis for the rule matching the given {@link BuildTarget}. This will * trigger its corresponding {@link/*www .ja v a 2 s . c om*/ * com.facebook.buck.core.description.RuleDescription#ruleImpl(RuleAnalysisContext, BuildTarget, * Object)}, which will create the rule's exported {@link ProviderInfoCollection} and register * it's corresponding Actions. * * <p>This method is similar in functionality to Bazel's {@code * com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction}. {@see <a * href="https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java">ConfiguredTargetFunction</a>} * * @return an {@link RuleAnalysisResult} containing information about the rule analyzed */ private <T> RuleAnalysisResult transformImpl(TargetNode<T> targetNode, TransformationEnvironment env) { BaseDescription<T> baseDescription = targetNode.getDescription(); Verify.verify(baseDescription instanceof RuleDescription); RuleDescription<T> ruleDescription = (RuleDescription<T>) baseDescription; RuleAnalysisContextImpl ruleAnalysisContext = new RuleAnalysisContextImpl(ImmutableMap.copyOf( Maps.transformValues(env.getDeps(RuleAnalysisKey.class), RuleAnalysisResult::getProviderInfos))); ProviderInfoCollection providers = ruleDescription.ruleImpl(ruleAnalysisContext, targetNode.getBuildTarget(), targetNode.getConstructorArg()); return ImmutableRuleAnalysisResultImpl.of(targetNode.getBuildTarget(), providers, ImmutableMap.copyOf(ruleAnalysisContext.getRegisteredActionData())); }
From source file:io.v.impl.google.lib.discovery.UpdateImpl.java
@Override public Advertisement getAdvertisement() { return new Advertisement(ad.getId(), ad.getInterfaceName(), ImmutableList.copyOf(ad.getAddresses()), new Attributes(ImmutableMap.copyOf(ad.getAttributes())), new Attachments(Maps.transformValues(ad.getAttachments(), new Function<byte[], byte[]>() { @Override/*from www . ja va2 s . co m*/ public byte[] apply(byte[] data) { return Arrays.copyOf(data, data.length); } }))); }
From source file:com.google.api.client.discovery.RestDiscovery.java
/** * Returns a map of the sub-resources on this resource. *///from w w w. j av a 2 s . co m public Map<String, RestResource> getResources() { if (document.getResources() == null) { return Collections.emptyMap(); } return Maps.transformValues(document.getResources(), new Function<Restresource, RestResource>() { public RestResource apply(Restresource input) { return new RestResource(input, document.getSchemas()); } }); }
From source file:com.facebook.buck.distributed.DistributedBuildState.java
public BuckConfig createBuckConfig(ProjectFilesystem projectFilesystem) { BuildJobStateBuckConfig remoteBuckConfig = remoteState.getBuckConfig(); ImmutableMap<String, ImmutableMap<String, String>> rawConfig = ImmutableMap .copyOf(Maps.transformValues(remoteBuckConfig.getRawBuckConfig(), new Function<List<OrderedStringMapEntry>, ImmutableMap<String, String>>() { @Override public ImmutableMap<String, String> apply(List<OrderedStringMapEntry> input) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (OrderedStringMapEntry entry : input) { builder.put(entry.getKey(), entry.getValue()); }/* w w w .j ava 2 s . c o m*/ return builder.build(); } })); Architecture remoteArchitecture = Architecture.valueOf(remoteBuckConfig.getArchitecture()); Architecture localArchitecture = Architecture.detect(); Preconditions.checkState(remoteArchitecture.equals(localArchitecture), "Trying to load config with architecture %s on a machine that is %s. " + "This is not supported.", remoteArchitecture, localArchitecture); Platform remotePlatform = Platform.valueOf(remoteBuckConfig.getPlatform()); Platform localPlatform = Platform.detect(); Preconditions.checkState(remotePlatform.equals(localPlatform), "Trying to load config with platform %s on a machine that is %s. This is not supported.", remotePlatform, localPlatform); return new BuckConfig(new Config(RawConfig.of(rawConfig)), projectFilesystem, remoteArchitecture, remotePlatform, ImmutableMap.copyOf(remoteBuckConfig.getUserEnvironment())); }
From source file:com.google.gerrit.server.ChangeUtil.java
/** * Get the next patch set ID from scanning refs in the repo. * * @param git repository to scan for patch set refs. * @param id previous patch set ID./*from w w w. ja va2 s . co m*/ * @return next unused patch set ID for the same change, skipping any IDs whose corresponding ref * names appear in the repository. */ public static PatchSet.Id nextPatchSetId(Repository git, PatchSet.Id id) throws IOException { return nextPatchSetIdFromChangeRefsMap(Maps.transformValues( git.getRefDatabase().getRefs(id.getParentKey().toRefPrefix()), Ref::getObjectId), id); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFile.java
private ImmutableMap<String, Object> getPropertiesFromMap(Map<String, String> propertyMap) { ImmutableMap<String, String> serviceProperties = getFilteredEntries(propertyMap, PROPERTY); Map<String, Object> transformedProperties = Maps.transformValues(serviceProperties, new Function<String, Object>() { @Override/*from ww w.j a va 2 s.c om*/ public Object apply(String input) { if (input.contains(LIST_DELIMITER)) { return splitBySeparatorAndTrimItems(input); } if (NumberUtils.isNumber(input)) { return NumberUtils.createNumber(input); } return input; } private Object splitBySeparatorAndTrimItems(String input) { String[] split = input.split(LIST_DELIMITER); for (int i = 0; i < split.length; i++) { split[i] = StringUtils.trim(split[i]); } return split; } }); return ImmutableMap.copyOf(transformedProperties); }
From source file:org.opentestsystem.authoring.testauth.service.impl.AffinityGroupHelper.java
private static final void populateDefaultItemSelectionParameters(final AffinityGroup affinityGroup, final String segmentId, final ItemSelectionAlgorithm itemSelectionAlgorithm) { if (itemSelectionAlgorithm != null && itemSelectionAlgorithm.getBlueprintParameters() != null) { affinityGroup.getAffinityGroupValueMap().get(segmentId) .setItemSelectionParameters(Maps.newHashMap(Maps.transformValues( Maps.uniqueIndex(itemSelectionAlgorithm.getBlueprintParameters(), ItemSelectionAlgorithmHelper.ISA_PARAMETER_NAME_TRANSFORMER), ItemSelectionAlgorithmHelper.ISA_PARAMETER_DEFAULT_VALUE_TRANSFORMER))); } else {//ww w .ja v a 2 s . c o m affinityGroup.getAffinityGroupValueMap().get(segmentId).setItemSelectionParameters(null); } }