List of usage examples for java.util Map replaceAll
default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
From source file:msi.gaml.types.GamaType.java
@Override public void setFieldGetters(final Map<String, OperatorProto> map) { map.replaceAll((final String key, final OperatorProto each) -> each.copyWithSignature(this)); getters = map;/*from w w w .j a va 2s .co m*/ // AD 20/09/13 Added the initialization of the type containing the // fields }
From source file:com.vsct.dt.hesperides.templating.platform.PropertiesData.java
public MustacheScope toMustacheScope(Set<KeyValueValorisationData> instanceValorisations, Set<KeyValueValorisationData> platformValorisations, Boolean buildingFile) { if (instanceValorisations == null) { instanceValorisations = new HashSet<>(); }/* ww w. j av a2s . c o m*/ if (platformValorisations == null) { platformValorisations = new HashSet<>(); } HashSet<ValorisationData> valorisations = new HashSet<>(); valorisations.addAll(keyValueProperties); valorisations.addAll(iterableProperties); if (platformValorisations != null) { /* addAll doesn't replace existing values, but we want to, so iterate */ for (KeyValueValorisationData v : platformValorisations) { //Remove local valorisation if it exists (ie has the same name even if the value is different) for (Iterator<ValorisationData> it = valorisations.iterator(); it.hasNext();) { ValorisationData existingValorisation = it.next(); if (existingValorisation.getName().equals(v.getName())) { it.remove(); } } valorisations.add(v); } } /* Prepare what will be injected in the values */ Map<String, String> injectableKeyValueValorisations = keyValueProperties.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); Map<String, String> injectablePlatformValorisations = platformValorisations.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); /* Erase local valorisations by platform valorisations */ injectableKeyValueValorisations.putAll(injectablePlatformValorisations); Map<String, String> injectableInstanceProperties = instanceValorisations.stream() .collect(Collectors.toMap(ValorisationData::getName, KeyValueValorisationData::getValue)); injectableKeyValueValorisations.replaceAll((key, value) -> value.replace("$", "\\$")); injectableInstanceProperties.replaceAll((key, value) -> value.replace("$", "\\$")); InjectableMustacheScope injectable = MustacheScope.from(valorisations) /* First re-inject keyValueValorisations, so they can refer to themselves */ .inject(injectableKeyValueValorisations) /* Do it a second time in case global properties where referring to themselves */ .inject(injectableKeyValueValorisations) /* Finally inject instance valorisations */ .inject(injectableInstanceProperties) /* Do it a third time in case instances properties where referring to global properties */ .inject(injectableKeyValueValorisations); MustacheScope mustacheScope = injectable.create(); if (mustacheScope.getMissingKeyValueProperties().size() > 0 && buildingFile) { Map<String, String> missing_valuation = new HashMap<>(); Set<KeyValuePropertyModel> missing = mustacheScope.getMissingKeyValueProperties(); missing.stream().forEach(prop -> { missing_valuation.put(prop.getName(), ""); }); mustacheScope = injectable.inject(missing_valuation).create(); } return mustacheScope; }