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:com.yammer.collections.azure.AbstractCollectionView.java

@SuppressWarnings("NullableProblems")
@Override
public Iterator<E> iterator() {
    return Iterables.transform(getBackingIterable(), typeExtractor).iterator();
}

From source file:org.jclouds.azure.storage.blob.blobstore.functions.CommonPrefixesToResourceMetadata.java

public Iterable<ResourceMetadata> apply(

        Iterable<String> prefixes) {
    return Iterables.transform(prefixes, new Function<String, ResourceMetadata>() {
        public ResourceMetadata apply(String from) {
            MutableResourceMetadata returnVal = new MutableResourceMetadataImpl();
            returnVal.setType(ResourceType.RELATIVE_PATH);
            returnVal.setName(from);// w w  w . j  a  va  2s. c om
            return returnVal;
        }
    });
}

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

@Inject
public DatasetModuleNameCompleter(final DatasetModuleClient datasetModuleClient, final CLIConfig cliConfig) {
    super(new Supplier<Collection<String>>() {
        @Override//from  w ww  .  ja  va2  s. c om
        public Collection<String> get() {
            try {
                List<DatasetModuleMeta> list = datasetModuleClient.list(cliConfig.getCurrentNamespace());
                return Lists.newArrayList(Iterables.transform(list, new Function<DatasetModuleMeta, String>() {
                    @Override
                    public String apply(DatasetModuleMeta input) {
                        return input.getName();
                    }
                }));
            } catch (IOException e) {
                return Lists.newArrayList();
            } catch (UnauthorizedException e) {
                return Lists.newArrayList();
            }
        }
    });
}

From source file:org.sonatype.nexus.orient.entity.action.BrowseEntitiesAction.java

public Iterable<T> execute(final ODatabaseDocumentTx db) {
    checkNotNull(db);/*from  w w  w  .ja  v a 2 s  .co m*/

    return Iterables.transform(adapter.browseDocuments(db), new Function<ODocument, T>() {
        @Nullable
        @Override
        public T apply(@Nullable final ODocument input) {
            return input != null ? adapter.readEntity(input) : null;
        }
    });
}

From source file:msi.gama.common.util.OldFileUtils.java

/**
 * Construct an absolute file path.//from  ww  w .j a  v a 2 s  .  co  m
 *
 * @param scope
 *            the scope
 * @param fp
 *            the fp
 * @param mustExist
 *            the must exist
 * @return the string
 * @throws GamaRuntimeException
 *             the gama runtime exception
 */
static public String constructAbsoluteFilePathAlternate(final IScope scope, final String fp,
        final boolean mustExist) throws GamaRuntimeException {
    String filePath = null;
    Iterable<String> baseDirectories = null;
    final IExperimentAgent a = scope.getExperiment();
    // final List<String> referenceDirectories = a.getWorkingPaths();

    try {
        baseDirectories = Iterables.transform(a.getWorkingPaths(), each -> {
            try {
                return withTrailingSep(URLDecoder.decode(each, "UTF-8"));
            } catch (final UnsupportedEncodingException e1) {
                return each;
            }
        });
        filePath = URLDecoder.decode(fp, "UTF-8");
    } catch (final UnsupportedEncodingException e1) {
        filePath = fp;
    }
    final GamaRuntimeException ex = new GamaRuntimeFileException(scope,
            "File denoted by " + filePath + " not found.");
    File file = null;
    if (FileUtils.isAbsolutePath(filePath)) {
        file = new File(filePath);
        if (file.exists() || !mustExist) {
            try {
                return file.getCanonicalPath();
            } catch (final IOException e) {
                e.printStackTrace();
                return file.getAbsolutePath();
            }
        }
        for (final String baseDirectory : baseDirectories) {
            file = new File(baseDirectory + removeRoot(filePath));
            if (file.exists()) {
                try {
                    return file.getCanonicalPath();
                } catch (final IOException e) {
                    e.printStackTrace();
                    return file.getAbsolutePath();
                }
            }
            ex.addContext(file.getAbsolutePath());
        }
    } else {
        for (final String baseDirectory : baseDirectories) {
            file = new File(baseDirectory + filePath);
            if (file.exists()) {
                try {
                    // We have to try if the test is necessary.
                    if (scope.getExperiment().isHeadless()) {
                        // if (GAMA.isInHeadLessMode()) {
                        return file.getAbsolutePath();
                    } else {
                        return file.getCanonicalPath();
                    }

                } catch (final IOException e) {
                    e.printStackTrace();
                    return file.getAbsolutePath();
                }
            }

            ex.addContext(file.getAbsolutePath());
        }
        // We havent found the file, but it may not exist. In that case, the
        // first directory is used as a reference.
        if (!mustExist) {
            try {
                return new File(Iterables.get(baseDirectories, 0) + filePath).getCanonicalPath();
            } catch (final IOException e) {
                throw ex;
            }
        }
    }

    throw ex;
}

From source file:org.jclouds.atmosonline.saas.blobstore.functions.ResourceMetadataListToDirectoryEntryList.java

public BoundedSet<DirectoryEntry> apply(org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> from) {

    return new BoundedHashSet<DirectoryEntry>(
            Iterables.transform(from, new Function<StorageMetadata, DirectoryEntry>() {
                public DirectoryEntry apply(StorageMetadata from) {
                    FileType type = (from.getType() == StorageType.FOLDER
                            || from.getType() == StorageType.RELATIVE_PATH) ? FileType.DIRECTORY
                                    : FileType.REGULAR;
                    return new DirectoryEntry(from.getProviderId(), type, from.getName());
                }//from ww  w  .j  a v a  2 s  .c o m

            }), from.getNextMarker());

}

From source file:org.sonar.batch.issue.DefaultProjectIssues.java

@Override
public Iterable<Issue> resolvedIssues() {
    return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(true)),
            new IssueTransformer());
}

From source file:org.apache.crunch.impl.spark.fn.PairFlatMapPairDoFn.java

@Override
public Iterable<Tuple2<K2, V2>> call(Iterator<Tuple2<K, V>> input) throws Exception {
    ctxt.initialize(fn);//from   w ww.  j  a va 2 s.com
    return Iterables.transform(
            new CrunchIterable<Pair<K, V>, Pair<K2, V2>>(fn,
                    Iterators.transform(input, GuavaUtils.<K, V>tuple2PairFunc())),
            GuavaUtils.<K2, V2>pair2tupleFunc());
}

From source file:org.apache.flex.compiler.problems.AmbiguousGotoTargetProblem.java

public AmbiguousGotoTargetProblem(IASNode site, Collection<LabeledStatementNode> gotoLabels) {
    super(site);/*from w  w  w .ja  va2  s.co m*/
    Iterable<String> locationStrings = Iterables.transform(gotoLabels,
            new Function<LabeledStatementNode, String>() {

                @Override
                public String apply(LabeledStatementNode targetLocation) {
                    return Integer.toString(targetLocation.getLine() + 1) + ":"
                            + Integer.toString(targetLocation.getColumn() + 1);
                }
            });
    targets = Joiner.on(", ").join(locationStrings);
}

From source file:com.android.build.gradle.managed.adaptor.NdkConfigAdaptor.java

@Nullable
@Override/*from w  w  w  .  j  a v  a  2 s  . c o m*/
public Collection<String> getLdLibs() {
    return Lists.newArrayList(Iterables.transform(ndkConfig.getLdLibs(), new Function<ManagedString, String>() {
        @Override
        public String apply(@Nullable ManagedString managedString) {
            return managedString == null ? null : managedString.getValue();
        }
    }));
}