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:gg.uhc.flagcommands.tab.OnlinePlayerTabComplete.java

@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String alias, String[] args,
        String complete, String[] others) {
    Set<String> players = Sets.newHashSet(Iterables.transform(Bukkit.getOnlinePlayers(), PLAYER_NAME));

    return StringUtil.copyPartialMatches(complete, players, Lists.<String>newArrayList());
}

From source file:shaded.org.openqa.selenium.remote.server.handler.internal.ArgumentConverter.java

public Object apply(Object arg) {
    if (arg instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> paramAsMap = (Map<String, Object>) arg;
        if (paramAsMap.containsKey("ELEMENT")) {
            shaded.org.openqa.selenium.remote.server.KnownElements.ProxiedElement element = (shaded.org.openqa.selenium.remote.server.KnownElements.ProxiedElement) knownElements
                    .get((String) paramAsMap.get("ELEMENT"));
            return element.getWrappedElement();
        }/* w  w w  .  j ava2  s  .c o m*/

        Map<String, Object> converted = Maps.newHashMapWithExpectedSize(paramAsMap.size());
        for (Map.Entry<String, Object> entry : paramAsMap.entrySet()) {
            converted.put(entry.getKey(), apply(entry.getValue()));
        }
        return converted;
    }

    if (arg instanceof List<?>) {
        return Lists.newArrayList(Iterables.transform((List<?>) arg, this));
    }

    return arg;
}

From source file:edu.umn.msi.tropix.proteomics.client.EnzymeUtils.java

public Iterable<String> getEnzymeNames() {
    return Iterables.transform(enzymes.getEnzymes(), ENZYME_NAME_FUNCTION);
}

From source file:com.isotrol.impe3.pms.core.engine.OnlineEngineModel.java

public OnlineEngineModel(EditionEntity edition, String routingDomain, BaseEngineModel model,
        PortalModelLoader portalLoader) throws PMSException {
    super(model);
    this.editionId = edition.getId();
    ImmutableMap.Builder<UUID, OnlinePortalModel> builder = ImmutableMap.builder();
    for (PortalDfn dfn : Iterables.transform(edition.getPortals(), PORTAL)) {
        // Temporal: see #15633
        // if (Objects.equal(routingDomain, dfn.getRoutingDomain().getName())) {
        final OnlinePortalModel portalModel = portalLoader.getOnline(model, dfn);
        builder.put(portalModel.getId(), portalModel);
        // }//from   w  w  w.ja v  a  2s. c o  m
    }
    this.portals = builder.build();
}

From source file:org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier.java

@Override
public Set<? extends Image> get() {
    Set<Image> images;
    logger.debug(">> providing images");
    images = Sets.newLinkedHashSet(Iterables.transform(sync.listImages(), slicehostImageToImage));
    logger.debug("<< images(%d)", images.size());
    return images;
}

From source file:org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrategy.java

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

From source file:edu.buaa.satla.analysis.cfa.CFACheck.java

/**
 * Traverse the CFA and run a series of checks at each node
 * @param cfa Node to start traversal from
 * @param nodes Optional set of all nodes in the CFA (may be null)
 * @param pruned Whether the CFA was pruned and may be incomplete.
 *///from   w w  w  .  j  av  a  2s  .  co m
public static boolean check(FunctionEntryNode cfa, Collection<CFANode> nodes, boolean pruned) {

    Set<CFANode> visitedNodes = new HashSet<>();
    Deque<CFANode> waitingNodeList = new ArrayDeque<>();

    waitingNodeList.add(cfa);
    while (!waitingNodeList.isEmpty()) {
        CFANode node = waitingNodeList.poll();

        if (visitedNodes.add(node)) {
            Iterables.addAll(waitingNodeList, CFAUtils.successorsOf(node));
            Iterables.addAll(waitingNodeList, CFAUtils.predecessorsOf(node)); // just to be sure to get ALL nodes.

            // The actual checks
            isConsistent(node);
            checkEdgeCount(node, pruned);
        }
    }

    if (nodes != null) {
        if (!visitedNodes.equals(nodes)) {
            assert false : "\nNodes in CFA but not reachable through traversal: "
                    + Iterables.transform(Sets.difference(new HashSet<>(nodes), visitedNodes), DEBUG_FORMAT)
                    + "\nNodes reached that are not in CFA: "
                    + Iterables.transform(Sets.difference(visitedNodes, new HashSet<>(nodes)), DEBUG_FORMAT);
        }
    }
    return true;
}

From source file:org.jclouds.ibmdev.compute.strategy.IBMDeveloperCloudListNodesStrategy.java

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

From source file:co.cask.cdap.internal.app.queue.BasicInputDatum.java

BasicInputDatum(final QueueName queueName, DequeueResult<S> result, Function<S, T> decoder) {
    this.result = result;
    this.retry = new AtomicInteger(0);
    this.queueName = queueName;
    // Memorize the transformed Iterable so that decoder would only invoked once for each event no matter
    // how many times iterator() is called. This is to save time as well as a need for the case where
    // metrics has been logged inside the decoder.
    this.events = result.isEmpty() ? ImmutableList.<T>of()
            : ImmutableList.copyOf(Iterables.transform(result, decoder));
    this.inputContext = new InputContext() {
        @Override/*w w  w.  j  a v  a  2  s . co  m*/
        public String getOrigin() {
            return queueName.getSimpleName();
        }

        @Override
        public int getRetryCount() {
            return retry.get();
        }

        @Override
        public String toString() {
            return Objects.toStringHelper(InputContext.class).add("queue", queueName).toString();
        }
    };
}

From source file:com.exoplatform.iversion.VersionGraphBase.java

Set<VersionNode<K, V, M, T>> revisionsToNodes(Iterable<Long> revisions) {
    return ImmutableSet.copyOf(Iterables.transform(revisions, revisionToVersionNode));
}