Example usage for com.google.common.collect Iterables concat

List of usage examples for com.google.common.collect Iterables concat

Introduction

In this page you can find the example usage for com.google.common.collect Iterables concat.

Prototype

public static <T> Iterable<T> concat(final Iterable<? extends Iterable<? extends T>> inputs) 

Source Link

Document

Combines multiple iterables into a single iterable.

Usage

From source file:org.eclipse.xtext.xbase.scoping.SyntaxFilteredScope.java

@Override
public Iterable<IEObjectDescription> getAllElements() {
    return Iterables
            .concat(Iterables.transform(values, new Function<QualifiedName, Iterable<IEObjectDescription>>() {
                @Override//ww  w. ja v a 2s  . co  m
                public Iterable<IEObjectDescription> apply(QualifiedName input) {
                    return parent.getElements(input);
                }
            }));
}

From source file:io.crate.operation.merge.PassThroughPagingIterator.java

@Override
public void merge(Iterable<? extends KeyIterable<TKey, TRow>> iterables) {
    Iterable<TRow> concat = Iterables.concat(iterables);

    if (repeatable) {
        this.iterables.addAll(iterables);
        this.storedForRepeat = null;
    }//  w ww .  jav  a2 s.co  m
    if (iterator.hasNext()) {
        iterator = Iterators.concat(iterator, concat.iterator());
    } else {
        iterator = concat.iterator();
    }
}

From source file:org.apache.druid.segment.incremental.SpatialDimensionRowTransformer.java

public SpatialDimensionRowTransformer(List<SpatialDimensionSchema> spatialDimensions) {
    this.spatialDimensionMap = Maps.newHashMap();
    for (SpatialDimensionSchema spatialDimension : spatialDimensions) {
        if (this.spatialDimensionMap.put(spatialDimension.getDimName(), spatialDimension) != null) {
            throw new ISE("Duplicate spatial dimension names found! Check your schema yo!");
        }//from w  w  w . j  av a 2  s  . com
    }
    this.spatialPartialDimNames = Sets.newHashSet(Iterables
            .concat(Lists.transform(spatialDimensions, new Function<SpatialDimensionSchema, List<String>>() {
                @Override
                public List<String> apply(SpatialDimensionSchema input) {
                    return input.getDims();
                }
            })));
}

From source file:codecrafter47.bungeetablistplus.managers.PlayerManager.java

public List<IPlayer> getPlayers(Collection<String> filter, ProxiedPlayer who, boolean includeSuspectors) {
    List<IPlayer> list = new ArrayList<>();
    Iterable<IPlayer> players = Iterables
            .concat(Collections2.transform(playerProviders, new Function<IPlayerProvider, Iterable<IPlayer>>() {
                @Override//from   w  ww.  ja  v a 2  s .  c  o m
                public Iterable<IPlayer> apply(IPlayerProvider iPlayerProvider) {
                    return iPlayerProvider.getPlayers();
                }
            }));
    for (IPlayer p : players) {
        boolean areGroupRules = false;
        boolean areServerRules = false;
        boolean fitGroupRules = false;
        boolean fitServerRules = false;
        String group = plugin.getPermissionManager().getMainGroup(p);
        for (String rule : filter) {
            if (rule.isEmpty()) {
                // ignore
            } else {
                Optional<ServerInfo> server = p.getServer();
                if (rule.equalsIgnoreCase("currentserver")) {
                    areServerRules = true;
                    if (server.isPresent() && who.getServer() != null) {
                        if (server.get().getName().equalsIgnoreCase(who.getServer().getInfo().getName())) {
                            fitServerRules = true;
                        }
                    }
                } else if (isServer(rule)) {
                    areServerRules = true;
                    if (server.isPresent()) {
                        if (server.get().getName().equalsIgnoreCase(rule)) {
                            fitServerRules = true;
                        }
                        String[] s = rule.split("#");
                        if (s.length == 2) {
                            if (server.get().getName().equalsIgnoreCase(s[0])) {
                                String world = plugin.getBridge().getPlayerInformation(p, "world");
                                if (world != null) {
                                    if (world.equalsIgnoreCase(s[1])) {
                                        fitServerRules = true;
                                    }
                                }
                            }
                        }
                    }
                } else {
                    areGroupRules = true;
                    if (group != null) {
                        if (group.equalsIgnoreCase(rule)) {
                            fitGroupRules = true;
                        }
                    }
                }
            }
        }
        if (((!areServerRules) || fitServerRules) && ((!areGroupRules) || fitGroupRules)
                && !BungeeTabListPlus.isHidden(p, who) && (includeSuspectors || p.getGameMode() != 3)) {
            list.add(p);
        }
    }
    return list;
}

From source file:org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy.java

public RunningInstance getRunningInstanceInRegion(String region, String id) {
    return getOnlyElement(
            Iterables.concat(client.getInstanceApi().get().describeInstancesInRegion(region, id)));
}

From source file:org.apache.giraph.block_app.framework.block.RepeatBlock.java

@Override
public Iterator<AbstractPiece> iterator() {
    return Iterables.concat(Collections.nCopies(repeatTimes.get(), block)).iterator();
}

From source file:eu.itesla_project.iidm.network.impl.MergedBus.java

@Override
public Iterable<TerminalExt> getConnectedTerminals() {
    checkValidity();/*from  w  w w.  j a  va 2s  .c o  m*/
    List<Iterable<TerminalExt>> iterables = new ArrayList<>(buses.size());
    for (ConfiguredBus bus : buses) {
        iterables.add(bus.getConnectedTerminals());
    }
    return Iterables.concat(iterables);
}

From source file:com.google.devtools.build.lib.query2.RBuildFilesVisitor.java

@Override
protected Visit getVisitResult(Iterable<SkyKey> values) throws InterruptedException {
    Collection<Iterable<SkyKey>> reverseDeps = env.graph.getReverseDeps(values).values();
    Set<SkyKey> keysToUseForResult = CompactHashSet.create();
    Set<SkyKey> keysToVisitNext = CompactHashSet.create();
    for (SkyKey rdep : Iterables.concat(reverseDeps)) {
        if (rdep.functionName().equals(SkyFunctions.PACKAGE)) {
            keysToUseForResult.add(rdep);
            // Every package has a dep on the external package, so we need to include those edges too.
            if (rdep.equals(EXTERNAL_PACKAGE_KEY)) {
                keysToVisitNext.add(rdep);
            }//from  www  .  j a v a  2 s.com
        } else if (!rdep.functionName().equals(SkyFunctions.PACKAGE_LOOKUP)
                && !rdep.functionName().equals(SkyFunctions.GLOB)) {
            // Packages may depend on the existence of subpackages, but these edges aren't relevant to
            // rbuildfiles. They may also depend on files transitively through globs, but these cannot
            // be included in load statements and so we don't traverse through these either.
            keysToVisitNext.add(rdep);
        }
    }
    return new Visit(keysToUseForResult, keysToVisitNext);
}

From source file:co.cask.tigon.internal.app.runtime.flow.FlowUtils.java

/**
 * Configures all queues being used in a flow.
 *
 * @return A Multimap from flowletId to QueueName where the flowlet is a consumer of.
 *//*from  w  w w.  j  a  va  2  s  . c om*/
public static Multimap<String, QueueName> configureQueue(Program program, FlowSpecification flowSpec,
        QueueAdmin queueAdmin) {
    // Generate all queues specifications
    Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecs = new SimpleQueueSpecificationGenerator()
            .create(flowSpec);

    // For each queue in the flow, gather a map of consumer groupId to number of instances
    Table<QueueName, Long, Integer> queueConfigs = HashBasedTable.create();

    // For storing result from flowletId to queue.
    ImmutableSetMultimap.Builder<String, QueueName> resultBuilder = ImmutableSetMultimap.builder();

    // Loop through each flowlet
    for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) {
        String flowletId = entry.getKey();
        long groupId = FlowUtils.generateConsumerGroupId(program, flowletId);
        int instances = entry.getValue().getInstances();

        // For each queue that the flowlet is a consumer, store the number of instances for this flowlet
        for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.column(flowletId).values())) {
            queueConfigs.put(queueSpec.getQueueName(), groupId, instances);
            resultBuilder.put(flowletId, queueSpec.getQueueName());
        }
    }

    try {
        // For each queue in the flow, configure it through QueueAdmin
        for (Map.Entry<QueueName, Map<Long, Integer>> row : queueConfigs.rowMap().entrySet()) {
            LOG.info("Queue config for {} : {}", row.getKey(), row.getValue());
            queueAdmin.configureGroups(row.getKey(), row.getValue());
        }
        return resultBuilder.build();
    } catch (Exception e) {
        LOG.error("Failed to configure queues", e);
        throw Throwables.propagate(e);
    }
}

From source file:org.jclouds.blobstore.strategy.internal.ConcatenateContainerLists.java

@Override
public Iterable<? extends StorageMetadata> execute(String container, ListContainerOptions options) {
    try {/*from  ww w.j  a va 2  s  . c  om*/
        boolean truncated = true;
        List<PageSet<? extends StorageMetadata>> listings = Lists.newArrayList();
        while (truncated) {
            PageSet<? extends StorageMetadata> listing = connection.list(container, options);
            truncated = listing.getNextMarker() != null;
            if (truncated) {
                options = options instanceof ImmutableListContainerOptions
                        ? options.clone().afterMarker(listing.getNextMarker())
                        : options.afterMarker(listing.getNextMarker());
            }
            listings.add(listing);
        }
        return Iterables.concat(listings);
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, BlobRuntimeException.class);
        throw new BlobRuntimeException("Error getting resource metadata in container: " + container, e);
    }
}