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:org.obiba.opal.web.magma.Dtos.java

@SuppressWarnings("ConstantConditions")
public static ValueSetsDto.ValueDto.Builder asDto(@Nullable String link, @NotNull Value value,
        boolean filterBinary) {
    Function<Object, String> toString = filterBinary ? FilteredToStringFunction.INSTANCE
            : Functions.toStringFunction();

    ValueSetsDto.ValueDto.Builder valueDto = ValueSetsDto.ValueDto.newBuilder();
    if (!value.isNull()) {
        if (value.isSequence()) {
            int i = 0;
            for (Value v : value.asSequence().getValue()) {
                valueDto.addValues(asDto(link + "?pos=" + i, v, filterBinary));
                i++;//from  www  .  j a  v a 2s  .  c  om
            }
        } else {
            if (filterBinary && value.getValueType() == BinaryType.get()) {
                valueDto.setLength(value.getLength());
                valueDto.setLink(link);
            }
            String valueStr = toString.apply(value);
            valueDto.setValue(valueStr);
        }
    }

    return valueDto;
}

From source file:com.facebook.buck.event.listener.ChromeTraceBuildListener.java

@Subscribe
public void artifactFetchFinished(ArtifactCacheEvent.Finished finished) {
    ImmutableMap.Builder<String, String> argumentsBuilder = ImmutableMap.<String, String>builder()
            .put("success", Boolean.toString(finished.isSuccess()))
            .put("rule_key", finished.getRuleKey().toString());
    Optionals.putIfPresent(finished.getCacheResult().transform(Functions.toStringFunction()), "cache_result",
            argumentsBuilder);//w w w  . ja v a2  s  .  c  o  m

    writeChromeTraceEvent("buck", finished.getCategory(), ChromeTraceEvent.Phase.END, argumentsBuilder.build(),
            finished);
}

From source file:edu.mit.streamjit.util.bytecode.Method.java

public void dump(PrintWriter writer) {
    writer.write(Joiner.on(' ').join(modifiers()));
    writer.write(" ");
    writer.write(getType().getReturnType().toString());
    writer.write(" ");
    writer.write(getName());//w w  w. j av  a2s .c  om

    writer.write("(");
    String argString;
    if (isResolved())
        argString = Joiner.on(", ")
                .join(FluentIterable.from(arguments()).transform(new Function<Argument, String>() {
                    @Override
                    public String apply(Argument input) {
                        return input.getType() + " " + input.getName();
                    }
                }));
    else
        argString = Joiner.on(", ").join(
                FluentIterable.from(getType().getParameterTypes()).transform(Functions.toStringFunction()));
    writer.write(argString);
    writer.write(")");

    if (!isResolved()) {
        writer.write(";");
        writer.println();
        writer.flush();
        return;
    }

    writer.write(" {");
    writer.println();
    if (isMutable()) {
        for (LocalVariable v : localVariables()) {
            writer.write("\t");
            writer.write(v.toString());
            writer.write(";");
            writer.println();
        }
        if (!localVariables.isEmpty())
            writer.println();
    }
    for (BasicBlock b : basicBlocks()) {
        writer.write(b.getName());
        writer.write(": ");
        writer.println();

        for (Instruction i : b.instructions()) {
            writer.write("\t");
            writer.write(i.toString());
            writer.println();
        }
    }
    writer.write("}");
    writer.println();
    writer.flush();
}

From source file:org.killbill.billing.payment.dao.DefaultPaymentDao.java

@Override
public Pagination<PaymentTransactionModelDao> getByTransactionStatusAcrossTenants(
        final Iterable<TransactionStatus> transactionStatuses, final DateTime createdBeforeDate,
        final DateTime createdAfterDate, final Long offset, final Long limit) {

    final Collection<String> allTransactionStatus = ImmutableList
            .copyOf(Iterables.transform(transactionStatuses, Functions.toStringFunction()));
    final Date createdBefore = createdBeforeDate.toDate();
    final Date createdAfter = createdAfterDate.toDate();

    return paginationHelper.getPagination(TransactionSqlDao.class,
            new PaginationIteratorBuilder<PaymentTransactionModelDao, PaymentTransaction, TransactionSqlDao>() {
                @Override/*from   w  ww  .  j a  v a 2 s  . c  o m*/
                public Long getCount(final TransactionSqlDao sqlDao, final InternalTenantContext context) {
                    return sqlDao.getCountByTransactionStatusPriorDateAcrossTenants(allTransactionStatus,
                            createdBefore, createdAfter);
                }

                @Override
                public Iterator<PaymentTransactionModelDao> build(final TransactionSqlDao sqlDao,
                        final Long offset, final Long limit, final Ordering ordering,
                        final InternalTenantContext context) {
                    return sqlDao.getByTransactionStatusPriorDateAcrossTenants(allTransactionStatus,
                            createdBefore, createdAfter, offset, limit, ordering.toString());
                }
            }, offset, limit, null);
}

From source file:com.blackducksoftware.bdio.io.LinkedDataContext.java

/**
 * Expand a single value given a specific definition.
 *///  www.ja v  a  2  s  .  c  om
@Nullable
private Object expandValue(TermDefinition definition, @Nullable Object value) {
    if (value instanceof Iterable<?>) {
        // Accumulate expanded values into the appropriate collection
        Collection<Object> values = new LinkedList<>();
        for (Object obj : (Iterable<?>) value) {
            values.add(expandValue(definition, obj));
        }
        return definition.getContainer().copyOf(values);
    } else if (value instanceof Node) {
        // Expand the node and merge the types from the definition
        Map<String, Object> embeddedNode = expand((Node) value);
        embeddedNode.put(JsonLdKeyword.TYPE.toString(),
                FluentIterable.from(Iterables.concat(definition.getTypes(), ((Node) value).types()))
                        .transform(Functions.toStringFunction()).toList());
        return embeddedNode;
    } else if (value instanceof Map<?, ?>) {
        // First convert the map into a node and then expand that
        Map<String, Object> embeddedNode = expand(expandToNode((Map<?, ?>) value));
        // TODO FluentIterable.append is available (again?) in Guava 18.0
        Iterable<String> definitionTypes = FluentIterable.from(definition.getTypes())
                .transform(Functions.toStringFunction()).toList();
        if (embeddedNode.containsKey(JsonLdKeyword.TYPE.toString())) {
            embeddedNode.put(JsonLdKeyword.TYPE.toString(),
                    ImmutableList.builder().addAll(definitionTypes)
                            .addAll(FluentIterable
                                    .from((Iterable<?>) embeddedNode.get(JsonLdKeyword.TYPE.toString()))
                                    .transform(Functions.toStringFunction()))
                            .build());
        } else {
            embeddedNode.put(JsonLdKeyword.TYPE.toString(), definitionTypes);
        }
        return embeddedNode;
    } else if (value != null) {
        // Scalar, convert based on type
        return convertExpand(value, definition.getTypes());
    }
    return null;
}

From source file:com.android.monkeyrunner.MonkeyDevice.java

@MonkeyRunnerExported(doc = "Starts an Activity on the device by sending an Intent "
        + "constructed from the specified parameters.", args = { "uri", "action", "data", "mimetype",
                "categories", "extras", "component", "flags" }, argDocs = { "The URI for the Intent.",
                        "The action for the Intent.", "The data URI for the Intent",
                        "The mime type for the Intent.",
                        "A Python iterable containing the category names for the Intent.",
                        "A dictionary of extras to add to the Intent. Types of these extras "
                                + "are inferred from the python types of the values.",
                        "The component of the Intent.",
                        "An iterable of flags for the Intent."
                                + "All arguments are optional. The default value for each argument is null."
                                + "(see android.content.Intent)" })

public void startActivity(PyObject[] args, String[] kws) {
    ArgParser ap = JythonUtils.createArgParser(args, kws);
    Preconditions.checkNotNull(ap);// w w w . ja  v  a2 s . c o  m

    String uri = ap.getString(0, null);
    String action = ap.getString(1, null);
    String data = ap.getString(2, null);
    String mimetype = ap.getString(3, null);
    Collection<String> categories = Collections2.transform(JythonUtils.getList(ap, 4),
            Functions.toStringFunction());
    Map<String, Object> extras = JythonUtils.getMap(ap, 5);
    String component = ap.getString(6, null);
    int flags = ap.getInt(7, 0);

    impl.startActivity(uri, action, data, mimetype, categories, extras, component, flags);
}

From source file:com.eucalyptus.bootstrap.SystemBootstrapper.java

private static String printBanner() {
    String prefix = "\n\t";
    String headerHeader = "\n_________________________________________________________\n";
    String headerFormat = "  %-53.53s";
    String headerFooter = "\n_________________________________________________________\n";

    String banner = "Started Eucalyptus Version: " + singleton.getVersion() + "\n";
    banner += headerHeader + String.format(headerFormat, "System Bootstrap Configuration") + headerFooter;
    for (Bootstrap.Stage stage : Bootstrap.Stage.values()) {
        banner += prefix + stage.name() + SEP + stage.describe()
                .replaceAll("(\\w*)\\w\n", "\1\n" + prefix + stage.name() + SEP).replaceAll("^\\w* ", "");
    }//  w  ww .java2 s .  c om
    banner += headerHeader + String.format(headerFormat, "Component Bootstrap Configuration") + headerFooter;
    for (Component c : Components.list()) {
        if (c.getComponentId().isAvailableLocally()) {
            banner += c.getBootstrapper();
        }
    }
    banner += headerHeader + String.format(headerFormat, "Local Services") + headerFooter;
    for (Component c : Components.list()) {
        if (c.hasLocalService()) {
            ServiceConfiguration localConfig = c.getLocalServiceConfiguration();
            banner += prefix + c.getName() + SEP + localConfig.toString();
            banner += prefix + c.getName() + SEP + localConfig.getComponentId().toString();
            banner += prefix + c.getName() + SEP + localConfig.lookupState().toString();
        }
    }
    banner += headerHeader + String.format(headerFormat, "Detected Interfaces") + headerFooter;
    for (NetworkInterface iface : Internets.getNetworkInterfaces()) {
        banner += prefix + iface.getDisplayName() + SEP
                + Lists.transform(iface.getInterfaceAddresses(), Functions.toStringFunction());
        for (InetAddress addr : Lists.newArrayList(Iterators.forEnumeration(iface.getInetAddresses()))) {
            banner += prefix + iface.getDisplayName() + SEP + addr;
        }
    }
    LOG.info(banner);
    return banner;
}

From source file:com.android.monkeyrunner.MonkeyDevice.java

@MonkeyRunnerExported(doc = "Sends a broadcast intent to the device.", args = { "uri", "action", "data",
        "mimetype", "categories", "extras", "component", "flags" }, argDocs = { "The URI for the Intent.",
                "The action for the Intent.", "The data URI for the Intent", "The mime type for the Intent.",
                "An iterable of category names for the Intent.",
                "A dictionary of extras to add to the Intent. Types of these extras "
                        + "are inferred from the python types of the values.",
                "The component of the Intent.",
                "An iterable of flags for the Intent." + "All arguments are optional. " + ""
                        + "The default value for each argument is null."
                        + "(see android.content.Context.sendBroadcast(Intent))" })
public void broadcastIntent(PyObject[] args, String[] kws) {
    ArgParser ap = JythonUtils.createArgParser(args, kws);
    Preconditions.checkNotNull(ap);//from  www .j a va2s  . c  o m

    String uri = ap.getString(0, null);
    String action = ap.getString(1, null);
    String data = ap.getString(2, null);
    String mimetype = ap.getString(3, null);
    Collection<String> categories = Collections2.transform(JythonUtils.getList(ap, 4),
            Functions.toStringFunction());
    Map<String, Object> extras = JythonUtils.getMap(ap, 5);
    String component = ap.getString(6, null);
    int flags = ap.getInt(7, 0);

    impl.broadcastIntent(uri, action, data, mimetype, categories, extras, component, flags);
}

From source file:edu.harvard.med.screensaver.db.LibrariesDAOImpl.java

@Override
public Set<ScreenType> findScreenTypesForWells(Set<WellKey> wellKeys) {
    Set<String> wellIds = Sets.newHashSet(Iterables.transform(wellKeys, Functions.toStringFunction()));
    final HqlBuilder hql = new HqlBuilder().select("l", "screenType").distinctProjectionValues()
            .from(Well.class, "w").from("w", Well.library, "l").whereIn("w", "id", wellIds);
    List<ScreenType> screenTypes = runQuery(new Query<ScreenType>() {
        public List<ScreenType> execute(Session session) {
            return hql.toQuery(session, true).list();
        }/*from  w  w  w. ja va2 s . c  o m*/
    });
    return Sets.newTreeSet(screenTypes);
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

private String propertyDescription(ModelSchemaExtractionContext<?> parentContext, ModelProperty<?> property) {
    if (property.getDeclaredBy().size() == 1 && property.getDeclaredBy().contains(parentContext.getType())) {
        return String.format("property '%s'", property.getName());
    } else {//from www. ja  v a  2  s  .c  om
        ImmutableSortedSet<String> declaredBy = ImmutableSortedSet
                .copyOf(Iterables.transform(property.getDeclaredBy(), Functions.toStringFunction()));
        return String.format("property '%s' declared by %s", property.getName(),
                Joiner.on(", ").join(declaredBy));
    }
}