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.opentestsystem.authoring.testspecbank.domain.EnumNamesAsString.java

public static <T extends Enum> String[] NAME_VALUES_AS_STRING(final T[] enumValues) {
    return Iterables.toArray(Iterables.transform(Lists.newArrayList(enumValues), new Function<T, String>() {
        @Override//w w  w. j  av a  2 s . c  o  m
        public String apply(final T enumIn) {
            if (enumIn != null) {
                return enumIn.name();
            }
            return "";
        }
    }), String.class);
}

From source file:it.anyplace.sync.core.utils.BlockUtils.java

public static String hashBlocks(List<BlockInfo> blocks) {
    return BaseEncoding.base16().encode(Hashing.sha256()
            .hashBytes(Joiner.on(",").join(Iterables.transform(blocks, new Function<BlockInfo, String>() {
                @Override// w w w  . j  a  v a  2s  .c  om
                public String apply(BlockInfo input) {
                    return input.getHash();
                }
            })).getBytes()).asBytes());
}

From source file:org.openhab.binding.amazondashbutton.internal.pcap.PcapUtil.java

/**
 * Returns all Pcap network interfaces relying on {@link Pcaps#findAllDevs()}.
 *
 * @return A {@link Iterable} of all {@link PcapNetworkInterfaceWrapper}s
 *///from w ww. j  av a  2 s .c  o  m
public static Iterable<PcapNetworkInterfaceWrapper> getAllNetworkInterfaces() {
    try {
        final Iterable<PcapNetworkInterfaceWrapper> allNetworkInterfaces = Iterables
                .transform(Pcaps.findAllDevs(), PcapNetworkInterfaceWrapper.TRANSFORMER);
        return allNetworkInterfaces;
    } catch (PcapNativeException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.stackframe.xml.DOMUtilities.java

/**
 * A convenience view that gets the node values out of a NodeList.
 *
 * @param nodeList this NodeList to get values out of
 * @return an Iterable of the values//from  ww  w  . j  a  va2s  .  c o m
 */
public static Iterable<String> values(NodeList nodeList) {
    return Iterables.transform(iterable(nodeList), new Function<Node, String>() {
        @Override
        public String apply(Node f) {
            return f.getNodeValue();
        }
    });
}

From source file:de.flapdoodle.guava.Flatter.java

public static <P, T> Function<? super P, Iterable<? extends Flat<P, T>>> flat(
        final Function<? super P, ? extends Iterable<? extends T>> sub) {
    return new Function<P, Iterable<? extends Flat<P, T>>>() {

        @Override//  w ww .ja va 2  s  .  c o  m
        public Iterable<? extends Flat<P, T>> apply(final P parent) {
            return Iterables.transform(sub.apply(parent), new Function<T, Flat<P, T>>() {
                public Flat<P, T> apply(T value) {
                    return new Flat<P, T>(parent, value);
                };
            });
        }

    };
}

From source file:com.google.devtools.build.xcode.util.Interspersing.java

/**
 * Inserts {@code what} before each item in {@code sequence}, returning a lazy sequence of twice
 * the length.//  ww  w.  j  av a2s . com
 */
public static <E> Iterable<E> beforeEach(final E what, Iterable<E> sequence) {
    Preconditions.checkNotNull(what);
    return Iterables.concat(Iterables.transform(sequence, new Function<E, Iterable<E>>() {
        @Override
        public Iterable<E> apply(E element) {
            return ImmutableList.of(what, element);
        }
    }));
}

From source file:ivorius.ivtoolkit.tools.Pairs.java

public static <T> Iterable<T> both(Iterable<? extends Pair<T, T>> set) {
    return Sets.newHashSet(Iterables.concat(Iterables.transform(set, Pairs.<T>leftFunction()),
            Iterables.transform(set, Pairs.<T>rightFunction())));
}

From source file:org.javersion.core.Merge.java

protected static <K, V, T extends Version<K, V>> Iterable<Merge<K, V>> toMergeNodes(
        Iterable<VersionNode<K, V, T>> nodes) {
    return Iterables.transform(nodes, new Function<VersionNode<K, V, T>, Merge<K, V>>() {
        @Override/* www  .ja va2  s .co m*/
        public Merge<K, V> apply(VersionNode<K, V, T> input) {
            return input;
        }
    });
}

From source file:com.google.gerrit.server.OptionUtil.java

public static Iterable<String> splitOptionValue(String value) {
    return Iterables.transform(COMMA_OR_SPACE.split(value), TO_LOWER_CASE);
}

From source file:org.obiba.opal.web.taxonomy.Dtos.java

public static Opal.TaxonomyDto asDto(Taxonomy taxonomy) {
    Opal.TaxonomyDto.Builder builder = Opal.TaxonomyDto.newBuilder();
    builder.setName(taxonomy.getName());
    if (taxonomy.hasAuthor())
        builder.setAuthor(taxonomy.getAuthor());
    if (taxonomy.hasLicense())
        builder.setLicense(taxonomy.getLicense());
    builder.addAllTitle(toLocaleTextDtoList(taxonomy.getTitle()));
    builder.addAllDescription(toLocaleTextDtoList(taxonomy.getDescription()));

    if (taxonomy.hasVocabularies()) {
        builder.addAllVocabularies(//w w w.ja va2s. co  m
                Iterables.transform(taxonomy.getVocabularies(), new Function<Vocabulary, Opal.VocabularyDto>() {
                    @Nullable
                    @Override
                    public Opal.VocabularyDto apply(@Nullable Vocabulary input) {
                        return asDto(input);
                    }
                }));
    }
    return builder.build();
}