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:adwords.axis.v201309.advancedoperations.UpdateSiteLinks.java

/**
 * Updates FeedItems for the Feed, setting line 1 description and line 2 description from the
 * contents of the feedItemDescriptions map.
 *
 * @param adWordsServices service locator for AdWords services
 * @param session the AdWords session to use for service calls
 * @param feedId the ID of the feed to update
 * @param line1Attribute the FeedAttribute for line 1 description
 * @param line2Attribute the FeedAttribute for line 2 description
 * @param feedItemDescriptions a map from feedItemId to a two-element array where item 0 is the
 *        line 1 description and item 1 is the line 2 description
 * @throws Exception/*from w w  w  .j av  a2 s .co  m*/
 */
private static void updateFeedItems(AdWordsServices adWordsServices, AdWordsSession session, Long feedId,
        FeedAttribute line1Attribute, FeedAttribute line2Attribute, Map<Long, String[]> feedItemDescriptions)
        throws Exception {
    FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);

    List<String> feedItemIds = Lists
            .newArrayList(Iterables.transform(feedItemDescriptions.keySet(), Functions.toStringFunction()));
    Selector itemSelector = new SelectorBuilder().fields("FeedId", "FeedItemId", "AttributeValues")
            // Limit FeedItems to the feed.
            .equalsId(feedId)
            // Limit FeedItems to the items in the feedItemDescriptions map.
            .in("FeedItemId", feedItemIds.toArray(new String[0])).build();

    FeedItem[] feedItems = feedItemService.get(itemSelector).getEntries();

    List<FeedItemOperation> itemOperations = Lists.newArrayListWithCapacity(feedItems.length);
    for (FeedItem feedItem : feedItems) {
        // Construct a FeedItemOperation that will set the line 1 and line 2
        // attribute values for this FeedItem.
        FeedItemAttributeValue[] itemAttributeValues = new FeedItemAttributeValue[2];

        FeedItemAttributeValue line1AttributeValue = new FeedItemAttributeValue();
        line1AttributeValue.setFeedAttributeId(line1Attribute.getId());
        line1AttributeValue.setStringValue(feedItemDescriptions.get(feedItem.getFeedItemId())[0]);
        itemAttributeValues[0] = line1AttributeValue;

        FeedItemAttributeValue line2AttributeValue = new FeedItemAttributeValue();
        line2AttributeValue.setFeedAttributeId(line2Attribute.getId());
        line2AttributeValue.setStringValue(feedItemDescriptions.get(feedItem.getFeedItemId())[1]);

        itemAttributeValues[1] = line2AttributeValue;
        feedItem.setAttributeValues(itemAttributeValues);

        FeedItemOperation operation = new FeedItemOperation();
        operation.setOperator(Operator.SET);
        operation.setOperand(feedItem);
        itemOperations.add(operation);
    }
    FeedItemReturnValue itemsUpdateReturnValue = feedItemService
            .mutate(itemOperations.toArray(new FeedItemOperation[0]));
    System.out.printf("Updated %d items%n", itemsUpdateReturnValue.getValue().length);
}

From source file:org.jclouds.joyent.cloudapi.v6_5.domain.Dataset.java

/**
 * If the value is a string, it will be quoted, as that's how json strings are represented.
 * //from   w w w  .  j a  va  2 s.co  m
 * @return key to a json literal of the value
 * @see #getRequirements
 * @see Json#fromJson
 */
public Map<String, String> getRequirementsAsJsonLiterals() {
    return Maps.transformValues(requirements, Functions.toStringFunction());
}

From source file:org.apache.brooklyn.container.location.docker.DockerJcloudsLocation.java

@Override
public Template buildTemplate(ComputeService computeService, ConfigBag config,
        Collection<JcloudsLocationCustomizer> customizers) {
    String loginUser = config.get(JcloudsLocation.LOGIN_USER);
    String loginPassword = config.get(JcloudsLocation.LOGIN_USER_PASSWORD);
    String loginKeyFile = config.get(JcloudsLocation.LOGIN_USER_PRIVATE_KEY_FILE);
    String loginKeyData = config.get(JcloudsLocation.LOGIN_USER_PRIVATE_KEY_DATA);

    Template template = super.buildTemplate(computeService, config, customizers);
    DockerTemplateOptions templateOptions = (DockerTemplateOptions) template.getOptions();
    Image image = template.getImage();
    List<String> env = MutableList.copyOf(templateOptions.getEnv());

    // Inject login credentials, if required
    Boolean injectLoginCredentials = config.get(INJECT_LOGIN_CREDENTIAL);
    if (injectLoginCredentials == null) {
        String imageDescription = image.getDescription();
        for (String regex : IMAGE_DESCRIPTION_REGEXES_REQUIRING_INJECTED_LOGIN_CREDS) {
            if (imageDescription != null && imageDescription.matches(regex)) {
                injectLoginCredentials = true;
                break;
            }//from  w w w . j av a2 s .c o  m
        }
    }
    if (Strings.isBlank(loginUser) && Strings.isBlank(loginPassword) && Strings.isBlank(loginKeyFile)
            && Strings.isBlank(loginKeyData)) {
        if (Boolean.TRUE.equals(injectLoginCredentials)) {
            loginUser = "root";
            loginPassword = Identifiers.makeRandomPassword(12);
            templateOptions.overrideLoginUser(loginUser);
            templateOptions.overrideLoginPassword(loginPassword);

            env.add("BROOKLYN_ROOT_PASSWORD=" + loginPassword);
        }
    }

    Entity context = validateCallerContext(config);
    Map<String, Object> containerEnv = MutableMap
            .copyOf(context.config().get(DockerContainer.CONTAINER_ENVIRONMENT));
    for (Map.Entry<String, String> entry : Maps.transformValues(containerEnv, Functions.toStringFunction())
            .entrySet()) {
        env.add(String.format("%s=%s", entry.getKey(), entry.getValue()));
    }
    templateOptions.env(env);

    return template;
}

From source file:org.jclouds.joyent.cloudapi.v6_5.domain.Dataset.java

/**
 * Contains a grouping of various minimum requirements for provisioning a machine with this
 * dataset. For example 'password' indicates that a password must be provided.
 * /*from   ww  w . jav  a  2 s.c  o  m*/
 * <h4>Note</h4>
 * 
 * requirements can contain arbitrarily complex values. If the value has structure, you should
 * use {@link #getRequirementsAsJsonLiterals}
 */
public Map<String, String> getRequirements() {
    return Maps.transformValues(requirements, Functions.compose(Functions.toStringFunction(), unquoteString));
}

From source file:com.eucalyptus.compute.common.internal.vm.VmCreateImageTask.java

/**
 * Instance matching criterion.// ww  w  .  j a v a2  s. com
 */
public static Criterion inState(final Set<CreateImageState> states) {
    return Restrictions.in("runtimeState.createImageTask.state",
            Lists.newArrayList(Iterables.transform(states, Functions.toStringFunction())));
}

From source file:com.facebook.buck.android.SmartDexingStep.java

@Override
public String getDescription(ExecutionContext context) {
    StringBuilder b = new StringBuilder();
    b.append(getShortName());/*from w ww  . ja  v  a  2s .c  o  m*/
    b.append(' ');

    Multimap<Path, Path> outputToInputs = outputToInputsSupplier.get();
    for (Path output : outputToInputs.keySet()) {
        b.append("-out ");
        b.append(output.toString());
        b.append("-in ");
        Joiner.on(':').appendTo(b,
                Iterables.transform(outputToInputs.get(output), Functions.toStringFunction()));
    }

    return b.toString();
}

From source file:com.googlecode.blaisemath.svg.BlaiseGraphicsTestApp.java

@Action
public void addDelegatingPointSet2() {
    Map<Integer, Point2D> points2 = Maps.newLinkedHashMap();
    for (int i = 1; i <= 10; i++) {
        points2.put(i, randomPoint());//from   ww w.ja v  a 2 s .c  o  m
    }
    final DelegatingPointSetGraphic<Integer, Graphics2D> bp = new DelegatingPointSetGraphic<Integer, Graphics2D>(
            MarkerRenderer.getInstance(), TextRenderer.getInstance());
    bp.addObjects(points2);
    bp.setDragEnabled(true);
    bp.getStyler().setLabelDelegate(Functions.toStringFunction());
    bp.getStyler().setLabelStyleDelegate(new Function<Integer, AttributeSet>() {
        AttributeSet r = new AttributeSet();

        public AttributeSet apply(Integer src) {
            r.put(Styles.TEXT_ANCHOR, Anchor.CENTER);
            r.put(Styles.FONT_SIZE, 5 + src.floatValue());
            return r;
        }
    });
    bp.getStyler().setStyleDelegate(new Function<Integer, AttributeSet>() {
        AttributeSet r = new AttributeSet();

        public AttributeSet apply(Integer src) {
            r.put(Styles.MARKER_RADIUS, src + 2);
            r.put(Styles.FILL, new Color((src * 10 + 10) % 255, (src * 20 + 25) % 255, (src * 30 + 50) % 255));
            r.put(Styles.STROKE, Colors.lighterThan(r.getColor(Styles.FILL)));
            return r;
        }
    });
    root1.addGraphic(bp);
}

From source file:brooklyn.entity.basic.BrooklynTaskTags.java

/** creates a tag suitable for marking a stream available on a task, but which might be GC'd */
public static WrappedStream tagForStreamSoft(String streamType, ByteArrayOutputStream stream) {
    MemoryUsageTracker.SOFT_REFERENCES.track(stream, stream.size());
    Maybe<ByteArrayOutputStream> weakStream = Maybe.softThen(stream, STREAM_GARBAGE_COLLECTED_MAYBE);
    return new WrappedStream(streamType, Suppliers.compose(Functions.toStringFunction(), weakStream),
            Suppliers.compose(Streams.sizeFunction(), weakStream));
}

From source file:com.google.jimfs.PathService.java

/**
 * Returns the URI for the given path. The given file system URI is the base against which the
 * path is resolved to create the returned URI.
 *//* w  ww.  j a  va 2  s .  c om*/
public URI toUri(URI fileSystemUri, JimfsPath path) {
    checkArgument(path.isAbsolute(), "path (%s) must be absolute", path);
    String root = String.valueOf(path.root());
    Iterable<String> names = Iterables.transform(path.names(), Functions.toStringFunction());
    return type.toUri(fileSystemUri, root, names);
}

From source file:com.facebook.buck.android.ApkBuilderStep.java

@Override
public String getDescription(ExecutionContext context) {
    return String.format(
            // TODO(mbolin): Make the directory that corresponds to $ANDROID_HOME a field that is
            // accessible via an AndroidPlatformTarget and insert that here in place of "$ANDROID_HOME".
            "java -classpath $ANDROID_HOME/tools/lib/sdklib.jar %s %s -v -u %s -z %s %s %s -f %s",
            "com.android.sdklib.build.ApkBuilderMain", pathToOutputApkFile,
            Joiner.on(' ').join(Iterables.transform(nativeLibraryDirectories, new Function<Path, String>() {
                @Override//  w w w .j  a  v a  2 s .c  om
                public String apply(Path s) {
                    return "-nf " + s;
                }
            })), Joiner.on(' ').join(Iterables.transform(zipFiles, Functions.toStringFunction())), resourceApk,
            Joiner.on(' ').join(Iterables.transform(assetDirectories, new Function<String, String>() {
                @Override
                public String apply(String s) {
                    return "-rf " + s;
                }
            })), dexFile);
}