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

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

Introduction

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

Prototype

@CheckReturnValue
public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterable that applies function to each element of fromIterable .

Usage

From source file:org.estatio.dom.communicationchannel.EmailAddresses.java

@Programmatic
public EmailAddress findByEmailAddress(final CommunicationChannelOwner owner, final String emailAddress) {

    final List<CommunicationChannelOwnerLink> links = communicationChannelOwnerLinks
            .findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.EMAIL_ADDRESS);
    final Iterable<EmailAddress> emailAddresses = Iterables.transform(links,
            CommunicationChannelOwnerLink.Functions.communicationChannel(EmailAddress.class));
    final Optional<EmailAddress> emailAddressIfFound = Iterables.tryFind(emailAddresses,
            EmailAddress.Predicates.equalTo(emailAddress));
    return emailAddressIfFound.orNull();
}

From source file:co.cask.cdap.cli.completer.element.DatasetNameCompleter.java

@Inject
public DatasetNameCompleter(final DatasetClient datasetClient, final CLIConfig cliConfig) {
    super(new Supplier<Collection<String>>() {
        @Override//from   w ww.  jav a 2s  .  c o  m
        public Collection<String> get() {
            try {
                List<DatasetSpecificationSummary> list = datasetClient.list(cliConfig.getCurrentNamespace());
                return Lists.newArrayList(
                        Iterables.transform(list, new Function<DatasetSpecificationSummary, String>() {
                            @Override
                            public String apply(DatasetSpecificationSummary input) {
                                // TODO: hack to handle namespaced dataset names -- assumes there are no periods in dataset names
                                String[] tokens = input.getName().split("\\.");
                                return tokens[tokens.length - 1];
                            }
                        }));
            } catch (IOException e) {
                return Lists.newArrayList();
            } catch (UnauthorizedException e) {
                return Lists.newArrayList();
            }
        }
    });
}

From source file:com.blacklocus.jres.response.bulk.JresBulkReply.java

public Iterable<JresBulkItemResult> getResults() {
    return Iterables.transform(node().get("items"), new Function<JsonNode, JresBulkItemResult>() {
        @Override/*w  w  w.ja  v  a  2  s  .  co m*/
        public JresBulkItemResult apply(JsonNode resultEntry) {
            assert resultEntry.size() == 1;
            Map.Entry<String, JsonNode> result = resultEntry.fields().next();
            Item item = ObjectMappers.fromJson(result.getValue(), Item.class);
            return new JresBulkItemResult(result.getKey(), item);
        }
    });
}

From source file:google.registry.model.ofy.AugmentedDeleter.java

@Override
public Result<Void> entities(Iterable<?> entities) {
    handleDeletion(Iterables.transform(entities, OBJECTS_TO_KEYS));
    return delegate.entities(entities);
}

From source file:org.locationtech.geogig.storage.sqlite.SQLiteConflictsDatabase.java

@Override
public List<Conflict> getConflicts(String namespace, String pathFilter) {
    return Lists.newArrayList(Iterables.transform(get(namespace, pathFilter, cx), StringToConflict.INSTANCE));
}

From source file:org.apache.maven.model.building.Result.java

/**
 * Success with warnings./*from   w  w  w . j  a  v  a  2 s  .co m*/
 */
public static <T> Result<T> success(T model, Result<?>... results) {
    return success(model, Iterables.concat(Iterables.transform(Arrays.asList(results), GET_PROBLEMS)));
}

From source file:android.support.test.espresso.util.TreeIterables.java

/**
 * Creates an iterable that traverses the tree formed by the given root.
 *
 * Along with iteration order, the distance from the root element is also tracked.
 *
 * @param root the root view to track from.
 * @return An iterable of ViewAndDistance containing the view tree in a depth first order with
 *   the distance of a given node from the root.
 *//*from   www. j  a va  2 s  .  co m*/
public static Iterable<ViewAndDistance> depthFirstViewTraversalWithDistance(View root) {
    final DistanceRecordingTreeViewer<View> distanceRecorder = new DistanceRecordingTreeViewer<View>(root,
            VIEW_TREE_VIEWER);

    return Iterables.transform(depthFirstTraversal(root, distanceRecorder),
            new Function<View, ViewAndDistance>() {
                @Override
                public ViewAndDistance apply(View view) {
                    return new ViewAndDistance(view, distanceRecorder.getDistance(view));
                }
            });
}

From source file:com.google.devtools.kythe.extractors.shared.ExtractorUtils.java

/**
 * Creates fully populated FileInput protocol buffers based on a provided set of files.
 *
 * @param filePathToFileDatas map with file contents.
 * @return fully populated FileInput protos
 * @throws ExtractionException//from www  .j ava 2 s.c om
 */
public static List<FileData> convertBytesToFileDatas(final Map<String, byte[]> filePathToFileContents)
        throws ExtractionException {
    checkNotNull(filePathToFileContents);

    return Lists.newArrayList(
            Iterables.transform(filePathToFileContents.keySet(), new Function<String, FileData>() {
                @Override
                public FileData apply(String path) {
                    return createFileData(path, filePathToFileContents.get(path));
                }
            }));
}

From source file:net.hillsdon.reviki.configuration.PropertiesPerWikiConfiguration.java

public List<File> getOtherSearchIndexDirectories() {
    Iterable<WikiConfiguration> otherWikis = Iterables.filter(_deploymentConfiguration.getWikis(),
            Predicates.not(Predicates.<WikiConfiguration>equalTo(this)));
    return Lists.newArrayList(Iterables.transform(otherWikis, WikiConfiguration.TO_SEARCH_INDEX_DIR));
}

From source file:com.facebook.buck.step.CompositeStep.java

@Override
public String getDescription(final ExecutionContext context) {
    return Joiner.on(" && ").join(Iterables.transform(steps, new Function<Step, String>() {
        @Override//w ww .j a v  a2 s.c o  m
        public String apply(Step step) {
            return step.getDescription(context);
        }
    }));
}