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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static <K, V> Entry<K, V> immutableEntry(@Nullable K key, @Nullable V value) 

Source Link

Document

Returns an immutable map entry with the specified key and value.

Usage

From source file:com.appenginefan.toolkit.persistence.PersistenceAdapter.java

@Override
public List<Entry<String, T>> scanReverse(String start, String end, int max) {
    List<Entry<String, T>> result = Lists.newArrayList();
    for (Entry<String, S> entry : backend.scanReverse(start, end, max)) {
        T value = null;/*from  www.j a  v a  2s  .  c  o  m*/
        if (entry.getValue() != null) {
            value = makeType(entry.getValue());
        }
        result.add(Maps.immutableEntry(entry.getKey(), value));
    }
    return result;
}

From source file:ninja.leaping.permissionsex.backend.memory.MemoryDataStore.java

@Override
public CompletableFuture<ImmutableSubjectData> setDataInternal(String type, String identifier,
        ImmutableSubjectData data) {//from w w  w .  j  a va  2  s  . co  m
    if (track) {
        this.data.put(Maps.immutableEntry(type, identifier), data);
    }

    return CompletableFuture.completedFuture(data);
}

From source file:io.atlassian.fugue.extras.ImmutableMaps.java

/**
 * Builds an immutable map from the given iterable, with key derived from the
 * application of the iterable to the keyTransformer, and value derived from
 * the application of the iterable to the valueTransformer.
 * <p>//from ww w .  j a va  2  s  .  co m
 * <code>null</code> value is allowed and will be passed to the keyTransformer
 * and valueTransformer. However, if either the keyTransformer or the
 * valueTransformer returns <code>null</code> for an entry, the entry is
 * ignored. If keyTransformer returns the same key for multiple entries,
 * {@link java.lang.IllegalArgumentException} will be thrown.
 *
 * @param <T> the input type
 * @param <K> the key type
 * @param <V> the value type
 * @param from the iterable we use as the source
 * @param keyTransformer transform keys
 * @param valueTransformer transform values
 * @return the transformed map
 */
public static <T, K, V> ImmutableMap<K, V> toMap(Iterable<T> from,
        final Function<? super T, ? extends K> keyTransformer,
        final Function<? super T, ? extends V> valueTransformer) {
    return toMap(com.google.common.collect.Iterables.transform(from,
            entry -> Maps.immutableEntry(keyTransformer.apply(entry), valueTransformer.apply(entry))));
}

From source file:com.nesscomputing.cache.NonEvictingJvmCacheProvider.java

@Override
public Map<String, Boolean> add(String namespace, Collection<CacheStore<byte[]>> stores,
        @Nullable CacheStatistics cacheStatistics) {
    final Map<String, Boolean> result = Maps.newHashMap();

    for (CacheStore<byte[]> entry : stores) {
        LOG.trace("%s setting %s:%s", this, namespace, entry.getKey());
        Entry<String, String> key = Maps.immutableEntry(namespace, entry.getKey());
        byte[] data = entry.getData();
        byte[] old;
        if (data != null) {
            old = map.putIfAbsent(key, data);
        } else {//ww w.  j ava 2  s .  com
            old = null;
        }
        result.put(entry.getKey(), old == null);
    }
    return result;
}

From source file:org.apache.provisionr.amazon.core.ImageTable.java

static <K, V> Iterable<Map.Entry<K, V>> zip(Iterable<K> first, Iterable<V> second) {
    checkArgument(Iterables.size(first) == Iterables.size(second), "iterables don't have the same size");

    final Iterator<K> iterator = first.iterator();
    return newArrayList(transform(second, new Function<V, Map.Entry<K, V>>() {
        @Override//  w w  w  .j  a v  a 2s. c om
        public Map.Entry<K, V> apply(V input) {
            return Maps.immutableEntry(iterator.next(), input);
        }
    }));
}

From source file:com.google.devtools.build.lib.syntax.ListComprehension.java

public void add(Expression loopVar, Expression listExpression) {
    lists.add(Maps.immutableEntry(new LValue(loopVar), listExpression));
}

From source file:com.github.benmanes.caffeine.cache.testing.CacheGenerator.java

/** Returns a lazy stream so that the test case is GC-able after use. */
public Stream<Entry<CacheContext, Cache<Integer, Integer>>> generate() {
    return combinations().stream().map(this::newCacheContext).filter(this::isCompatible).map(context -> {
        Cache<Integer, Integer> cache = newCache(context);
        populate(context, cache);// ww w.  ja  v  a2 s .  c  o  m
        return Maps.immutableEntry(context, cache);
    });
}

From source file:com.palantir.common.collect.MapEntries.java

public static <K, V1, V2> EntryTransformer<K, V1, V2> entryTransformerFromFun(
        final Function<Entry<K, V1>, V2> f) {
    return new EntryTransformer<K, V1, V2>() {
        @Override//www.ja  v  a 2s . c o m
        public V2 transformEntry(K k, V1 v1) {
            return f.apply(Maps.immutableEntry(k, v1));
        }
    };
}

From source file:me.lucko.luckperms.common.dependencies.DependencyManager.java

public static void loadDependencies(LuckPermsPlugin plugin, Set<StorageType> storageTypes) {
    plugin.getLog().info("Loading dependencies...");

    List<Dependency> dependencies = new ArrayList<>();
    for (StorageType storageType : storageTypes) {
        dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType));
    }/*from  w ww .  j  a v a2 s  . co  m*/

    if (plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
        dependencies.add(Dependency.JEDIS);
    }

    plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());

    File data = new File(plugin.getDataDirectory(), "lib");
    data.mkdirs();

    // Download files.
    List<Map.Entry<Dependency, File>> toLoad = new ArrayList<>();
    for (Dependency dependency : dependencies) {
        try {
            toLoad.add(Maps.immutableEntry(dependency, downloadDependency(plugin, data, dependency)));
        } catch (Throwable e) {
            plugin.getLog().severe("Exception whilst downloading dependency " + dependency.name());
            e.printStackTrace();
        }
    }

    // Load classes.
    for (Map.Entry<Dependency, File> e : toLoad) {
        try {
            loadJar(plugin, e.getValue(), e.getKey().getTestClass());
        } catch (Throwable e1) {
            plugin.getLog().severe("Failed to load jar for dependency " + e.getKey().name());
            e1.printStackTrace();
        }
    }
}

From source file:me.lucko.luckperms.contexts.WorldCalculator.java

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
    UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
    worldCache.put(internal, e.getPlayer().getWorld().getName());
    pushUpdate(e.getPlayer(), Maps.immutableEntry(WORLD_KEY, e.getFrom().getName()),
            Maps.immutableEntry(WORLD_KEY, e.getPlayer().getWorld().getName()));
}