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:jflowmap.util.Log4ExportAppender.java

public static Iterable<String> messagesOf(Iterable<Pair<Long, String>> messages) {
    return Iterables.transform(messages, new Function<Pair<Long, String>, String>() {
        @Override/*w w w  .j  a  v a 2  s  .  c  o  m*/
        public String apply(Pair<Long, String> from) {
            return from.second();
        }
    });
}

From source file:org.renjin.primitives.combine.Combine.java

/**
 * combines its arguments to form a vector. All arguments are coerced to a common type which is the
 * type of the returned value, and all attributes except names are removed.
 *
 * @param arguments/*  ww w  . j a  v  a 2s .  c  o  m*/
 * @param recursive
 * @return
 */
@Builtin
public static SEXP c(@ArgumentList ListVector arguments, @NamedFlag("recursive") boolean recursive) {

    // Iterate over all the vectors in the argument
    // list to determine which vector type to use
    Inspector inspector = new Inspector(recursive);
    inspector.acceptAll(Iterables.transform(arguments.namedValues(), VALUE_OF));

    CombinedBuilder builder = inspector.newBuilder().useNames(true);

    // Allocate a new vector with all the elements
    return new Combiner(recursive, builder).add(arguments.namedValues()).build();
}

From source file:org.apache.aurora.scheduler.filter.ConstraintMatcher.java

/**
 * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this
 * filter was created with.//from  w  w w  .  j  a  v  a 2  s .  com
 *
 * @param constraint Scheduling filter to check.
 * @return A veto if the constraint is not satisfied based on the existing state of the job.
 */
static Optional<Veto> getVeto(AttributeAggregate cachedjobState, Iterable<IAttribute> hostAttributes,
        IConstraint constraint) {

    Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes,
            new NameFilter(constraint.getName()));
    Optional<IAttribute> attribute;
    if (Iterables.isEmpty(sameNameAttributes)) {
        attribute = Optional.absent();
    } else {
        Set<String> attributeValues = ImmutableSet
                .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES)));
        attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues)));
    }

    ITaskConstraint taskConstraint = constraint.getConstraint();
    switch (taskConstraint.getSetField()) {
    case VALUE:
        boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.of()),
                taskConstraint.getValue());
        return matches ? Optional.absent() : Optional.of(Veto.constraintMismatch(constraint.getName()));

    case LIMIT:
        if (!attribute.isPresent()) {
            return Optional.of(Veto.constraintMismatch(constraint.getName()));
        }

        boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(),
                cachedjobState);
        return satisfied ? Optional.absent() : Optional.of(Veto.unsatisfiedLimit(constraint.getName()));

    default:
        throw new SchedulerException(
                "Failed to recognize the constraint type: " + taskConstraint.getSetField());
    }
}

From source file:com.isotrol.impe3.pms.core.obj.MessageMappers.java

public static Iterable<LocalizedNamePB> localizedName(Map<Locale, Name> names) {
    return Iterables.transform(names.entrySet(), LocalizedNameMapper.INSTANCE);
}

From source file:org.fcrepo.jms.headers.DefaultMessageFactory.java

private static String getEventURIs(final Set<Integer> types) {
    final String uris = Joiner.on(',').join(Iterables.transform(types, new Function<Integer, String>() {

        @Override/*from  w w w .  ja va 2 s .  c  om*/
        public String apply(final Integer type) {
            return REPOSITORY_NAMESPACE + EventType.valueOf(type);
        }
    }));
    log.debug("Constructed event type URIs: {}", uris);
    return uris;
}

From source file:org.asoem.greyfish.utils.collect.Products.java

/**
 * Create a view of the iterable of products as a product of iterables of the {@link Product2#first() first} and
 * {@link org.asoem.greyfish.utils.collect.Product2#second() second} elements respectively.
 *
 * @param products the iterable to unzip
 * @param <E1>     the type of the first product element
 * @param <E2>     the type of the second product element
 * @return a view of the iterable of products as a product of iterables
 *///from   www . ja  v a2s  . c o  m
public static <E1, E2> Product2<Iterable<E1>, Iterable<E2>> unzip(
        final Iterable<? extends Product2<? extends E1, ? extends E2>> products) {
    final Iterable<E1> transform = Iterables.transform(products,
            new Function<Product2<? extends E1, ? extends E2>, E1>() {

                @Override
                public E1 apply(final Product2<? extends E1, ? extends E2> product2) {
                    return checkNotNull(product2).first();
                }
            });
    final Iterable<E2> transform1 = Iterables.transform(products,
            new Function<Product2<? extends E1, ? extends E2>, E2>() {

                @Override
                public E2 apply(final Product2<? extends E1, ? extends E2> product2) {
                    return checkNotNull(product2).second();
                }
            });
    return Tuple2.of(transform, transform1);
}

From source file:org.eclipse.viatra.query.runtime.localsearch.MatchingTable.java

@Override
public Iterator<Tuple> iterator() {
    return Iterables.transform(matchings.keySet(), new Function<MatchingKey, Tuple>() {

        @Override/*w w w  .  ja va  2s. c  om*/
        public Tuple apply(MatchingKey input) {
            return new FlatTuple(input.keys);
        }
    }).iterator();
}

From source file:mocks.HelloServiceMock.java

@Override
public Hellos getHellos() {

    return Hellos.builder().helloCollection(
            Lists.newArrayList(Iterables.transform(mockedMessageStrings, new Function<HelloEntity, String>() {

                @Override/*from  www  .ja  v  a  2s.  c  o m*/
                public String apply(HelloEntity arg0) {

                    return arg0.getHelloMessage();
                }
            }))).build();
}

From source file:io.v.chat.ParticipantsPanel.java

public void setParticipants(List<Participant> participants) {
    participantTextArea.clear();//from www .j  av a  2s.c  om
    boolean first = true;
    Function<Participant, String> nameFunction = new Function<Participant, String>() {
        @Override
        public String apply(Participant input) {
            return input.getName();
        }
    };
    for (String participant : Ordering.natural().sortedCopy(Iterables.transform(participants, nameFunction))) {
        if (first) {
            participantTextArea.setLine(0, participant);
            first = false;
        } else {
            participantTextArea.appendLine(participant);
        }
    }
}

From source file:org.apache.mahout.clustering.streaming.tools.IOUtils.java

/**
 * Converts CentroidWritable values in a sequence file into Centroids lazily.
 * @param dirIterable the source iterable (comes from a SequenceFileDirIterable).
 * @return an Iterable<Centroid> with the converted vectors.
 *//*from w  ww.j a va2 s .  c o m*/
public static Iterable<Centroid> getCentroidsFromClusterWritableIterable(
        Iterable<ClusterWritable> dirIterable) {
    return Iterables.transform(dirIterable, new Function<ClusterWritable, Centroid>() {
        int numClusters = 0;

        @Override
        public Centroid apply(ClusterWritable input) {
            Preconditions.checkNotNull(input);
            return new Centroid(numClusters++, input.getValue().getCenter().clone(),
                    input.getValue().getTotalObservations());
        }
    });
}