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:ninja.leaping.permissionsex.backend.file.FileSubjectData.java

private static Set<Entry<String, String>> contextsFrom(ConfigurationNode node) {
    Set<Entry<String, String>> contexts = Collections.emptySet();
    ConfigurationNode contextsNode = node.getNode(KEY_CONTEXTS);
    if (contextsNode.hasMapChildren()) {
        contexts = ImmutableSet.copyOf(Collections2.transform(contextsNode.getChildrenMap().entrySet(), ent -> {
            return Maps.immutableEntry(ent.getKey().toString(), String.valueOf(ent.getValue().getValue()));
        }));//w  w w.  ja v  a 2  s .  c  o  m
    }
    return contexts;
}

From source file:gg.uhc.uhc.modules.commands.ModuleEntryConverter.java

@Override
public Map.Entry<String, Module> convert(String value) {
    Optional<Module> module = registry.get(value);

    if (!module.isPresent())
        throw new ValueConversionException("Invalid module id: " + value);

    return Maps.immutableEntry(value, module.get());
}

From source file:com.nesscomputing.db.postgres.embedded.EmbeddedPostgreSQLController.java

/**
 * Each schema set has its own database cluster.  The template1 database has the schema preloaded so that
 * each test case need only create a new database and not re-invoke Migratory.
 *//*from  w  w w .  j ava 2  s .c o  m*/
private synchronized static Cluster getCluster(URI baseUrl, String[] personalities) throws IOException {
    final Entry<URI, Set<String>> key = Maps.immutableEntry(baseUrl,
            (Set<String>) ImmutableSet.copyOf(personalities));

    Cluster result = CLUSTERS.get(key);
    if (result != null) {
        return result;
    }

    result = new Cluster(EmbeddedPostgreSQL.start());

    final DBI dbi = new DBI(result.getPg().getTemplateDatabase());
    final Migratory migratory = new Migratory(new MigratoryConfig() {
    }, dbi, dbi);
    migratory.addLocator(new DatabasePreparerLocator(migratory, baseUrl));

    final MigrationPlan plan = new MigrationPlan();
    int priority = 100;

    for (final String personality : personalities) {
        plan.addMigration(personality, Integer.MAX_VALUE, priority--);
    }

    migratory.dbMigrate(plan);

    result.start();

    CLUSTERS.put(key, result);
    return result;
}

From source file:com.continuuity.weave.internal.appmaster.RunnableContainerRequest.java

/**
 * Remove a resource request and return it.
 * @return The {@link Resource} and {@link Collection} of {@link RuntimeSpecification} or
 *         {@code null} if there is no more request.
 *///from w ww  . j ava 2  s. c  om
Map.Entry<Resource, ? extends Collection<RuntimeSpecification>> takeRequest() {
    Map.Entry<Resource, Collection<RuntimeSpecification>> next = Iterators.getNext(requests, null);
    return next == null ? null : Maps.immutableEntry(next.getKey(), ImmutableList.copyOf(next.getValue()));
}

From source file:de.cosmocode.commons.RandomOrdering.java

@Override
public int compare(T left, T right) {
    if (Objects.equal(left, right)) {
        // compare(x, y)==0) == (x.equals(y)
        return 0;
    } else {/*from w w  w . j  a  va  2s.  co  m*/
        // will either return a cached value or compute a new one
        return values.get(Maps.immutableEntry(left, right));
    }
}

From source file:io.atomix.rest.resources.PrimitiveResource.java

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)/*  w  w  w  . j av  a2s .c om*/
public Response getPrimitives() {
    Map<String, PrimitiveInfo> primitivesInfo = primitives.getPrimitives(type).stream()
            .map(info -> Maps.immutableEntry(info.name(), new PrimitiveInfo(info.name(), info.type().name())))
            .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
    return Response.ok(primitivesInfo).build();
}

From source file:ninja.leaping.permissionsex.data.SubjectCache.java

private SubjectCache(final String type, final SubjectCache existing, final DataStore dataStore) {
    this.type = type;
    this.dataStore = dataStore;
    this.defaultIdentifier = Maps.immutableEntry(PermissionsEx.SUBJECTS_DEFAULTS, type);
    cache = CacheBuilder.newBuilder().maximumSize(512).build(
            CacheLoader.from(identifier -> dataStore.getData(type, identifier, clearListener(identifier))));
    if (existing != null) {
        this.listeners = existing.listeners;
        existing.cache.asMap().forEach((k, v) -> {
            try {
                listeners.call(k, getData(k, null));
            } catch (ExecutionException e) {
                // TODO: Not ignore this somehow? Add a listener in to the backend?
            }//from  w  w w.  j  a va  2s.  c  o  m
        });
    } else {
        this.listeners = new CacheListenerHolder<>();
    }
}

From source file:org.renyan.leveldb.impl.WriteBatchImpl.java

@Override
public WriteBatchImpl delete(byte[] key) {
    Preconditions.checkNotNull(key, "key is null");
    batch.add(Maps.immutableEntry(Slices.wrappedBuffer(key), (Slice) null));
    approximateSize += 6 + key.length;//from  w w w. j  a v a2s .co m
    return this;
}

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

@Override
public Map<String, byte[]> get(String namespace, Collection<String> keys,
        @Nullable CacheStatistics cacheStatistics) {
    Map<String, byte[]> ret = Maps.newHashMap();
    for (String key : keys) {
        byte[] data = map.get(Maps.immutableEntry(namespace, key));
        LOG.trace("%s getting %s:%s=%s", this, namespace, key, data);
        if (data != null) {
            ret.put(key, data);//from w w  w  . j a  v a 2 s  . co m
        }
    }
    return ret;
}

From source file:me.lucko.luckperms.bukkit.model.ChildPermissionProvider.java

public void setup() {
    ImmutableMap.Builder<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap
            .builder();/*w w w .  ja va 2s.com*/

    for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
        // handle true
        Map<String, Boolean> trueChildren = new HashMap<>();
        resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false);
        trueChildren.remove(permission.getName(), true);
        if (!trueChildren.isEmpty()) {
            permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true),
                    ImmutableMap.copyOf(trueChildren));
        }

        // handle false
        Map<String, Boolean> falseChildren = new HashMap<>();
        resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false);
        falseChildren.remove(permission.getName(), false);
        if (!falseChildren.isEmpty()) {
            permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false),
                    ImmutableMap.copyOf(falseChildren));
        }
    }

    this.permissions = permissions.build();
}