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.apache.cassandra.db.commitlog.ReplayPosition.java

/**
 * Convenience method to compute the replay position for a group of SSTables.
 * @param sstables//from www.  j av  a  2s  . co  m
 * @return the most recent (highest) replay position
 */
public static ReplayPosition getReplayPosition(Iterable<? extends SSTable> sstables) {
    if (Iterables.isEmpty(sstables))
        return NONE;

    Function<SSTable, ReplayPosition> f = new Function<SSTable, ReplayPosition>() {
        public ReplayPosition apply(SSTable sstable) {
            return sstable.replayPosition;
        }
    };
    Ordering<ReplayPosition> ordering = Ordering.from(ReplayPosition.comparator);
    return ordering.max(Iterables.transform(sstables, f));
}

From source file:cosmos.sql.call.impl.Filter.java

public List<ChildVisitor> getFilters() {
    return Lists.newArrayList(Iterables.transform(children.values(), new Function<CallIfc<?>, ChildVisitor>() {

        @Override//from   w  ww .jav  a 2  s . c  o  m
        public ChildVisitor apply(CallIfc<?> child) {
            return (ChildVisitor) child;
        }

    }));
}

From source file:org.dslforge.ace.generator.ANTLRGrammar.java

@Override
public Set<String> getKeywords() {
    Map<String, Integer> stringLiteralToTypeMap = getGrammar().composite.stringLiteralToTypeMap;
    Set<String> keySet = stringLiteralToTypeMap.keySet();
    Set<String> keywords = Sets.newHashSet(Iterables.transform(keySet, new Function<String, String>() {
        @Override/* ww  w. java2s  .  c  om*/
        public String apply(String input) {
            return input.substring(1, input.length() - 1);
        }
    }));
    return keywords;
}

From source file:org.geogit.storage.memory.Node.java

/**
 * Returns all nodes reachable from this node through an outgoing relationship. 
 *///from   w  w w.  j  a va  2s . c om
public Iterable<Node> to() {
    return Iterables.transform(out, new Function<Edge, Node>() {
        @Override
        public Node apply(Edge e) {
            return e.dst;
        }
    });
}

From source file:org.gradle.model.internal.manage.schema.extract.MethodDescription.java

@Override
public String toString() {
    Iterable<String> parameterTypeNames = Iterables.transform(Arrays.asList(parameterTypes),
            new Function<Type, String>() {
                public String apply(Type type) {
                    return typeName(type);
                }/*www  .  ja  v a2  s. c  o  m*/
            });
    return String.format("%s %s.%s(%s)", typeName(returnType), owner.getName(), name,
            Joiner.on(", ").join(parameterTypeNames));
}

From source file:de.cosmocode.commons.reflect.DefaultClasspath.java

public DefaultClasspath(String classpath) {
    Preconditions.checkNotNull(classpath, "Classpath");

    this.entries = ImmutableSet
            .copyOf(Iterables.transform(SPLITTER.split(classpath), new Function<String, URL>() {

                @Override//from  w w  w.  j  a  v  a2s  . co  m
                public URL apply(String from) {
                    try {
                        return new File(from).toURI().toURL();
                    } catch (MalformedURLException e) {
                        throw new ExceptionInInitializerError(e);
                    }
                }

            }));
}

From source file:com.atlassian.jira.license.DefaultLicenseStatusMessage.java

@Override
public String getAllMessages(final String delimiter) {
    Iterable<String> values = Iterables.transform(messagesOrder, new Function<String, String>() {
        @Override//from  w  w  w  . j  av a 2s . com
        public String apply(@Nullable final String input) {
            return messages.get(input);
        }
    });
    return Joiner.on(delimiter).join(values);
}

From source file:sf.net.experimaestro.manager.scripting.ConstructorFunction.java

@Override
protected Iterable<ConstructorDeclaration> declarations() {
    return Iterables.transform(constructors, ConstructorDeclaration::new);
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ListNodeBaseSerializer.java

@Override
public final Iterable<E> serialize(final ListSchemaNode schema, final N node) {
    return Iterables.concat(Iterables.transform(node.getValue(), input -> {
        final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
        final int size = Iterables.size(serializedChild);

        Preconditions.checkState(size == 1,
                "Unexpected count of entries  for list serialized from: %s, should be 1, was: %s", input, size);
        return serializedChild;
    }));/*ww  w .j ava 2 s .  c  o m*/
}

From source file:org.onos.yangtools.yang.data.impl.schema.transform.base.serializer.ListNodeBaseSerializer.java

@Override
public final Iterable<E> serialize(final ListSchemaNode schema, final N node) {
    return Iterables.concat(Iterables.transform(node.getValue(), new Function<O, Iterable<E>>() {
        @Override//w  w w. j a  va  2s  .  co m
        public Iterable<E> apply(final O input) {
            final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
            final int size = Iterables.size(serializedChild);

            Preconditions.checkState(size == 1,
                    "Unexpected count of entries  for list serialized from: %s, should be 1, was: %s", input,
                    size);
            return serializedChild;
        }
    }));
}