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:kn.uni.gis.dataimport.Main.java
private static void insertData(SQLFacade sqlConnection, final String tableName, final List<String> readLines) throws SQLException { // Mapping from id -> multiple (parsed) lines Multimap<String, List<String>> index = Multimaps .index(Lists.transform(readLines, new Function<String, List<String>>() { @Override//from w w w .ja va2 s . c o m public List<String> apply(String input) { ArrayList<String> newArrayList = Lists .newArrayList(Splitter.on("\t").trimResults().split(input)); newArrayList.remove(newArrayList.size() - 1); return newArrayList; } }), new Function<List<String>, String>() { @Override public String apply(List<String> input) { return input.get(ID_INDEX); } }); // Collapse now to a mapping id -> one line Map<String, List<String>> collapsedValues = Maps.transformValues(index.asMap(), new Function<Collection<List<String>>, List<String>>() { @Override public List<String> apply(Collection<List<String>> input) { List<String> toReturn = Lists.newArrayList(); // set id List<String> firstLine = input.iterator().next(); toReturn.add(firstLine.get(0)); // set coordinates StringBuilder stringBuilder = new StringBuilder(); for (List<String> ret : input) { stringBuilder.append(ret.get(1)); stringBuilder.append(" "); stringBuilder.append(ret.get(2)); stringBuilder.append(","); } String coords = stringBuilder.toString(); // add additional line data for (int i = 5; i < firstLine.size(); i++) { toReturn.add("'" + firstLine.get(i).replaceAll("'", "''") + "'"); } // delete last ',' and add GeoInformation as last column toReturn.add(GeoColumn.getGeoColumn(tableName) .getGeoInsertionSQL(coords.substring(0, coords.lastIndexOf(',')))); return toReturn; } }); List<String> toexecute = Lists.newArrayList(); for (Map.Entry<String, List<String>> entry : collapsedValues.entrySet()) { toexecute.add(String.format("insert into \"%s\" values (%s);", tableName, Joiner.on(",").join(entry.getValue()))); } sqlConnection.executeBatch(toexecute.toArray(new String[toexecute.size()])); }
From source file:com.twitter.common.stats.NumericStatExporter.java
/** * Starts the stat exporter./* w w w . j av a2 s.c om*/ * * @param shutdownRegistry Shutdown hook registry to allow the exporter to cleanly halt. */ public void start(ShutdownRegistry shutdownRegistry) { long intervalSecs = exportInterval.as(Time.SECONDS); executor.scheduleAtFixedRate(exporter, intervalSecs, intervalSecs, TimeUnit.SECONDS); shutdownRegistry.addAction(new Command() { @Override public void execute() { stop(); exportSink.execute(Maps.transformValues(Maps.uniqueIndex(Stats.getNumericVariables(), GET_NAME), SAMPLE_AND_READ_STAT)); } }); }
From source file:com.google.devtools.build.skyframe.InMemoryGraphImpl.java
@Override public Map<SkyKey, SkyValue> getValues() { return Collections .unmodifiableMap(Maps.transformValues(nodeMap, new Function<InMemoryNodeEntry, SkyValue>() { @Override/* ww w . j a v a 2 s. co m*/ public SkyValue apply(InMemoryNodeEntry entry) { return entry.toValue(); } })); }
From source file:org.apache.fluo.api.client.AbstractSnapshotBase.java
@Override public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) { Map<RowColumn, Bytes> bytesMap = get(rowColumns); return Maps.transformValues(bytesMap, b -> b.toString()); }
From source file:com.facebook.swift.codec.ArrayField.java
public Map<Short, List<Short>> getMapShortList() { if (mapShortArray == null) { return null; }//from w w w . j a va 2 s. c o m return Maps.transformValues(mapShortArray, shortArrayAsList()); }
From source file:ai.grakn.migration.sql.SQLMigrator.java
/** * Convert values to be valid - removing nulls and changing to supported types * @param data data to make valid/*from w ww . j ava 2 s. co m*/ * @return valid data */ private Map<String, Object> convertToValidValues(Map<String, Object> data) { data = Maps.filterValues(data, Objects::nonNull); data = Maps.transformValues(data, this::convertToSupportedTypes); return data; }
From source file:io.airlift.drift.codec.ArrayField.java
public Map<Short, List<Short>> getMapShortList() { if (mapShortArray == null) { return null; }// w ww .j a v a 2 s .com return Maps.transformValues(mapShortArray, Shorts::asList); }
From source file:org.onosproject.cluster.LeadershipService.java
/** * Returns the candidate nodes for each topic. * * @return A mapping from topics to corresponding list of candidates. * @deprecated 1.6.0 Goldeneye release. Replace usages with {@link #getLeadership(String)} *///from w w w . j av a2s.c o m @Deprecated default Map<String, List<NodeId>> getCandidates() { return ImmutableMap .copyOf(Maps.transformValues(getLeaderBoard(), v -> ImmutableList.copyOf(v.candidates()))); }
From source file:org.spongepowered.common.config.type.GlobalConfig.java
public Map<String, Predicate<InetAddress>> getIpSets() { return ImmutableMap .copyOf(Maps.transformValues(this.ipSets, new Function<List<IpSet>, Predicate<InetAddress>>() { @Nullable//from w w w. ja va2 s.com @Override public Predicate<InetAddress> apply(List<IpSet> input) { return Predicates.and(input); } })); }
From source file:com.google.template.soy.data.internal.AbstractDict.java
@Override @Nonnull//from w w w . j a va2 s.co m public final Map<String, ? extends SoyValue> asResolvedJavaStringMap() { return Maps.transformValues(asJavaStringMap(), Transforms.RESOLVE_FUNCTION); }