Example usage for com.google.common.base Functions toStringFunction

List of usage examples for com.google.common.base Functions toStringFunction

Introduction

In this page you can find the example usage for com.google.common.base Functions toStringFunction.

Prototype

public static Function<Object, String> toStringFunction() 

Source Link

Document

Returns a function that calls toString() on its argument.

Usage

From source file:de.cosmocode.palava.ipc.json.custom.php.explorer.Commands.java

@Override
public void execute(IpcCall call, Map<String, Object> result) throws IpcCommandExecutionException {
    final UtilityList<Object> packageNames = call.getArguments().getList("packages");

    final Renderer renderer = rendererProvider.get();

    final Classpath classpath = Reflection.defaultClasspath();
    final Function<Object, String> toString = Functions.toStringFunction();
    final Packages packages = classpath.restrictTo(Iterables.transform(packageNames, toString));
    final Iterable<Class<? extends IpcCommand>> commands = Iterables.transform(packages.filter(filter),
            Reflection.asSubclass(IpcCommand.class));

    renderer.value(commands, CommandRenderer.INSTANCE);
    result.put("commands", renderer.build());
}

From source file:google.registry.model.JsonMapBuilder.java

public <T> JsonMapBuilder putListOfStrings(String name, @Nullable Iterable<T> value) {
    map.put(name, value == null ? Collections.EMPTY_LIST
            : FluentIterable.from(value).transform(Functions.toStringFunction()).toList());
    return this;
}

From source file:com.ninja_squad.core.presentation.Option.java

/**
 * Creates a new option from its value and the <code>toString</code> function to set its label
 * @param value the value of the option//from   w ww  .j  a  v a 2s .c o m
 * @return the created option
 * @see #forValue(Object, Function)
 */
public static <V> Option<V> forValue(@Nonnull V value) {
    return forValue(value, Functions.toStringFunction());
}

From source file:org.sosy_lab.cpachecker.cfa.types.c.CFunctionType.java

@Override
public String toString() {
    return toASTString(Strings.nullToEmpty(getName()), Functions.toStringFunction());
}

From source file:brooklyn.util.text.StringFunctions.java

/** provided here as a convenience; prefer {@link Functions#toStringFunction()} */
public static Function<Object, String> toStringFunction() {
    return Functions.toStringFunction();
}

From source file:io.bazel.rules.closure.webfiles.server.ListingPage.java

void serve(final Webpath webpath) throws IOException {
    response.setContentType(MediaType.HTML_UTF_8);
    response.setPayload(TOFU.newRenderer(ListingSoyInfo.LISTING)
            .setData(new SoyMapData(ListingSoyInfo.ListingSoyTemplateInfo.LABEL, config.get().getLabel(),
                    ListingSoyInfo.ListingSoyTemplateInfo.PATHS,
                    new SoyListData(FluentIterable.from(webpaths).filter(new Predicate<Webpath>() {
                        @Override
                        public boolean apply(Webpath path) {
                            return path.startsWith(webpath);
                        }/*w  ww .ja v a 2 s . c o m*/
                    }).transform(Functions.toStringFunction()))))
            .render().getBytes(StandardCharsets.UTF_8));
}

From source file:com.google.devtools.build.lib.query2.engine.FunctionExpression.java

@Override
public String toString() {
    return function.getName() + "("
            + Joiner.on(", ").join(Iterables.transform(args, Functions.toStringFunction())) + ")";
}

From source file:com.google.errorprone.bugpatterns.threadsafety.AbstractLockMethodChecker.java

private static String formatLockString(Set<GuardedByExpression> locks) {
    ImmutableList<String> sortedUnhandled = FluentIterable.from(locks).transform(Functions.toStringFunction())
            .toSortedList(Ordering.natural());
    return Joiner.on(", ").join(sortedUnhandled);
}

From source file:de.faustedition.template.TemplateRepresentationFactory.java

public TemplateRepresentation create(String path, ClientInfo client, Map<String, Object> model) {
    path = path.replaceAll("^/+", "").replaceAll("/+$", "");
    final Language language = client.getPreferredLanguage(SUPPORTED_LANGUAGES);
    final Locale locale = (language == null ? Locale.GERMAN : new Locale(language.getName()));

    Template template;/*from  w w w  .j  av  a2  s. co m*/
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Getting template for '{}' (locale: '{}')", path, locale);
        }
        template = configuration.getTemplate(path + ".ftl", locale);
        Preconditions.checkNotNull(template, "Cannot find template for " + path);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }

    model.put("roles", Lists.transform(client.getRoles(), Functions.toStringFunction()));

    final ResourceBundle messages = ResourceBundle.getBundle("messages", locale);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Putting message resource bundle '{}' into model (requested locale '{}')",
                messages.getLocale(), locale);
    }
    model.put("message", messages);

    final SortedMap<String, String> textTableOfContents = new TreeMap<String, String>();
    /* TODO add toc
    for (Map.Entry<FaustURI, String> tocEntry : textManager.tableOfContents().entrySet()) {
       final String textUriPath = tocEntry.getKey().getPath();
       final String textName = textUriPath.substring("/text/".length(), textUriPath.length() - ".xml".length());
       textTableOfContents.put(textName, tocEntry.getValue());
    }
    model.put("textToc", textTableOfContents);
      */
    TemplateRepresentation representation = new TemplateRepresentation(template, model, MediaType.TEXT_HTML);
    representation.setLanguages(Collections.singletonList(language));

    return representation;
}

From source file:com.example.listsync.ListRepository.java

private List<String> toStringList(List<CheckItem> download) {
    return Lists.transform(download, Functions.toStringFunction());
}