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:org.ow2.proactive.scheduling.api.graphql.fetchers.TaskDataFetcher.java

@Override
protected Stream<Task> dataMapping(Stream<TaskData> dataStream) {
    // TODO Task progress not accessible from DB. It implies to establish a connection with
    // the SchedulerFrontend active object to get the value that is in the Scheduler memory

    return dataStream.map(taskData -> {
        TaskData.DBTaskId id = taskData.getId();

        return Task.builder().additionalClasspath(taskData.getAdditionalClasspath())
                .description(taskData.getDescription()).executionDuration(taskData.getExecutionDuration())
                .executionHostname(taskData.getExecutionHostName()).finishedTime(taskData.getFinishedTime())
                .genericInformation(taskData.getGenericInformation()).id(id.getTaskId())
                .inErrorTime(taskData.getInErrorTime()).javaHome(taskData.getJavaHome()).jobId(id.getJobId())
                .jvmArguments(taskData.getJvmArguments())
                .maxNumberOfExecution(taskData.getMaxNumberOfExecution()).name(taskData.getTaskName())
                .numberOfExecutionLeft(taskData.getNumberOfExecutionLeft())
                .numberOfExecutionOnFailureLeft(taskData.getNumberOfExecutionOnFailureLeft())
                .onTaskError(//from  w  w  w .ja  v  a  2  s .  c  om
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, taskData.getOnTaskErrorString()))
                .preciousLogs(taskData.isPreciousLogs()).preciousResult(taskData.isPreciousResult())
                .restartMode(RestartMode.getMode(taskData.getRestartModeId()).getDescription().toUpperCase())
                .resultPreview(taskData.getResultPreview()).runAsMe(taskData.isRunAsMe())
                .scheduledTime(taskData.getScheduledTime()).startTime(taskData.getStartTime())
                .status(taskData.getTaskStatus().name()).tag(taskData.getTag())
                .variables(taskData.getVariables().values().stream()
                        .map(taskDataVariable -> Maps.immutableEntry(taskDataVariable.getName(),
                                taskDataVariable.getValue()))
                        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
                .workingDir(taskData.getWorkingDir()).walltime(taskData.getWallTime()).build();
    });
}

From source file:org.cinchapi.common.util.NonBlockingHashMultimap.java

/**
 * {@inheritDoc}//from  w  ww .j ava  2s  . c o m
 * <p>
 * <strong>NOTE:</strong> This method deviates from the original
 * {@link Multimap} interface in that changes to the returned collection
 * WILL NOT update the underlying multimap and vice-versa.
 */
@Override
public Collection<Entry<K, V>> entries() {
    Set<Entry<K, V>> entries = new NonBlockingHashSet<Entry<K, V>>();
    for (K key : keySet()) {
        for (V value : get(key)) {
            entries.add(Maps.immutableEntry(key, value));
        }
    }
    return entries;
}

From source file:org.jooby.internal.spec.RouteCollector.java

private void importRoutes(final Type type, final Context ctx) {
    // compiled or parse?
    List<Map.Entry<Object, Node>> result = ctx.parseSpec(type).map(specs -> {
        List<Map.Entry<Object, Node>> nodes = new ArrayList<>();
        specs.forEach(spec -> nodes.add(Maps.immutableEntry(spec, null)));
        return nodes;
    }).orElseGet(() -> ctx.parse(type).map(unit -> new RouteCollector(true, owners).accept(unit, ctx))
            .orElse(Collections.emptyList()));
    owners.accept(type.getTypeName());//  www.  jav a 2  s  .  co m
    this.nodes.addAll(result);
}

From source file:com.infinities.keystone4j.identity.controller.impl.GroupV3ControllerImpl.java

@Override
public CollectionWrapper<Group> listGroupsForUser(String userid) throws Exception {
    Entry<String, String> entrys = Maps.immutableEntry("user_id", userid);
    FilterProtectedAction<Group> command = new FilterProtectedDecorator<Group>(
            new ListGroupsForUserAction(identityApi, tokenProviderApi, policyApi, userid), tokenProviderApi,
            policyApi, entrys);//from w  w w  . j a  va 2  s . co  m
    CollectionWrapper<Group> ret = command.execute(getRequest(), "name");
    return ret;
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLExpiringKeyValueService.java

@Override
public void multiPut(Map<String, ? extends Map<Cell, byte[]>> valuesByTable, final long timestamp,
        final long time, final TimeUnit unit) throws KeyAlreadyExistsException {
    Map<ResultSetFuture, String> resultSetFutures = Maps.newHashMap();
    for (Entry<String, ? extends Map<Cell, byte[]>> e : valuesByTable.entrySet()) {
        final String table = e.getKey();
        // We sort here because some key value stores are more efficient if you store adjacent keys together.
        NavigableMap<Cell, byte[]> sortedMap = ImmutableSortedMap.copyOf(e.getValue());

        Iterable<List<Entry<Cell, byte[]>>> partitions = partitionByCountAndBytes(sortedMap.entrySet(),
                getMultiPutBatchCount(), getMultiPutBatchSizeBytes(), table,
                CQLKeyValueServices.MULTIPUT_ENTRY_SIZING_FUNCTION);

        for (final List<Entry<Cell, byte[]>> p : partitions) {
            List<Entry<Cell, Value>> partition = Lists.transform(p,
                    new Function<Entry<Cell, byte[]>, Entry<Cell, Value>>() {
                        @Override
                        public Entry<Cell, Value> apply(Entry<Cell, byte[]> input) {
                            return Maps.immutableEntry(input.getKey(),
                                    Value.create(input.getValue(), timestamp));
                        }//w  w  w. j  a  v  a2s. co  m
                    });
            resultSetFutures.put(getPutPartitionResultSetFuture(table, partition, TransactionType.NONE,
                    CassandraKeyValueServices.convertTtl(time, unit)), table);
        }
    }

    for (Entry<ResultSetFuture, String> result : resultSetFutures.entrySet()) {
        ResultSet resultSet;
        try {
            resultSet = result.getKey().getUninterruptibly();
            resultSet.all();
        } catch (Throwable t) {
            throw Throwables.throwUncheckedException(t);
        }
        CQLKeyValueServices.logTracedQuery(
                getPutQuery(result.getValue(), CassandraKeyValueServices.convertTtl(time, unit)), resultSet,
                session, cqlStatementCache.NORMAL_QUERY);
    }
}

From source file:com.infinities.keystone4j.assignment.controller.action.roleassignment.AbstractRoleAssignmentAction.java

private Entry<Boolean, List<FormattedRoleAssignment>> limit(List<FormattedRoleAssignment> refs, Hints hints) {
    boolean NOT_LIMITED = false;
    boolean LIMITED = true;

    if (hints == null || hints.getLimit() == null) {
        return Maps.immutableEntry(NOT_LIMITED, refs);
    }//from  ww w  .j  av a2  s.c  o  m

    if (hints.getLimit().isTruncated()) {
        return Maps.immutableEntry(LIMITED, refs);
    }

    if (refs.size() > hints.getLimit().getLimit()) {
        return Maps.immutableEntry(LIMITED, refs.subList(0, hints.getLimit().getLimit()));
    }

    return Maps.immutableEntry(NOT_LIMITED, refs);
}

From source file:com.facebook.buck.distributed.DistributedBuildFileHashes.java

private static ListenableFuture<ImmutableMap<BuildRule, RuleKey>> ruleKeyComputation(ActionGraph actionGraph,
        final LoadingCache<ProjectFilesystem, DefaultRuleKeyBuilderFactory> ruleKeyFactories,
        ListeningExecutorService executorService) {
    List<ListenableFuture<Map.Entry<BuildRule, RuleKey>>> ruleKeyEntries = new ArrayList<>();
    for (final BuildRule rule : actionGraph.getNodes()) {
        ruleKeyEntries.add(executorService.submit(new Callable<Map.Entry<BuildRule, RuleKey>>() {
            @Override// w  w  w  .  j  a  va  2 s  .  co  m
            public Map.Entry<BuildRule, RuleKey> call() throws Exception {
                return Maps.immutableEntry(rule, ruleKeyFactories.get(rule.getProjectFilesystem()).build(rule));
            }
        }));
    }
    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:org.icgc.dcc.release.job.export.util.SchemaGenerator.java

private static Entry<String, String> parseSchemaDefinition(String schemaDefinition) {
    val keyValue = Lists.newArrayList(Splitters.COLON.split(schemaDefinition));
    checkState(keyValue.size() == 2,/*  ww  w  . java 2s . c om*/
            "Incorrect format of field definition. Expected <key> : <value>. Actual: %s", schemaDefinition);

    val fieldName = keyValue.get(0).trim();
    val value = keyValue.get(1).trim();

    return Maps.immutableEntry(fieldName, value);
}

From source file:me.lucko.luckperms.common.commands.impl.generic.permission.PermissionInfo.java

private static Map.Entry<Component, String> nodesToMessage(boolean temp, String filter,
        SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber,
        boolean console) {
    // parse the filter
    String nodeFilter = null;/*w  w w  .jav  a2 s.  c  o  m*/
    Map.Entry<String, String> contextFilter = null;

    if (filter != null) {
        int index = filter.indexOf('=');

        context: if (index != -1) {
            String key = filter.substring(0, index);
            if (key.equals(""))
                break context;

            String value = filter.substring(index + 1);
            if (value.equals(""))
                break context;

            contextFilter = Maps.immutableEntry(key, value);
        }

        if (contextFilter == null) {
            nodeFilter = filter;
        }
    }

    List<Node> l = new ArrayList<>();
    for (Node node : nodes) {
        if ((node.isGroupNode() && node.getValuePrimitive()) || node.isPrefix() || node.isSuffix()
                || node.isMeta())
            continue;

        // check against filters
        if (nodeFilter != null && !node.getPermission().startsWith(nodeFilter))
            continue;
        if (contextFilter != null
                && !node.getFullContexts().hasIgnoreCase(contextFilter.getKey(), contextFilter.getValue()))
            continue;
        if (temp != node.isTemporary())
            continue;

        l.add(node);
    }

    if (l.isEmpty()) {
        return Maps.immutableEntry(TextComponent.builder("None").color(TextColor.DARK_AQUA).build(), null);
    }

    int index = pageNumber - 1;
    List<List<Node>> pages = CommandUtils.divideList(l, 15);

    if (index < 0 || index >= pages.size()) {
        pageNumber = 1;
        index = 0;
    }

    List<Node> page = pages.get(index);

    TextComponent.Builder message = TextComponent.builder("");
    String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + l.size()
            + "&7 entries";
    if (filter != null) {
        title += " - filtered by &f\"" + filter + "\"&7)";
    } else {
        title += ")";
    }

    for (Node node : page) {
        String s = "&3> " + (node.getValuePrimitive() ? "&a" : "&c") + node.getPermission()
                + (console ? " &7(" + node.getValuePrimitive() + "&7)" : "")
                + CommandUtils.getAppendableNodeContextString(node) + "\n";
        if (temp) {
            s += "&2-    expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()) + "\n";
        }

        message.append(TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder()
                .applyDeep(makeFancy(holder, label, node)).build());
    }

    return Maps.immutableEntry(message.build(), title);
}

From source file:org.onosproject.store.primitives.impl.TranscodingAsyncConsistentTreeMap.java

@Override
public CompletableFuture<Map.Entry<String, Versioned<V1>>> pollLastEntry() {
    return backingMap.pollLastEntry().thenApply(
            entry -> Maps.immutableEntry(entry.getKey(), versionedValueTransform.apply(entry.getValue())));
}