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.jclouds.tools.ant.taskdefs.sshjava.SSHJava.java
void replaceAllTokensIn(File directory) { Replace replacer = new Replace(); replacer.setProject(getProject());// w ww . j a v a 2 s . c o m replacer.setDir(directory); Map<String, String> map = Maps.newLinkedHashMap(); // this has to go first map.put(directory.getAbsolutePath(), remotedir.getAbsolutePath()); map.putAll(Maps.transformValues(shiftMap, new Function<String, String>() { @Override public String apply(String in) { return remotebase + ShellToken.FS.to(osFamily) + in; } })); map.putAll(replace); for (Entry<String, String> entry : map.entrySet()) { Replacefilter filter = replacer.createReplacefilter(); filter.setToken(entry.getKey()); filter.setValue(entry.getValue()); } replacer.execute(); }
From source file:io.hops.transaction.context.BaseEntityContext.java
final Collection<Entity> get(Predicate<ContextEntity> pred) { Map<Key, ContextEntity> filtered = Maps.filterValues(contextEntities, pred); Collection<Entity> transformed = Maps.transformValues(filtered, new Function<ContextEntity, Entity>() { @Override/*from w w w .j ava 2s . c o m*/ public Entity apply(ContextEntity input) { return input.getEntity(); } }).values(); return Collections2.filter(transformed, Predicates.notNull()); }
From source file:co.cask.cdap.data2.dataset2.lib.table.TableDataset.java
@Override public Row incrementAndGet(byte[] row, byte[][] columns, long[] amounts) { Map<byte[], Long> incResult; try {//from ww w . j a v a 2 s . c om incResult = table.incrementAndGet(row, columns, amounts); } catch (NumberFormatException e) { LOG.debug("increment failed for table: " + getTransactionAwareName() + ", row: " + Bytes.toStringBinary(row), e); throw e; } catch (Exception e) { LOG.debug("increment failed for table: " + getTransactionAwareName() + ", row: " + Bytes.toStringBinary(row), e); throw new DataSetException("increment failed", e); } // todo: define IncrementResult to make it more efficient return new Result(row, Maps.transformValues(incResult, new Function<Long, byte[]>() { @Nullable @Override public byte[] apply(@Nullable Long input) { return input == null ? null : Bytes.toBytes(input); } })); }
From source file:org.jboss.aerogear.android.impl.http.HttpRestProvider.java
private HeaderAndBody getHeaderAndBody(HttpURLConnection urlConnection) throws IOException { int statusCode = urlConnection.getResponseCode(); HeaderAndBody result;//from w ww . j ava2 s .c om Map<String, List<String>> headers; byte[] responseData; switch (statusCode) { case HttpStatus.SC_OK: InputStream in = new BufferedInputStream(urlConnection.getInputStream()); responseData = readBytes(in); break; case HttpStatus.SC_NO_CONTENT: responseData = new byte[0]; break; default: InputStream err = new BufferedInputStream(urlConnection.getErrorStream()); byte[] errData = readBytes(err); Map<String, String> errorHeaders = Maps.transformValues(urlConnection.getHeaderFields(), new Function<List<String>, String>() { @Override public String apply(List<String> input) { return TextUtils.join(",", input); } }); throw new HttpException(errData, statusCode, errorHeaders); } headers = urlConnection.getHeaderFields(); result = new HeaderAndBody(responseData, new HashMap<String, Object>(headers.size())); for (Map.Entry<String, List<String>> header : headers.entrySet()) { result.setHeader(header.getKey(), TextUtils.join(",", header.getValue())); } return result; }
From source file:org.devnexus.aerogear.HttpRestProvider.java
private HeaderAndBody getHeaderAndBody(HttpURLConnection urlConnection) throws IOException { int statusCode = urlConnection.getResponseCode(); HeaderAndBody result;//from w ww . ja v a 2 s. c o m Map<String, List<String>> headers; byte[] responseData; switch (statusCode) { case HttpStatus.SC_OK: case HttpStatus.SC_CREATED: InputStream in = new BufferedInputStream(urlConnection.getInputStream()); responseData = readBytes(in); break; case HttpStatus.SC_NO_CONTENT: responseData = new byte[0]; break; default: InputStream err = new BufferedInputStream(urlConnection.getErrorStream()); byte[] errData = readBytes(err); Map<String, String> errorHeaders = Maps.transformValues(urlConnection.getHeaderFields(), new Function<List<String>, String>() { @Override public String apply(List<String> input) { return TextUtils.join(",", input); } }); throw new HttpException(errData, statusCode, errorHeaders); } headers = urlConnection.getHeaderFields(); result = new HeaderAndBody(responseData, new HashMap<String, Object>(headers.size())); for (Map.Entry<String, List<String>> header : headers.entrySet()) { result.setHeader(header.getKey(), TextUtils.join(",", header.getValue())); } return result; }
From source file:org.jclouds.joyent.cloudapi.v6_5.domain.Dataset.java
/** * Contains a grouping of various minimum requirements for provisioning a machine with this * dataset. For example 'password' indicates that a password must be provided. * //w w w . j a va2s . com * <h4>Note</h4> * * requirements can contain arbitrarily complex values. If the value has structure, you should * use {@link #getRequirementsAsJsonLiterals} */ public Map<String, String> getRequirements() { return Maps.transformValues(requirements, Functions.compose(Functions.toStringFunction(), unquoteString)); }
From source file:ninja.leaping.permissionsex.backend.sql.SqlSubjectData.java
@Override public Map<Set<Entry<String, String>>, List<Entry<String, String>>> getAllParents() { return Maps.filterValues( Maps.transformValues(segments, dataEntry -> dataEntry == null ? null : dataEntry.getParents() == null ? null : ImmutableList.copyOf(dataEntry.getParents())), v -> v != null);//from w w w . j av a 2 s . com }
From source file:org.apache.brooklyn.container.location.docker.DockerJcloudsLocation.java
@Override public Template buildTemplate(ComputeService computeService, ConfigBag config, Collection<JcloudsLocationCustomizer> customizers) { String loginUser = config.get(JcloudsLocation.LOGIN_USER); String loginPassword = config.get(JcloudsLocation.LOGIN_USER_PASSWORD); String loginKeyFile = config.get(JcloudsLocation.LOGIN_USER_PRIVATE_KEY_FILE); String loginKeyData = config.get(JcloudsLocation.LOGIN_USER_PRIVATE_KEY_DATA); Template template = super.buildTemplate(computeService, config, customizers); DockerTemplateOptions templateOptions = (DockerTemplateOptions) template.getOptions(); Image image = template.getImage(); List<String> env = MutableList.copyOf(templateOptions.getEnv()); // Inject login credentials, if required Boolean injectLoginCredentials = config.get(INJECT_LOGIN_CREDENTIAL); if (injectLoginCredentials == null) { String imageDescription = image.getDescription(); for (String regex : IMAGE_DESCRIPTION_REGEXES_REQUIRING_INJECTED_LOGIN_CREDS) { if (imageDescription != null && imageDescription.matches(regex)) { injectLoginCredentials = true; break; }//from ww w . j a va 2s .c om } } if (Strings.isBlank(loginUser) && Strings.isBlank(loginPassword) && Strings.isBlank(loginKeyFile) && Strings.isBlank(loginKeyData)) { if (Boolean.TRUE.equals(injectLoginCredentials)) { loginUser = "root"; loginPassword = Identifiers.makeRandomPassword(12); templateOptions.overrideLoginUser(loginUser); templateOptions.overrideLoginPassword(loginPassword); env.add("BROOKLYN_ROOT_PASSWORD=" + loginPassword); } } Entity context = validateCallerContext(config); Map<String, Object> containerEnv = MutableMap .copyOf(context.config().get(DockerContainer.CONTAINER_ENVIRONMENT)); for (Map.Entry<String, String> entry : Maps.transformValues(containerEnv, Functions.toStringFunction()) .entrySet()) { env.add(String.format("%s=%s", entry.getKey(), entry.getValue())); } templateOptions.env(env); return template; }
From source file:org.onosproject.store.primitives.impl.PartitionedAsyncConsistentMap.java
@Override public CompletableFuture<Boolean> prepareAndCommit(MapTransaction<K, V> transaction) { Map<AsyncConsistentMap<K, V>, List<MapUpdate<K, V>>> updatesGroupedByMap = Maps.newIdentityHashMap(); transaction.updates().forEach(update -> { AsyncConsistentMap<K, V> map = getMap(update.key()); updatesGroupedByMap.computeIfAbsent(map, k -> Lists.newLinkedList()).add(update); });/*w w w . j a v a2 s .c o m*/ Map<AsyncConsistentMap<K, V>, MapTransaction<K, V>> transactionsByMap = Maps.transformValues( updatesGroupedByMap, list -> new MapTransaction<>(transaction.transactionId(), list)); return Tools .allOf(transactionsByMap.entrySet().stream().map(e -> e.getKey().prepareAndCommit(e.getValue())) .collect(Collectors.toList())) .thenApply(list -> list.stream().reduce(Boolean::logicalAnd).orElse(true)); }
From source file:com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService.java
@Override public void putWithTimestamps(String tableName, Multimap<Cell, Value> cellValues) throws KeyAlreadyExistsException { if (cellValues.isEmpty()) { return;/* www . java2 s.c o m*/ } Validate.isTrue(!tableName.equals(TransactionConstants.TRANSACTION_TABLE), TRANSACTION_ERROR); long lastTimestamp = -1; boolean allAtSameTimestamp = true; for (Value value : cellValues.values()) { long timestamp = value.getTimestamp(); Validate.isTrue(timestamp != Long.MAX_VALUE); Validate.isTrue(timestamp >= 0); if (lastTimestamp != -1 && timestamp != lastTimestamp) { allAtSameTimestamp = false; } lastTimestamp = timestamp; } if (allAtSameTimestamp) { Multimap<Cell, byte[]> cellValuesWithStrippedTimestamp = Multimaps.transformValues(cellValues, Value.GET_VALUE); Map<Cell, byte[]> putMap = Maps.transformValues(cellValuesWithStrippedTimestamp.asMap(), new Function<Collection<byte[]>, byte[]>() { @Override public byte[] apply(Collection<byte[]> input) { try { return Iterables.getOnlyElement(input); } catch (IllegalArgumentException e) { log.error( "Application tried to put multiple same-cell values in at same timestamp; attempting to perform last-write-wins, but ordering is not guaranteed."); return Iterables.getLast(input); } } }); put(tableName, putMap, lastTimestamp); return; } delegate.putWithTimestamps(tableName, cellValues); }