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.obeonetwork.dsl.uml2.design.tests.automation.common.ModelChangeRecorder.java

public ImmutableListMultimap<EClass, EObject> changedObjectsPerType() {
    Iterable<EObject> changedObjects = Iterables.transform(changes, Notifications.toChangedEObject);
    return EObjects.perType(changedObjects);
}

From source file:gg.uhc.flagcommands.tab.WorldTabComplete.java

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args,
        String toComplete, String[] others) {
    return StringUtil.copyPartialMatches(toComplete, Iterables.transform(Bukkit.getWorlds(), WORLD_NAME),
            Lists.<String>newArrayList());
}

From source file:com.cloudera.cdk.data.filesystem.FileSystemView.java

@Override
public DatasetReader<E> newReader() {
    final Iterable<Path> directories;
    if (dataset.getDescriptor().isPartitioned()) {
        directories = Iterables.transform(partitionIterator(), new Function<Key, Path>() {
            private final Path rootDirectory = fsDataset.getDirectory();
            private final PathConversion convert = new PathConversion();

            @Override/*w  w  w . j  a  va  2  s . com*/
            public Path apply(Key key) {
                if (key != null) {
                    return new Path(rootDirectory, convert.fromKey(key));
                } else {
                    throw new DatasetException("[BUG] Null partition");
                }
            }
        });
    } else {
        directories = Lists.newArrayList(fsDataset.getDirectory());
    }

    return new MultiFileDatasetReader<E>(fsDataset.getFileSystem(),
            new PathIterator(fsDataset.getFileSystem(), directories), dataset.getDescriptor());
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.AllCatalogItemsInOrg.java

@Override
public Iterable<? extends CatalogItem> apply(Org from) {
    return Iterables.concat(Iterables.transform(allCatalogsInOrg.apply(from),
            new Function<Catalog, Iterable<? extends CatalogItem>>() {
                @Override/*  www . ja v a 2  s. c om*/
                public Iterable<? extends CatalogItem> apply(Catalog from) {
                    return allCatalogItemsInCatalog.apply(from);
                }

            }));
}

From source file:com.facebook.buck.apple.FrameworkPath.java

public static FrameworkPath fromString(BuildTarget target, String string) {
    Path path = Paths.get(string);

    String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString();

    if (firstElement.startsWith("$")) { // NOPMD - length() > 0 && charAt(0) == '$' is ridiculous
        Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement);
        if (sourceTree.isPresent()) {
            return ImmutableFrameworkPath.builder().setSourceTreePath(
                    new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()))).build();
        } else {/* w  w  w  .  j  a v  a  2  s  . c om*/
            throw new HumanReadableException(String.format(
                    "Unknown SourceTree: %s in target: %s. Should be one of: %s", firstElement, target,
                    Joiner.on(',')
                            .join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()),
                                    new Function<PBXReference.SourceTree, String>() {
                                        @Override
                                        public String apply(PBXReference.SourceTree input) {
                                            return "$" + input.toString();
                                        }
                                    }))));
        }
    } else {
        return ImmutableFrameworkPath.builder()
                .setSourcePath(new BuildTargetSourcePath(target, Paths.get(string))).build();
    }
}

From source file:uk.ac.stfc.isis.ibex.configserver.configuration.ConfigInfo.java

/**
 * Reduces a list of ConfigInfo objects to a list of their names only.
 * //from  www.j  a v a  2  s . co m
 * @param infos The list of ConfigInfos
 * @return The list of config names
 */
public static Collection<String> names(Collection<ConfigInfo> infos) {
    if (infos == null) {
        return Collections.emptyList();
    }

    return Lists.newArrayList(Iterables.transform(infos, new Function<ConfigInfo, String>() {
        @Override
        public String apply(ConfigInfo info) {
            return info.name();
        }
    }));
}

From source file:com.facebook.buck.cxx.CxxCompilationDatabaseEntry.java

public CxxCompilationDatabaseEntry(String directory, String file, ImmutableList<String> args) {
    this.directory = directory;
    this.file = file;
    this.args = args;
    this.command = Joiner.on(' ').join(Iterables.transform(args, Escaper.SHELL_ESCAPER));
}

From source file:io.crate.operation.collect.RowsTransformer.java

public static Iterable<Row> toRowsIterable(CollectInputSymbolVisitor<?> docInputSymbolVisitor,
        RoutedCollectPhase collectPhase, Iterable<?> iterable) {
    WhereClause whereClause = collectPhase.whereClause();
    if (whereClause.noMatch()) {
        return Collections.emptyList();
    }/*from w w  w .  j a va 2 s .  com*/

    CollectInputSymbolVisitor.Context ctx = docInputSymbolVisitor
            .extractImplementations(collectPhase.toCollect());
    OrderBy orderBy = collectPhase.orderBy();
    if (orderBy != null) {
        for (Symbol symbol : orderBy.orderBySymbols()) {
            docInputSymbolVisitor.process(symbol, ctx);
        }
    }

    Input<Boolean> condition;
    if (whereClause.hasQuery()) {
        assert DataTypes.BOOLEAN.equals(whereClause.query().valueType());
        //noinspection unchecked  whereClause().query() is a symbol of type boolean so it must become Input<Boolean>
        condition = (Input<Boolean>) docInputSymbolVisitor.process(whereClause.query(), ctx);
    } else {
        condition = Literal.BOOLEAN_TRUE;
    }

    @SuppressWarnings("unchecked")
    Iterable<Row> rows = Iterables.filter(
            Iterables.transform(iterable,
                    new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.docLevelExpressions())),
            InputCondition.asPredicate(condition));

    if (orderBy == null) {
        return rows;
    }
    return sortRows(Iterables.transform(rows, Row.MATERIALIZE), collectPhase);
}

From source file:com.metamx.common.parsers.CSVParser.java

public CSVParser(final Optional<String> listDelimiter) {
    this.listDelimiter = listDelimiter.isPresent() ? listDelimiter.get() : Parsers.DEFAULT_LIST_DELIMITER;
    this.listSplitter = Splitter.on(this.listDelimiter);
    this.valueFunction = new Function<String, Object>() {
        @Override/*from   w  w w .j  a v a  2s  .  c o m*/
        public Object apply(String input) {
            if (input.contains(CSVParser.this.listDelimiter)) {
                return Lists.newArrayList(
                        Iterables.transform(listSplitter.split(input), ParserUtils.nullEmptyStringFunction));
            } else {
                return ParserUtils.nullEmptyStringFunction.apply(input);
            }
        }
    };
}

From source file:org.jclouds.s3.blobstore.functions.ResourceToBucketList.java

public ListBucketResponse apply(PageSet<? extends StorageMetadata> list) {

    Iterable<ObjectMetadata> contents = Iterables
            .transform(Iterables.filter(list, new Predicate<StorageMetadata>() {

                public boolean apply(StorageMetadata input) {
                    return input.getType() == StorageType.BLOB;
                }//from  w  w w. ja  v  a 2 s. c om

            }), new Function<StorageMetadata, ObjectMetadata>() {

                public MutableObjectMetadata apply(StorageMetadata from) {
                    return blob2ObjectMd.apply((BlobMetadata) from);
                }

            });

    Set<String> commonPrefixes = Sets
            .newLinkedHashSet(Iterables.transform(Iterables.filter(list, new Predicate<StorageMetadata>() {

                public boolean apply(StorageMetadata input) {
                    return input.getType() == StorageType.RELATIVE_PATH;
                }

            }), new Function<StorageMetadata, String>() {

                public String apply(StorageMetadata from) {
                    return from.getName();
                }

            }));
    return new ListBucketResponseImpl(null, contents, null, null, list.getNextMarker(), 0, "/",
            list.getNextMarker() != null, commonPrefixes);
}