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(Iterable<? extends T> a, Iterable<? extends T> b) 

Source Link

Document

Combines two iterables into a single iterable.

Usage

From source file:org.eclipse.xtext.xbase.lib.IterableExtensions.java

/**
 * <p>//  w  ww .j a v a2  s  .c  om
 * Concatenates two iterables into a single iterable. The returned iterable has an iterator that traverses the
 * elements in {@code a}, followed by the elements in {@code b}. The resulting iterable is effectivly a view on the
 * source iterables. That is, the source iterators are not polled until necessary and the result will reflect
 * changes in the sources.
 * </p>
 * <p>
 * The returned iterable's iterator supports {@code remove()} when the corresponding input iterator supports it.
 * </p>
 * 
 * @param a
 *            the first iterable. May not be <code>null</code>.
 * @param b
 *            the second iterable. May not be <code>null</code>.
 * @return a combined iterable. Never <code>null</code>.
 */
@Pure
@Inline(value = "$3.$4concat($1, $2)", imported = Iterables.class)
public static <T> Iterable<T> operator_plus(Iterable<? extends T> a, Iterable<? extends T> b) {
    return Iterables.concat(a, b);
}

From source file:com.b2international.snowowl.snomed.importer.rf2.validation.SnomedExtendedMapTypeRefSetValidator.java

@Override
protected void doValidate(String effectiveTime, IProgressMonitor monitor) {
    super.doValidate(effectiveTime, monitor);
    addDefect(DefectType.EXTENDED_MAP_REFERENCED_INVALID_CONCEPT,
            Iterables.concat(mapCategoryConceptNotExist, correlationConceptNotExist));
}

From source file:org.glowroot.local.ui.TraceCommonService.java

@Nullable
Trace getTrace(String traceId) throws Exception {
    // check active traces first, then pending traces, and finally stored traces
    // to make sure that the trace is not missed if it is in transition between these states
    for (Transaction transaction : Iterables.concat(transactionRegistry.getTransactions(),
            transactionCollectorImpl.getPendingTransactions())) {
        if (transaction.getId().equals(traceId)) {
            return createTrace(transaction);
        }//from   w  w w.j  a  va 2  s.co m
    }
    return traceDao.readTrace(traceId);
}

From source file:org.jenkinsci.plugins.github.util.FluentIterableWrapper.java

/**
 * Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
 * followed by those of {@code other}. The iterators are not polled until necessary.
 *
 * <p>The returned iterable's {@code Iterator} supports {@code remove()} when the corresponding
 * {@code Iterator} supports it./*from  www. j a  va  2  s . c  o  m*/
 */
@CheckReturnValue
public final FluentIterableWrapper<E> append(Iterable<? extends E> other) {
    return from(Iterables.concat(iterable, other));
}

From source file:org.sonar.plugins.pmd.PmdViolationToRuleViolation.java

private Resource findResourceFor(IRuleViolation violation) {
    List<File> allSources = ImmutableList
            .copyOf(Iterables.concat(projectFileSystem.getSourceDirs(), projectFileSystem.getTestDirs()));

    return JavaFile.fromAbsolutePath(violation.getFilename(), allSources, true);
}

From source file:com.ebuddy.cassandra.structure.DefaultPath.java

@Override
public Path concat(Path other) {
    Iterable<String> newPathElements = Iterables.concat(pathElements, other.getElements());
    return new DefaultPath(newPathElements);
}

From source file:org.richfaces.cdk.templatecompiler.statements.IfStatement.java

@Override
public Iterable<HelperMethod> getRequiredMethods() {
    return Iterables.concat(super.getRequiredMethods(), testStatement.getRequiredMethods());
}

From source file:com.facebook.buck.doctor.DefaultExtraInfoCollector.java

@Override
public Optional<ExtraInfoResult> run() throws IOException, InterruptedException, ExtraInfoExecutionException {
    ImmutableList<String> extraInfoCommand = doctorConfig.getExtraInfoCommand();
    if (extraInfoCommand.isEmpty()) {
        return Optional.empty();
    }/*www .j  a v a 2  s.  c o m*/

    // TODO(ruibm): Potentially add the initial static launch dir here as well as any launch-*
    // logs buck is currently generating.
    Path rageExtraFilesDir = projectFilesystem.getBuckPaths().getLogDir().resolve("rage-extra-info");
    projectFilesystem.deleteRecursivelyIfExists(rageExtraFilesDir);
    projectFilesystem.mkdirs(rageExtraFilesDir);

    String extraInfoCommandOutput = runCommandAndGetStdout(
            Iterables.concat(extraInfoCommand,
                    ImmutableList.of("--output-dir", projectFilesystem.resolve(rageExtraFilesDir).toString())),
            projectFilesystem, processExecutor);

    ImmutableSet<Path> rageExtraFiles = projectFilesystem.getFilesUnderPath(rageExtraFilesDir);

    return Optional.of(
            ExtraInfoResult.builder().setExtraFiles(rageExtraFiles).setOutput(extraInfoCommandOutput).build());
}

From source file:com.google.gerrit.server.schema.Schema_67.java

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    ui.message("Update ownerGroupId to ownerGroupUUID");

    // Scan all AccountGroup, and find the ones that need the owner_group_id
    // migrated to owner_group_uuid.
    Map<AccountGroup.Id, AccountGroup.Id> idMap = Maps.newHashMap();
    Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
    try {//from  w  ww  . j ava 2  s .  com
        ResultSet rs = stmt.executeQuery("SELECT group_id, owner_group_id FROM account_groups"
                + " WHERE owner_group_uuid is NULL or owner_group_uuid =''");
        try {
            while (rs.next()) {
                AccountGroup.Id groupId = new AccountGroup.Id(rs.getInt(1));
                AccountGroup.Id ownerId = new AccountGroup.Id(rs.getInt(2));
                idMap.put(groupId, ownerId);
            }
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }

    // Lookup up all groups by ID.
    Set<AccountGroup.Id> all = Sets.newHashSet(Iterables.concat(idMap.keySet(), idMap.values()));
    Map<AccountGroup.Id, AccountGroup> groups = Maps.newHashMap();
    com.google.gwtorm.server.ResultSet<AccountGroup> rs = db.accountGroups().get(all);
    try {
        for (AccountGroup group : rs) {
            groups.put(group.getId(), group);
        }
    } finally {
        rs.close();
    }

    // Update the ownerGroupUUID.
    List<AccountGroup> toUpdate = Lists.newArrayListWithCapacity(idMap.size());
    for (Entry<AccountGroup.Id, AccountGroup.Id> entry : idMap.entrySet()) {
        AccountGroup group = groups.get(entry.getKey());
        AccountGroup owner = groups.get(entry.getValue());
        group.setOwnerGroupUUID(owner.getGroupUUID());
        toUpdate.add(group);
    }

    db.accountGroups().update(toUpdate);
}

From source file:org.apache.cassandra.cql3.selection.AbstractFunctionSelector.java

public static Factory newFactory(final Function fun, final SelectorFactories factories)
        throws InvalidRequestException {
    if (fun.isAggregate()) {
        if (factories.doesAggregation())
            throw new InvalidRequestException(
                    "aggregate functions cannot be used as arguments of aggregate functions");
    }//from   ww w. jav  a 2s  .  com

    return new Factory() {
        protected String getColumnName() {
            if (AggregateFcts.isCountRows(fun))
                return "count";

            return new StrBuilder(fun.name().toString()).append('(')
                    .appendWithSeparators(factories.getColumnNames(), ", ").append(')').toString();
        }

        protected AbstractType<?> getReturnType() {
            return fun.returnType();
        }

        protected void addColumnMapping(SelectionColumnMapping mapping, ColumnSpecification resultsColumn) {
            SelectionColumnMapping tmpMapping = SelectionColumnMapping.newMapping();
            for (Factory factory : factories)
                factory.addColumnMapping(tmpMapping, resultsColumn);

            if (tmpMapping.getMappings().get(resultsColumn).isEmpty())
                // add a null mapping for cases where there are no
                // further selectors, such as no-arg functions and count
                mapping.addMapping(resultsColumn, (ColumnDefinition) null);
            else
                // collate the mapped columns from the child factories & add those
                mapping.addMapping(resultsColumn, tmpMapping.getMappings().values());
        }

        public Iterable<Function> getFunctions() {
            return Iterables.concat(fun.getFunctions(), factories.getFunctions());
        }

        public Selector newInstance() throws InvalidRequestException {
            return fun.isAggregate() ? new AggregateFunctionSelector(fun, factories.newInstances())
                    : new ScalarFunctionSelector(fun, factories.newInstances());
        }

        public boolean isWritetimeSelectorFactory() {
            return factories.containsWritetimeSelectorFactory();
        }

        public boolean isTTLSelectorFactory() {
            return factories.containsTTLSelectorFactory();
        }

        public boolean isAggregateSelectorFactory() {
            return fun.isAggregate() || factories.doesAggregation();
        }
    };
}