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:net.conquiris.lucene.search.Filters.java

/** Constructs a filter for docs matching any of the terms added to it. */
public static <T> TermsFilter terms(Function<? super T, Term> termBuilder, Iterable<T> values) {
    return terms(Iterables.transform(values, termBuilder));
}

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

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args,
        String complete, String[] others) {
    return StringUtil.copyPartialMatches(complete, Iterables.transform(scoreboard.getTeams(), TEAM_NAME),
            Lists.<String>newArrayList());
}

From source file:org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy.java

@Override
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
    return Iterables.filter(
            Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata), filter);
}

From source file:org.renjin.primitives.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/*from  ww  w.  jav  a 2s . co  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));

    if (!recursive && inspector.getCount() > DEFERRED_THRESHOLD
            && arguments.length() <= DEFERRED_ARGUMENT_LIMIT) {
        // return a view over these combined arguments
        if (inspector.getResult() == DoubleVector.VECTOR_TYPE) {
            return newDoubleView(arguments);
        }
    }

    // Allocate a new vector with all the elements
    return new Combiner(recursive, inspector.getResult()).add(arguments.namedValues()).combine();

}

From source file:ninja.leaping.permissionsex.sponge.PEXOptionSubjectData.java

private static <T> Map<Set<Context>, T> tKeys(Map<Set<Map.Entry<String, String>>, T> input) {
    final ImmutableMap.Builder<Set<Context>, T> ret = ImmutableMap.builder();
    for (Map.Entry<Set<Map.Entry<String, String>>, T> ent : input.entrySet()) {
        ret.put(ImmutableSet.copyOf(Iterables.transform(ent.getKey(),
                ctx -> ctx instanceof Context ? (Context) ctx : new Context(ctx.getKey(), ctx.getValue()))),
                ent.getValue());// w  ww  . j a  v  a2 s .  c om
    }
    return ret.build();
}

From source file:com.google.devtools.build.lib.rules.platform.ConstraintValue.java

/** Retrieves and casts the providers from the given targets. */
public static Iterable<ConstraintValueInfo> constraintValues(
        Iterable<? extends TransitiveInfoCollection> targets) {
    return Iterables.transform(targets, new Function<TransitiveInfoCollection, ConstraintValueInfo>() {
        @Override/* w  w w  .  ja  v  a  2s.  co m*/
        public ConstraintValueInfo apply(TransitiveInfoCollection target) {
            return constraintValue(target);
        }
    });
}

From source file:org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy.java

@Override
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
    return Iterables.filter(Iterables.transform(client.listSlices(), sliceToNodeMetadata), filter);
}

From source file:org.impressivecode.depress.common.Cells.java

public static DataCell stringListCell(final Iterable<String> stringList) {
    List<DataCell> coll = Lists.newArrayList(Iterables.transform(stringList, new Function<String, DataCell>() {
        @Override/* w  w  w .j  a  v  a 2 s .com*/
        public DataCell apply(final String value) {
            return stringCell(value);
        }
    }));
    return CollectionCellFactory.createListCell(coll);
}

From source file:com.android.ide.common.blame.MergingLogRewriter.java

@Override
public void receiveMessage(@NonNull Message message) {
    List<SourceFilePosition> originalPositions = message.getSourceFilePositions();

    Iterable<SourceFilePosition> positions = Iterables.transform(originalPositions, mGetOriginalPosition);

    mMessageReceiver.receiveMessage(new Message(message.getKind(), message.getText(), message.getRawMessage(),
            message.getToolName(), ImmutableList.copyOf(positions)));
}

From source file:org.lealone.cluster.streaming.management.StreamStateCompositeData.java

public static CompositeData toCompositeData(final StreamState streamState) {
    Map<String, Object> valueMap = new HashMap<>();
    valueMap.put(ITEM_NAMES[0], streamState.planId.toString());
    valueMap.put(ITEM_NAMES[1], streamState.description);

    CompositeData[] sessions = new CompositeData[streamState.sessions.size()];
    Lists.newArrayList(Iterables.transform(streamState.sessions, new Function<SessionInfo, CompositeData>() {
        public CompositeData apply(SessionInfo input) {
            return SessionInfoCompositeData.toCompositeData(streamState.planId, input);
        }/*from  ww  w . j  ava2 s . c  o m*/
    })).toArray(sessions);
    valueMap.put(ITEM_NAMES[2], sessions);

    long currentRxBytes = 0;
    long totalRxBytes = 0;
    long currentTxBytes = 0;
    long totalTxBytes = 0;
    for (SessionInfo sessInfo : streamState.sessions) {
        currentRxBytes += sessInfo.getTotalSizeReceived();
        totalRxBytes += sessInfo.getTotalSizeToReceive();
        currentTxBytes += sessInfo.getTotalSizeSent();
        totalTxBytes += sessInfo.getTotalSizeToSend();
    }
    double rxPercentage = (totalRxBytes == 0 ? 100L : currentRxBytes * 100L / totalRxBytes);
    double txPercentage = (totalTxBytes == 0 ? 100L : currentTxBytes * 100L / totalTxBytes);

    valueMap.put(ITEM_NAMES[3], currentRxBytes);
    valueMap.put(ITEM_NAMES[4], totalRxBytes);
    valueMap.put(ITEM_NAMES[5], rxPercentage);
    valueMap.put(ITEM_NAMES[6], currentTxBytes);
    valueMap.put(ITEM_NAMES[7], totalTxBytes);
    valueMap.put(ITEM_NAMES[8], txPercentage);

    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, valueMap);
    } catch (OpenDataException e) {
        throw Throwables.propagate(e);
    }
}