Example usage for com.google.common.collect Collections2 transform

List of usage examples for com.google.common.collect Collections2 transform

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 transform.

Prototype

public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function) 

Source Link

Document

Returns a collection that applies function to each element of fromCollection .

Usage

From source file:ezbake.groups.service.query.AuthorizationQuery.java

@Override
public Collection<String> transformToCachable(Set<Long> value) {
    return Collections2.transform(value, new Function<Long, String>() {
        @Nullable/*from   w  ww  . java2  s .  c o m*/
        @Override
        public String apply(Long item) {
            return Long.toString(item);
        }
    });
}

From source file:at.newmedialab.ldpath.model.fields.FieldMapping.java

/**
 * Get the values of this mapping for the context node passed as argument, transformed into the
 * datatype generated by the transformer.
 *
 * @param backend/*w  w w.  jav  a 2 s  .  c  o m*/
 * @param context
 * @return
 */
public Collection<T> getValues(final RDFBackend<Node> backend, final Node context,
        Map<Node, List<Node>> paths) {
    Function<Node, T> function = new Function<Node, T>() {
        @Override
        public T apply(Node input) {
            return transformer.transform(backend, input);
        }
    };

    return Collections2.transform(selector.select(backend, context, ImmutableList.of(context), paths),
            function);
}

From source file:org.spongepowered.common.command.SpongeHelpCommand.java

public static CommandSpec create() {
    return CommandSpec.builder().arguments(optional(string(Text.of("command"))))
            .description(Text.of("View a list of all commands."))
            .extendedDescription(Text.of(
                    "View a list of all commands. Hover over\n" + " a command to view its description. Click\n"
                            + " a command to insert it into your chat bar."))
            .executor((src, args) -> {
                Optional<String> command = args.getOne("command");
                if (command.isPresent()) {
                    Optional<? extends CommandMapping> mapping = SpongeImpl.getGame().getCommandManager()
                            .get(command.get(), src);
                    if (mapping.isPresent()) {
                        CommandCallable callable = mapping.get().getCallable();
                        Optional<? extends Text> desc = callable.getHelp(src);
                        if (desc.isPresent()) {
                            src.sendMessage(desc.get());
                        } else {
                            src.sendMessage(Text.of("Usage: /", command.get(), callable.getUsage(src)));
                        }/*  w  ww  .j a v a 2s . c om*/
                        return CommandResult.success();
                    }
                    throw new CommandException(Text.of("No such command: ", command.get()));
                }

                PaginationList.Builder builder = SpongeImpl.getGame().getServiceManager()
                        .provide(PaginationService.class).get().builder();
                builder.title(Text.builder("Available commands:").color(TextColors.DARK_GREEN).build());

                TreeSet<CommandMapping> commands = new TreeSet<>(COMMAND_COMPARATOR);
                commands.addAll(Collections2.filter(SpongeImpl.getGame().getCommandManager().getAll().values(),
                        input -> input.getCallable().testPermission(src)));
                builder.contents(ImmutableList
                        .copyOf(Collections2.transform(commands, input -> getDescription(src, input))));
                builder.sendTo(src);
                return CommandResult.success();
            }).build();
}

From source file:org.polarsys.reqcycle.impact.merge.Merger.java

public static MergeResult computeMergeResult(IFeaturedModelScope targetScope, IFeaturedModelScope refScope) {
    MergeResult result = new MergeResult();

    if (refScope instanceof ITrackingModelScope) {
        result.refAddedObjectIds.addAll(Collections2
                .transform(((ITrackingModelScope) refScope).getAddedObjects(), GET_FRAGMENT_FUNCTION));
        result.refRemovedObjectIds.addAll(((ITrackingModelScope) refScope).getRemovedObjectIds());
    }//from w  ww  .ja v a 2s .co m
    if (targetScope instanceof ITrackingModelScope) {
        result.targetAddedObjectIds.addAll(Collections2
                .transform(((ITrackingModelScope) targetScope).getAddedObjects(), GET_FRAGMENT_FUNCTION));
        result.targetRemovedObjectIds.addAll(((ITrackingModelScope) targetScope).getRemovedObjectIds());
    }

    return result;
}

From source file:org.openengsb.core.services.internal.security.model.PermissionSetData.java

@Override
public String toString() {
    Collection<String> children = Collections2.transform(permissionSets,
            new Function<PermissionSetData, String>() {
                @Override//from   w ww  .ja v a 2 s.c om
                public String apply(PermissionSetData input) {
                    return input.getName();
                };
            });
    return String.format("Set %s: %s, %s", name, children, permissions);
}

From source file:org.sonar.batch.rule.RuleFinderCompatibility.java

private Collection<Rule> byRepository(RuleQuery query) {
    return Collections2.transform(rules.findByRepository(query.getRepositoryKey()), ruleTransformer);
}

From source file:de.flapdoodle.guava.buildsupport.ExtractMarkdownFromCode.java

private static Collection<String> compactEmptyLines(Collection<String> lines) {
    return Collections2.filter(Collections2.transform(lines, new Function<String, String>() {

        @Override//  ww  w .  j  av a2  s  .  c  o m
        public String apply(String input) {
            if (input.trim().isEmpty()) {
                return "";
            }
            return input;
        }
    }), new Predicate<String>() {
        boolean lastOneWasEmpty = false;

        @Override
        public boolean apply(String input) {
            boolean addThisLine = true;

            if (input.isEmpty()) {
                if (lastOneWasEmpty)
                    addThisLine = false;
                lastOneWasEmpty = true;
            } else {
                lastOneWasEmpty = false;
            }
            return addThisLine;
        }
    });
}

From source file:net.sourceforge.ganttproject.io.GanttCSVOpen.java

private static Collection<String> getFieldNames(Enum[] fieldsEnum) {
    return Collections2.transform(Arrays.asList(fieldsEnum), new Function<Enum, String>() {
        @Override/*from w  w  w .j a v  a 2  s  .c  o  m*/
        public String apply(Enum input) {
            return input.toString();
        }
    });
}

From source file:com.dangdang.ddframe.job.cloud.scheduler.ha.ReconcileScheduledService.java

private void postReconcile() {
    log.info("Elastic Job - Reconcile: Posting {} tasks", remainingTasks.size());
    scheduler.reconcileTasks(/*from   ww  w.  j a v a2s  . c  o m*/
            Collections2.transform(remainingTasks, new Function<TaskContext, Protos.TaskStatus>() {
                @Override
                public Protos.TaskStatus apply(final TaskContext input) {
                    return Protos.TaskStatus.newBuilder()
                            .setTaskId(Protos.TaskID.newBuilder().setValue(input.getId()).build())
                            .setSlaveId(Protos.SlaveID.newBuilder().setValue(input.getSlaveId()).build())
                            .setState(Protos.TaskState.TASK_RUNNING).build();
                }
            }));
    latestReconcileMilliSeconds = System.currentTimeMillis();
    currentRePostInterval = currentRePostInterval < 0 ? retryIntervalUnit
            : currentRePostInterval * DEFAULT_MULTIPLIER;
    postTimes++;
    log.info("Elastic Job - Reconcile: Posted {} times, post time : {}, next trigger interval is {}", postTimes,
            latestReconcileMilliSeconds, currentRePostInterval);
}