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.onosproject.store.consistent.impl.ConsistentMapBackedJavaMap.java

@Override
public Set<java.util.Map.Entry<K, V>> entrySet() {
    return backingMap.entrySet().stream()
            .map(entry -> Maps.immutableEntry(entry.getKey(), entry.getValue().value()))
            .collect(Collectors.toSet());
}

From source file:com.chadekin.jadys.syntax.from.impl.FromClauseBuilderImpl.java

@Override
public void applyJoin(SqlLexical sqlLexical, String alias, String fullStatement) {
    if (JOIN_STATEMENTS.contains(sqlLexical)) {
        joinStatementTemp = Maps.immutableEntry(alias + JadysKeys.DOT, fullStatement);
    } else if (SqlLexical.ON == sqlLexical) {
        StringBuilder statement = new StringBuilder(joinStatementTemp.getValue()).append(JadysKeys.SPACE)
                .append(SqlLexical.ON).append(JadysKeys.SPACE).append(fullStatement);
        SqlExpressionItem expressionItem = new SqlExpressionItem();
        expressionItem.setParam(statement.toString());
        setSqlExpressionItem(expressionItem);
    }/*ww  w. j  av  a  2  s  .  com*/
}

From source file:io.airlift.drift.codec.internal.reflection.ReflectionThriftUnionCodec.java

@Override
public T read(TProtocolReader protocol) throws Exception {
    ProtocolReader reader = new ProtocolReader(protocol);
    reader.readStructBegin();/*from   w  w  w .j  a  v  a 2s  . c  o  m*/

    Map.Entry<Short, Object> data = null;
    Short fieldId = null;
    while (reader.nextField()) {
        checkState(fieldId == null, "Received Union with more than one value (seen id %s, now id %s)", fieldId,
                reader.getFieldId());

        fieldId = reader.getFieldId();

        // do we have a codec for this field
        ThriftCodec<?> codec = fields.get(fieldId);
        if (codec == null) {
            reader.skipFieldData();
        } else {
            // is this field readable
            ThriftFieldMetadata field = metadata.getField(fieldId);
            if (field.isWriteOnly() || field.getType() != THRIFT_FIELD) {
                reader.skipFieldData();
                continue;
            }

            // read the value
            Object value = reader.readField(codec);
            if (value == null) {
                continue;
            }

            data = Maps.immutableEntry(fieldId, value);
        }
    }
    reader.readStructEnd();

    // build the struct
    return constructStruct(data);
}

From source file:org.eclipse.sirius.common.ui.tools.internal.interpreter.VariableProposalProvider.java

@Override
public List<ContentProposal> getProposals(IInterpreter interpreter, ContentInstanceContext context) {
    final List<ContentProposal> proposals;
    if (context == null || !(interpreter instanceof VariableInterpreter)) {
        proposals = Collections.emptyList();
    } else {//  w w w  .ja va  2s  .  co  m
        if (context.getCurrentSelected() == null) {
            proposals = Collections.singletonList(getNewEmtpyExpression());
        } else {
            VariableInterpreter variableInterpreter = (VariableInterpreter) interpreter;
            // Transform Entry<String, Object> to Entry<String, String>
            Iterator<Entry<String, String>> variablesIterator = Iterators.transform(
                    variableInterpreter.getVariables().entrySet().iterator(),
                    new Function<Entry<String, Object>, Entry<String, String>>() {
                        public Map.Entry<String, String> apply(Map.Entry<String, Object> input) {
                            return Maps.immutableEntry(input.getKey(), input.getValue().toString());
                        };
                    });
            proposals = getProposals(context.getTextSoFar(), context.getCursorPosition(), variablesIterator);
        }
    }
    return proposals;
}

From source file:org.icgc.dcc.release.core.task.TaskExecutor.java

private static Collection<Entry<? extends Task, Optional<String>>> getSubmitTasks(JobContext jobContext,
        Collection<? extends Task> tasks) {
    val submitTasks = ImmutableList.<Entry<? extends Task, Optional<String>>>builder();
    for (val task : tasks) {
        if (task.getType() == TaskType.FILE_TYPE_PROJECT) {
            for (val projectName : jobContext.getProjectNames()) {
                submitTasks/* w  ww  . j av  a  2s  .  c  o  m*/
                        .add(Maps.immutableEntry(new ProjectTask(task, projectName), Optional.of(projectName)));
            }
        } else {
            submitTasks.add(Maps.immutableEntry(task, Optional.empty()));
        }
    }

    return submitTasks.build();
}

From source file:org.lanternpowered.server.service.pagination.LanternPaginationList.java

@SuppressWarnings("rawtypes")
@Override/*  w  ww  .  java  2 s  .c o m*/
public void sendTo(final MessageReceiver receiver) {
    checkNotNull(this.contents, "contents");
    checkNotNull(receiver, "source");
    this.service.registerCommandOnce();

    MessageReceiver realSource = receiver;
    while (realSource instanceof ProxySource) {
        realSource = ((ProxySource) realSource).getOriginalSource();
    }
    @SuppressWarnings("unchecked")
    PaginationCalculator calculator = new PaginationCalculator(this.linesPerPage);
    Iterable<Map.Entry<Text, Integer>> counts = StreamSupport.stream(this.contents.spliterator(), false)
            .map(input -> {
                int lines = calculator.getLines(receiver, input);
                return Maps.immutableEntry(input, lines);
            }).collect(Collectors.toList());

    Text title = this.title.orElse(null);
    if (title != null) {
        title = calculator.center(receiver, title, this.paginationSpacer);
    }

    ActivePagination pagination;
    if (this.contents instanceof List) { // If it started out as a list, it's probably reasonable to copy it to another list
        pagination = new ListPagination(receiver, calculator, ImmutableList.copyOf(counts), title,
                this.header.orElse(null), this.footer.orElse(null), this.paginationSpacer);
    } else {
        pagination = new IterablePagination(receiver, calculator, counts, title, this.header.orElse(null),
                this.footer.orElse(null), this.paginationSpacer);
    }

    this.service.getPaginationState(receiver, true).put(pagination);
    try {
        pagination.nextPage();
    } catch (CommandException e) {
        receiver.sendMessage(error(e.getText()));
    }
}

From source file:org.learningu.scheduling.util.bst.BstMap.java

private Set<Entry<K, V>> createEntrySet() {
    return new AbstractSet<Entry<K, V>>() {
        @Override/* w w w. ja va 2s  . c  o  m*/
        public Iterator<Entry<K, V>> iterator() {

            final BstInOrderPath<TreapNode<K, V>> startingPath = BstRangeOps.furthestPath(range, LEFT,
                    pathFactory(), root);
            final Iterator<BstInOrderPath<TreapNode<K, V>>> pathIterator = new AbstractLinkedIterator<BstInOrderPath<TreapNode<K, V>>>(
                    startingPath) {
                @Override
                protected BstInOrderPath<TreapNode<K, V>> computeNext(
                        BstInOrderPath<TreapNode<K, V>> previous) {
                    if (!previous.hasNext(RIGHT)) {
                        return null;
                    }
                    BstInOrderPath<TreapNode<K, V>> next = previous.next(RIGHT);
                    return range.contains(next.getTip().getKey()) ? next : null;
                }
            };
            return new Iterator<Entry<K, V>>() {
                K toRemove = null;

                @Override
                public boolean hasNext() {
                    return pathIterator.hasNext();
                }

                @Override
                public Entry<K, V> next() {
                    BstInOrderPath<TreapNode<K, V>> path = pathIterator.next();
                    TreapNode<K, V> tip = path.getTip();
                    toRemove = tip.getKey();
                    return Maps.immutableEntry(tip.getKey(), tip.getValue());
                }

                @Override
                public void remove() {
                    checkState(toRemove != null);
                    BstMap.this.remove(toRemove);
                    toRemove = null;
                }
            };
        }

        @Override
        public int size() {
            return BstMap.this.size();
        }
    };
}

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

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

From source file:com.facebook.buck.shell.WorkerToolDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params,
        final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {

    BuildRule rule = resolver.requireRule(args.exe);
    if (!(rule instanceof BinaryBuildRule)) {
        throw new HumanReadableException(
                "The 'exe' argument of %s, %s, needs to correspond to a " + "binary rule, such as sh_binary().",
                params.getBuildTarget(), args.exe.getFullyQualifiedName());
    }//from  www  .  ja  v a  2  s  . com

    Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER,
            params.getBuildTarget(), params.getCellRoots(), resolver);
    final ImmutableList<com.facebook.buck.rules.args.Arg> workerToolArgs = args.getStartupArgs().stream()
            .map(toArg::apply).collect(MoreCollectors.toImmutableList());

    ImmutableMap<String, String> expandedEnv = ImmutableMap
            .copyOf(FluentIterable.from(args.env.entrySet()).transform(input -> {
                try {
                    return Maps.immutableEntry(input.getKey(), MACRO_HANDLER.expand(params.getBuildTarget(),
                            params.getCellRoots(), resolver, input.getValue()));
                } catch (MacroException e) {
                    throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
                }
            }));

    int maxWorkers;
    if (args.maxWorkers.isPresent()) {
        // negative or zero: unlimited number of worker processes
        maxWorkers = args.maxWorkers.get() < 1 ? Integer.MAX_VALUE : args.maxWorkers.get();
    } else {
        // default is 1 worker process (for backwards compatibility)
        maxWorkers = 1;
    }

    return new DefaultWorkerTool(params, new SourcePathResolver(new SourcePathRuleFinder(resolver)),
            (BinaryBuildRule) rule, workerToolArgs, expandedEnv, maxWorkers,
            args.persistent.orElse(buckConfig.getBooleanValue(CONFIG_SECTION, CONFIG_PERSISTENT_KEY, false)));
}

From source file:me.lucko.luckperms.common.commands.generic.meta.MetaInfo.java

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args,
        String label, CommandPermission permission) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }//from  w w  w  .  j  a va2 s.c  om

    SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    Set<LocalizedNode> meta = new LinkedHashSet<>();

    // Collect data
    for (LocalizedNode node : holder.resolveInheritances()) {
        if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
            continue;
        }

        if (node.isPrefix()) {
            prefixes.add(Maps.immutableEntry(node.getPrefix().getKey(), node));
        } else if (node.isSuffix()) {
            suffixes.add(Maps.immutableEntry(node.getSuffix().getKey(), node));
        } else if (node.isMeta()) {
            meta.add(node);
        }
    }

    if (prefixes.isEmpty()) {
        Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.PREFIX, prefixes, sender, holder, label);
    }

    if (suffixes.isEmpty()) {
        Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.SUFFIX, suffixes, sender, holder, label);
    }

    if (meta.isEmpty()) {
        Message.META_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.META_HEADER.send(sender, holder.getFriendlyName());
        sendMetaMessage(meta, sender, holder, label);
    }

    return CommandResult.SUCCESS;
}