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:net.minecraftforge.common.model.animation.AnimationStateMachine.java
@Deprecated public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMap<String, String> transitions, String startState) { this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps .newSetMultimap(Maps.transformValues(transitions, new Function<String, Collection<String>>() { public Collection<String> apply(String input) { return ImmutableSet.of(input); }// w w w .j a v a2 s . c o m }), new Supplier<Set<String>>() { public Set<String> get() { return Sets.newHashSet(); } })), startState); }
From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java
public static <T, U> Function<RowResult<T>, RowResult<U>> transformValues(final Function<T, U> transform) { return new Function<RowResult<T>, RowResult<U>>() { @Override//from w w w . ja v a 2 s.co m public RowResult<U> apply(RowResult<T> row) { return RowResult.create(row.getRowName(), Maps.transformValues(row.getColumns(), transform)); } }; }
From source file:org.eclipse.xtext.xbase.lib.MapExtensions.java
/** * <p>Returns a map that performs the given {@code transformation} for each value of {@code original} when requested.</p> * /*from w w w . j a v a2s. c om*/ * <p>The mapping is done lazily. That is, subsequent access of the values in the map will repeatedly apply the * transformation. Characteristics of the original map, such as iteration order, are left intact. Changes in the * original map are reflected in the result map. The results supports removal if the original map supports removal.</p> * * @param original * the original map. May not be <code>null</code>. * @param transformation * the transformation. May not be <code>null</code>. * @return a map with equal keys but transformed values. Never <code>null</code>. * @since 2.4 */ public static <K, V1, V2> Map<K, V2> mapValues(Map<K, V1> original, Function1<? super V1, ? extends V2> transformation) { return Maps.transformValues(original, new FunctionDelegate<V1, V2>(transformation)); }
From source file:org.apache.helix.api.Cluster.java
/** * construct a cluster//from w ww. j a va 2s . c o m * @param id * @param resourceMap * @param participantMap * @param controllerMap * @param leaderId * @param constraintMap * @param stateModelMap * @param contextMap * @param userConfig * @param isPaused * @param autoJoinAllowed */ public Cluster(ClusterId id, Map<ResourceId, Resource> resourceMap, Map<ParticipantId, Participant> participantMap, Map<ControllerId, Controller> controllerMap, ControllerId leaderId, Map<ConstraintType, ClusterConstraints> constraintMap, Map<StateModelDefId, StateModelDefinition> stateModelMap, Map<ContextId, ControllerContext> contextMap, UserConfig userConfig, boolean isPaused, boolean autoJoinAllowed, ClusterDataCache cache) { // build the config // Guava's transform and "copy" functions really return views so the maps all reflect each other Map<ResourceId, ResourceConfig> resourceConfigMap = Maps.transformValues(resourceMap, new Function<Resource, ResourceConfig>() { @Override public ResourceConfig apply(Resource resource) { return resource.getConfig(); } }); Map<ParticipantId, ParticipantConfig> participantConfigMap = Maps.transformValues(participantMap, new Function<Participant, ParticipantConfig>() { @Override public ParticipantConfig apply(Participant participant) { return participant.getConfig(); } }); _config = new ClusterConfig.Builder(id).addResources(resourceConfigMap.values()) .addParticipants(participantConfigMap.values()).addConstraints(constraintMap.values()) .addStateModelDefinitions(stateModelMap.values()).pausedStatus(isPaused).userConfig(userConfig) .autoJoin(autoJoinAllowed).build(); _resourceMap = ImmutableMap.copyOf(resourceMap); _participantMap = ImmutableMap.copyOf(participantMap); // Build the subset of participants that is live ImmutableMap.Builder<ParticipantId, Participant> liveParticipantBuilder = new ImmutableMap.Builder<ParticipantId, Participant>(); for (Participant participant : participantMap.values()) { if (participant.isAlive()) { liveParticipantBuilder.put(participant.getId(), participant); } } _liveParticipantMap = liveParticipantBuilder.build(); _leaderId = leaderId; _contextMap = ImmutableMap.copyOf(contextMap); _cache = cache; // TODO impl this when we persist controllers and spectators on zookeeper _controllerMap = ImmutableMap.copyOf(controllerMap); _spectatorMap = Collections.emptyMap(); }
From source file:com.facebook.buck.core.rules.graphbuilder.impl.DefaultBuildRuleContextWithEnvironment.java
@Override public CompletionStage<BuildRule> getProviderCollectionForDeps(Iterable<BuildRuleKey> depKeys, Function<ImmutableMap<BuildRuleKey, BuildRuleInfoProviderCollection>, BuildRule> createBuildRuleWithDeps) { return getEnv().evaluateAll(depKeys, depBuildRules -> createBuildRuleWithDeps.apply( ImmutableMap.copyOf(Maps.transformValues(depBuildRules, rule -> rule.getProviderCollection())))); }
From source file:com.github.lukaszkusek.xml.comparator.XMLComparatorBuilder.java
public XMLComparatorBuilder valueExtractors(Map<String, String> valueExtractors) { this.valueExtractors = Maps.transformValues(valueExtractors, Pattern::compile); return this; }
From source file:de.tuberlin.uebb.jdae.transformation.Reduction.java
public Reduction(final Collection<Equation> equations) { final ImmutableList.Builder<GlobalEquation> be = ImmutableList.builder(); this.names = Maps.newTreeMap(); final Map<Unknown, Integer> layout = Maps.newTreeMap(); final TransitiveRelation<Unknown> equivalent = Relations.newTransitiveRelation(); for (Equation eq : equations) { for (Unknown unknown : eq.unknowns()) { final Unknown base = unknown.base(); final Integer order = layout.get(base); if (order == null || (unknown.der > order)) layout.put(base, unknown.der); }/*from w ww .ja va 2s . co m*/ if (eq instanceof Equality) { final Unknown l = ((Equality) eq).lhs; final Unknown r = ((Equality) eq).rhs; Unknown min = Ordering.natural().min(l, r); Unknown max = Ordering.natural().max(l, r); if (min.der == 0) { equivalent.relate(min, max); } } } final Navigator<Unknown> direct = equivalent.direct(); final Map<Unknown, Unknown> repres = Maps.newTreeMap(); for (Map.Entry<Unknown, Integer> entry : layout.entrySet()) { final Unknown base = entry.getKey(); final int max = entry.getValue(); final Unknown repr = Collections.max(Navigators.closure(direct, base), Ordering.natural()); for (int i = 0; i <= max; i++) { repres.put(base.der(i), repr.der(i)); } } final Function<Unknown, GlobalVariable> pack_dense = new Function<Unknown, GlobalVariable>() { final Map<Integer, Integer> mem = Maps.newTreeMap(); public GlobalVariable apply(Unknown u) { if (!mem.containsKey(u.nr)) { mem.put(u.nr, (mem.size() + 1)); names.put(mem.get(u.nr), u.name); } return new GlobalVariable(u.name, mem.get(u.nr), u.der); } }; ctxt = Maps.transformValues(repres, pack_dense); for (Equation eq : equations) { if (eq instanceof Equality) { final Unknown l = ((Equality) eq).lhs; final Unknown r = ((Equality) eq).rhs; final Unknown min = Ordering.natural().min(l, r); if (min.der != 0) be.add(eq.bind(ctxt)); } else { be.add(eq.bind(ctxt)); } } reduced = be.build(); this.unknowns = ImmutableSortedSet.copyOf(ctxt.values()); }
From source file:com.b2international.snowowl.datastore.internal.branch.CDOBranchMerger.java
@Override public Map<CDOID, Conflict> getConflicts() { // Due to the nature of rebase we need to transform certain conflicts to reflect the source and target branches properly if (isRebase) { return Maps.transformValues(super.getConflicts(), new Function<Conflict, Conflict>() { @Override//from w w w . ja va 2 s .c o m public Conflict apply(Conflict input) { return ConflictMapper.invert(input); } }); } return super.getConflicts(); }
From source file:org.apache.druid.client.cache.CaffeineCache.java
@Override public Map<NamedKey, byte[]> getBulk(Iterable<NamedKey> keys) { // The assumption here is that every value is accessed at least once. Materializing here ensures deserialize is only // called *once* per value. return ImmutableMap.copyOf(Maps.transformValues(cache.getAllPresent(keys), this::deserialize)); }
From source file:io.airlift.drift.codec.ArrayField.java
public Map<Short, List<Double>> getMapDoubleList() { if (mapDoubleArray == null) { return null; }//from ww w. j a v a2 s . c om return Maps.transformValues(mapDoubleArray, Doubles::asList); }