Example usage for com.google.common.collect Maps transformEntries

List of usage examples for com.google.common.collect Maps transformEntries

Introduction

In this page you can find the example usage for com.google.common.collect Maps transformEntries.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap,
        EntryTransformer<? super K, ? super V1, V2> transformer) 

Source Link

Document

Returns a view of a navigable map whose values are derived from the original navigable map's entries.

Usage

From source file:org.graylog2.alarmcallbacks.pagerduty.PagerDutyAlarmCallback.java

@Override
public Map<String, Object> getAttributes() {
    return Maps.transformEntries(configuration.getSource(),
            new Maps.EntryTransformer<String, Object, Object>() {
                @Override// www.  j  a  v  a 2  s  . co m
                public Object transformEntry(String key, Object value) {
                    if (CK_SERVICE_KEY.equals(key)) {
                        return "****";
                    }
                    return value;
                }
            });
}

From source file:org.apache.druid.query.aggregation.post.ExpressionPostAggregator.java

@Override
public Object compute(Map<String, Object> values) {
    // Maps.transformEntries is lazy, will only finalize values we actually read.
    final Map<String, Object> finalizedValues = Maps.transformEntries(values, (String k, Object v) -> {
        final Function<Object, Object> finalizer = finalizers.get(k);
        return finalizer != null ? finalizer.apply(v) : v;
    });/*from ww  w.ja va  2s.  com*/

    return parsed.eval(Parser.withMap(finalizedValues)).value();
}

From source file:com.android.build.gradle.internal.incremental.fixture.ClassEnhancement.java

private static Map<String, ClassLoader> setUpEnhancedClassLoaders(final ClassLoader mainClassLoader,
        final Map<String, File> compileOutputFolders, final boolean tracing) {
    return Maps.transformEntries(compileOutputFolders, new Maps.EntryTransformer<String, File, ClassLoader>() {
        @Override//ww  w . j  a  v  a 2s .  co  m
        public ClassLoader transformEntry(@Nullable String patch, @Nullable File compileOutputFolder) {
            Context context = InstrumentationRegistry.getContext();
            File optimizedDir = new ContextCompat().getCodeCacheDir(context);

            try {
                InputStream is = context.getAssets().open(compileOutputFolder.getPath() + "/classes.dex");
                File output;
                try {
                    File patchDir = new File(context.getDir("patches", Context.MODE_PRIVATE), patch);
                    patchDir.mkdir();
                    output = new File(patchDir, patch + ".dex");

                    Files.asByteSink(output).writeFrom(is);
                } finally {
                    is.close();
                }

                return new DexClassLoader(output.getAbsolutePath(), optimizedDir.getAbsolutePath(), null,
                        ClassEnhancement.class.getClassLoader());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}

From source file:com.google.api.client.discovery.RestDiscovery.java

@Override
public Map<String, OAuth2Scope> getOAuth2Scopes() {
    // Make sure we actually have some scopes to work with
    if (document.getAuth() == null || document.getAuth().getOauth2() == null
            || document.getAuth().getOauth2().getScopes() == null) {
        return Collections.emptyMap();
    }//from   ww w.j  a va2  s  .  co m

    return Maps.transformEntries(document.getAuth().getOauth2().getScopes(),
            new EntryTransformer<String, RestDescriptionAuthOauth2Scopes, OAuth2Scope>() {
                public OAuth2Scope transformEntry(String key, RestDescriptionAuthOauth2Scopes value) {
                    return new OAuth2Scope(key, value.getDescription());
                }
            });
}

From source file:org.apache.hadoop.hive.druid.serde.DruidGroupByQueryRecordReader.java

@Override
public boolean nextKeyValue() {
    // Results/*  w  w  w. j a v  a 2 s  . c o  m*/

    if (queryResultsIterator.hasNext()) {
        final Row row = queryResultsIterator.next();
        // currently druid supports only MapBasedRow as Jackson SerDe so it should safe to cast without check
        currentRow = (MapBasedRow) row;
        //@TODO move this out of here to org.apache.hadoop.hive.druid.serde.DruidSerDe
        currentEvent = Maps.transformEntries(currentRow.getEvent(), (key, value1) -> {
            if (timeExtractionFields.contains(key)) {
                return ISODateTimeFormat.dateTimeParser().parseMillis((String) value1);
            }
            if (intFormattedTimeExtractionFields.contains(key)) {
                return Integer.valueOf((String) value1);
            }
            return value1;
        });
        return true;
    }
    return false;
}

From source file:org.apache.beam.runners.spark.aggregators.metrics.WithNamedAggregatorsSupport.java

private Function<Map.Entry<String, Metric>, Map<String, Gauge>> toGauges() {
    return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {
        @Override/*from   w w w .  j  a v a  2s  .co  m*/
        public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
            final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators();
            final String parentName = entry.getKey();
            final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge());
            final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap();
            for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) {
                fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue());
            }
            return Maps.filterValues(fullNameGaugeMap, Predicates.notNull());
        }
    };
}

From source file:com.pentaho.big.data.bundles.impl.shim.hbase.mapping.MappingImpl.java

@Override
public Map<String, HBaseValueMetaInterface> getMappedColumns() {
    return Collections.unmodifiableMap(Maps.transformEntries(delegate.getMappedColumns(),
            new Maps.EntryTransformer<String, HBaseValueMeta, HBaseValueMetaInterface>() {
                @Override//  ww  w . j  a  v  a2  s. c o  m
                public HBaseValueMetaInterface transformEntry(String key, HBaseValueMeta value) {
                    if (value instanceof HBaseValueMetaInterface) {
                        return (HBaseValueMetaInterface) value;
                    }
                    return hBaseValueMetaInterfaceFactory.copy(value);
                }
            }));
}

From source file:com.feedzai.commons.sql.abstraction.engine.testconfig.DatabaseConfigurationUtil.java

/**
 * Loads the database configurations from the given source.
 *
 * @throws java.io.IOException/* w ww  .  j  a  va 2 s  .  com*/
 */
private void loadDatabaseConfigurations(InputStream is) throws IOException {
    final Properties properties = new Properties();
    properties.load(is);

    final Map<String, String> config = Maps.fromProperties(properties);
    final Map<String, Collection<String>> propsByVendor = groupByVendor(config);

    this.configs = Maps.transformEntries(propsByVendor,
            new Maps.EntryTransformer<String, Collection<String>, DatabaseConfiguration>() {
                @Override
                public DatabaseConfiguration transformEntry(String vendor, Collection<String> properties) {
                    return buildDatabaseConfiguration(vendor, properties, config);
                }
            });
}

From source file:google.registry.model.common.TimedTransitionProperty.java

/**
 * Converts the provided value map into the equivalent transition map, using transition objects
 * of the given TimedTransition subclass.  The value map must be sorted according to the natural
 * ordering of its DateTime keys, and keys cannot be earlier than START_OF_TIME.
 *//*w w w . j  a  va2 s. c o m*/
// NB: The Class<T> parameter could be eliminated by getting the class via reflection, but then
// the callsite cannot infer T, so unless you explicitly call this as .<V, T>fromValueMap() it
// will default to using just TimedTransition<V>, which fails at runtime.
private static <V, T extends TimedTransition<V>> NavigableMap<DateTime, T> makeTransitionMap(
        ImmutableSortedMap<DateTime, V> valueMap, final Class<T> timedTransitionSubclass) {
    checkArgument(Ordering.natural().equals(valueMap.comparator()),
            "Timed transition value map must have transition time keys in chronological order");
    return Maps.transformEntries(valueMap, new Maps.EntryTransformer<DateTime, V, T>() {
        // For each entry in the input value map, make the output map have an entry at the
        // corresponding time that points to a transition containing that time and that value.
        @Override
        public T transformEntry(DateTime transitionTime, V value) {
            checkArgument(!transitionTime.isBefore(START_OF_TIME),
                    "Timed transition times cannot be earlier than START_OF_TIME / Unix Epoch");
            T subclass = TypeUtils.instantiate(timedTransitionSubclass);
            ((TimedTransition<V>) subclass).transitionTime = transitionTime;
            subclass.setValue(value);
            return subclass;
        }
    });
}

From source file:org.locationtech.geogig.storage.datastream.v2_3.DataStreamValueSerializerV2_3.java

public @Override Map<String, Object> readMap(final DataInput in) throws IOException {
    final StringTable st = stringTable.get();
    final int[] keyIndices = readIntArray(in);
    if (keyIndices.length == 0) {
        return new HashMap<>();
    }//w w  w. j a  v  a  2 s. c o m
    final int[] offsets = readIntArray(in);
    final int dataSectionSize = readUnsignedVarInt(in);
    final byte[] rawData = new byte[dataSectionSize];
    in.readFully(rawData);

    Map<String, Integer> rawMap = new HashMap<>();
    for (int i = 0; i < keyIndices.length; i++) {
        String key = st.get(keyIndices[i]);
        rawMap.put(key, Integer.valueOf(offsets[i]));
    }

    EntryTransformer<String, Integer, Object> transformer = new EntryTransformer<String, Integer, Object>() {

        private final InternalInputStream byteStream = new InternalInputStream(rawData);

        public @Override Object transformEntry(String key, Integer dataOffset) {
            byteStream.setPosition(dataOffset.intValue());
            DataInput in = new DataInputStream(byteStream);
            try {
                FieldType type = FieldType.valueOf(in.readUnsignedByte());
                return decode(type, in);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
    return Maps.transformEntries(rawMap, transformer);
}