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.facebook.buck.distributed.DistBuildFileHashes.java

private static ListenableFuture<ImmutableMap<BuildRule, RuleKey>> ruleKeyComputation(ActionGraph actionGraph,
        final LoadingCache<ProjectFilesystem, DefaultRuleKeyFactory> ruleKeyFactories,
        ListeningExecutorService executorService) {
    List<ListenableFuture<Map.Entry<BuildRule, RuleKey>>> ruleKeyEntries = new ArrayList<>();
    for (final BuildRule rule : actionGraph.getNodes()) {
        ruleKeyEntries.add(executorService.submit(() -> Maps.immutableEntry(rule,
                ruleKeyFactories.get(rule.getProjectFilesystem()).build(rule))));
    }/*from  www .  ja va  2  s  .  c om*/
    ListenableFuture<List<Map.Entry<BuildRule, RuleKey>>> ruleKeyComputation = Futures
            .allAsList(ruleKeyEntries);
    return Futures.transform(ruleKeyComputation,
            new Function<List<Map.Entry<BuildRule, RuleKey>>, ImmutableMap<BuildRule, RuleKey>>() {
                @Override
                public ImmutableMap<BuildRule, RuleKey> apply(List<Map.Entry<BuildRule, RuleKey>> input) {
                    return ImmutableMap.copyOf(input);
                }
            }, executorService);
}

From source file:com.facebook.buck.jvm.java.autodeps.JavaDepsFinder.java

public static JavaDepsFinder createJavaDepsFinder(BuckConfig buckConfig, final CellPathResolver cellNames,
        ObjectMapper objectMapper, BuildEngineBuildContext buildContext, ExecutionContext executionContext,
        BuildEngine buildEngine) {//  w  w  w . j a  v a  2  s  .  c  o m
    Optional<String> javaPackageMappingOption = buckConfig.getValue(BUCK_CONFIG_SECTION,
            "java-package-mappings");
    ImmutableSortedMap<String, BuildTarget> javaPackageMapping;
    if (javaPackageMappingOption.isPresent()) {
        Stream<Map.Entry<String, BuildTarget>> entries = Splitter.on(',').omitEmptyStrings()
                .withKeyValueSeparator("=>").split(javaPackageMappingOption.get()).entrySet().stream()
                // returns the key of the entry ending in `.` if it does not do so already.
                .map(entry -> {
                    String originalKey = entry.getKey().trim();
                    // If the key corresponds to a Java package (not an entity), then make sure that it
                    // ends with a `.` so the prefix matching will work as expected in
                    // findProviderForSymbolFromBuckConfig(). Note that this heuristic could be a bit
                    // tighter.
                    boolean appearsToBeJavaPackage = !originalKey.endsWith(".")
                            && CharMatcher.javaUpperCase().matchesNoneOf(originalKey);
                    String key = appearsToBeJavaPackage ? originalKey + "." : originalKey;
                    BuildTarget buildTarget = BuildTargetParser.INSTANCE.parse(entry.getValue().trim(),
                            BuildTargetPatternParser.fullyQualified(), cellNames);
                    return Maps.immutableEntry(key, buildTarget);
                });
        javaPackageMapping = ImmutableSortedMap.copyOf(
                (Iterable<Map.Entry<String, BuildTarget>>) entries::iterator, Comparator.reverseOrder());
    } else {
        javaPackageMapping = ImmutableSortedMap.of();
    }

    JavaBuckConfig javaBuckConfig = buckConfig.getView(JavaBuckConfig.class);
    JavacOptions javacOptions = javaBuckConfig.getDefaultJavacOptions();
    JavaFileParser javaFileParser = JavaFileParser.createJavaFileParser(javacOptions);

    return new JavaDepsFinder(javaPackageMapping, javaFileParser, objectMapper, buildContext, executionContext,
            buildEngine);
}

From source file:net.slashies.phpBridge.ProtocolConstants.java

private static Stream<Map.Entry<Long, String>> entryStream() {
    return Arrays.stream(ProtocolConstants.class.getFields()).sequential()
            .filter(f -> Modifier.isPublic(f.getModifiers())).filter(f -> Modifier.isStatic(f.getModifiers()))
            .filter(f -> Modifier.isStatic(f.getModifiers())).filter(f -> f.getType().equals(int.class))
            .map(f -> {/*from w  w w  .jav a2s . c o m*/
                try {
                    return Maps.immutableEntry(Long.valueOf(f.getInt(null)), f.getName());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
}

From source file:org.apache.hadoop.hive.accumulo.columns.ColumnEncoding.java

public static Entry<ColumnEncoding, ColumnEncoding> getMapEncoding(String columnEncoding) {
    int index = columnEncoding.indexOf(AccumuloHiveConstants.COLON);
    if (-1 == index) {
        throw new IllegalArgumentException(
                "Serialized column encoding did not contain a pair of encodings to split");
    }/*from ww  w.j  a  va2  s  .co m*/

    String encoding1 = columnEncoding.substring(0, index), encoding2 = columnEncoding.substring(index + 1);

    return Maps.immutableEntry(get(encoding1), get(encoding2));
}

From source file:me.lucko.luckperms.sponge.service.storage.SubjectStorage.java

public Map.Entry<String, SubjectStorageModel> loadFromFile(String collectionName, String subjectName)
        throws IOException {
    checkContainer();/*from ww  w .  ja  v a 2s. c o  m*/
    File collection = new File(container, collectionName);
    if (!collection.exists()) {
        return null;
    }

    File subject = new File(collection, subjectName + ".json");
    return Maps.immutableEntry(subjectName, loadFromFile(subject).getValue());
}

From source file:ninja.leaping.permissionsex.backend.AbstractDataStore.java

@Override
public final Iterable<Map.Entry<String, ImmutableSubjectData>> getAll(final String type) {
    Objects.requireNonNull(type, "type");
    return Iterables.transform(getAllIdentifiers(type),
            input -> Maps.immutableEntry(input, getData(type, input, null)));
}

From source file:me.lucko.luckperms.common.commands.impl.misc.ApplyEditsCommand.java

private static Map.Entry<Set<Node>, Set<Node>> diff(Set<Node> before, Set<Node> after) {
    // entries in before but not after are being removed
    // entries in after but not before are being added

    Set<Node> added = new HashSet<>(after);
    added.removeAll(before);//from   www.j a va2 s .  c o  m

    Set<Node> removed = new HashSet<>(before);
    removed.removeAll(after);

    return Maps.immutableEntry(added, removed);
}

From source file:com.palantir.atlasdb.keyvalue.impl.KeyValueServices.java

public static Collection<Map.Entry<Cell, Value>> toConstantTimestampValues(
        final Collection<Map.Entry<Cell, byte[]>> cells, final long timestamp) {
    return Collections2.transform(cells, new Function<Map.Entry<Cell, byte[]>, Map.Entry<Cell, Value>>() {
        @Override/*  www.jav  a2s. c om*/
        public Map.Entry<Cell, Value> apply(Map.Entry<Cell, byte[]> entry) {
            return Maps.immutableEntry(entry.getKey(), Value.create(entry.getValue(), timestamp));
        }
    });
}

From source file:org.icgc.dcc.download.server.config.RecordsStatsServiceConfig.java

private static Entry<? extends DownloadDataType, ? extends Integer> parseEntry(String line) {
    val parts = Splitters.TAB.splitToList(line);
    val partsNum = parts.size();
    checkState(partsNum == 2, "Malformed records weights file. Expected 2 columns, but got %s", partsNum);
    val type = DownloadDataType.valueOf(parts.get(0));
    val weight = Integer.valueOf(parts.get(1));

    return Maps.immutableEntry(type, weight);
}

From source file:me.lucko.luckperms.common.commands.group.GroupListMembers.java

private static <T extends Comparable<T>> void sendResult(Sender sender, List<HeldPermission<T>> results,
        Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label,
        int page) {
    results = new ArrayList<>(results);
    results.sort(HeldPermissionComparator.normal());

    int pageIndex = page - 1;
    List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);

    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;//from   w w  w  . ja v  a2  s .c  o  m
        pageIndex = 0;
    }

    List<HeldPermission<T>> content = pages.get(pageIndex);

    List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream()
            .map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp))
            .collect(Collectors.toList());

    // send header
    headerMessage.send(sender, page, pages.size(), results.size());

    for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
        String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils
                .getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), ent.getValue().asNode());
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder()
                .applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin()))
                .build();
        sender.sendMessage(message);
    }
}