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

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

Introduction

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

Prototype

public static <T> boolean addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd) 

Source Link

Document

Adds all elements in iterable to collection .

Usage

From source file:org.ow2.petals.cloud.manager.core.puppet.DownloadFilesScriptBuilder.java

/**
 * Get all the URIs from the node and the context. URIs can be found on node software, properties, ...
 *
 * @param node/*w w w  .  jav  a 2 s  .c  o  m*/
 * @param context
 * @return
 */
protected List<Map<String, String>> getURIs(Node node, Context context) {

    List<Map<String, String>> result = Lists.newArrayList();

    // get node uris
    Iterable<Map<String, String>> n = Iterables
            .transform(Iterables.filter(node.getProperties(), new Predicate<Property>() {
                public boolean apply(org.ow2.petals.cloud.manager.api.deployment.Property input) {
                    return input.getType() != null && input.getType().equals(Constants.URL_TYPE)
                            && input.getValue() != null && input.getValue().startsWith("http://");
                }
            }), new Function<Property, Map<String, String>>() {
                public Map<String, String> apply(org.ow2.petals.cloud.manager.api.deployment.Property input) {
                    // we got an input property which is a uri type with http value
                    // TODO : Get destination from the input value suffix
                    return ImmutableMap.of("source", input.getValue(), "destination", input.getName());
                }
            });

    if (n != null) {
        Iterables.addAll(result, n);
    }

    // get software uris
    Iterable<Map<String, String>> softwares = Iterables.transform(getSoftwares(node, context),
            new Function<Software, Map<String, String>>() {
                public Map<String, String> apply(org.ow2.petals.cloud.manager.api.deployment.Software input) {
                    return ImmutableMap.of("source", input.getSource(), "destination", input.getName());
                }
            });
    if (softwares != null) {
        Iterables.addAll(result, softwares);
    }
    return result;
}

From source file:de.cosmocode.palava.maven.ipcstub.GeneratorModule.java

/**
 * Generates stub files for all found IpcCommands in the classpath.
 *
 * {@inheritDoc}/*from   w ww .  j  a v  a2  s .co  m*/
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final File targetDirectory = new File(project.getBuild().getOutputDirectory(), "ipcstub");

    // check configurations and aggregate all required packages
    final Set<String> allPackages = Sets.newHashSet();
    for (Generator generator : generators) {
        generator.check();
        allPackages.addAll(generator.getPackages());
    }

    log.info("Searching for IpcCommands in:");
    for (String pkg : allPackages) {
        log.info("    " + pkg);
    }

    // search for IpcCommands in all required packages
    final Set<Class<? extends IpcCommand>> foundClasses = Sets.newTreeSet(Reflection.orderByName());
    Iterables.addAll(foundClasses, generateCommandList(allPackages));

    log.info("Found " + foundClasses.size() + " IpcCommands; generating stubs...");

    // filter classes and let the generators do their work
    for (Generator generator : generators) {
        final Set<Class<? extends IpcCommand>> filteredClasses = Sets.newLinkedHashSet();
        for (Class<? extends IpcCommand> foundClass : foundClasses) {
            for (String requiredPackage : generator.getPackages()) {
                if (foundClass.getName().startsWith(requiredPackage + ".")) {
                    filteredClasses.add(foundClass);
                    break;
                }
            }
        }

        // whats the target directory?
        final File stubTargetDirectory = new File(targetDirectory, generator.getName());

        // now call the generator
        generator.generate(log, filteredClasses, stubTargetDirectory);
    }
}

From source file:dk.ilios.spanner.model.Trial.java

public void addAllMeasurements(Iterable<Measurement> measurements) {
    checkIsComplete();
    Iterables.addAll(this.measurements, measurements);
}

From source file:uk.co.unclealex.executable.generator.ScripterImpl.java

/**
 * {@inheritDoc}//from   w w w  . j  av  a2 s.  c o  m
 */
@Override
public void generate(Path targetPath, Path classesDirectory, String homeExpression, String version,
        Path workDirectory, Iterable<Path> dependencyJarFiles) throws IOException, ExecutableScanException {
    Path executableJarFileOrDirectory = jarService.findJarFileOrDirectoryDefiningClass(
            ExecutableEntryPoint.class.getClassLoader(), ExecutableEntryPoint.class.getName());
    List<Path> allJarFilesOrDirectories = Lists.newArrayList();
    allJarFilesOrDirectories.add(executableJarFileOrDirectory);
    allJarFilesOrDirectories.add(classesDirectory);
    allJarFilesOrDirectories.add(generateCodeJar(classesDirectory, workDirectory, dependencyJarFiles));
    Iterables.addAll(allJarFilesOrDirectories, dependencyJarFiles);
    JarService jarService = getJarService();
    List<KnownLengthInputSupplier> jarInputSuppliers = Lists.newLinkedList();
    KnownLengthInputSupplierFactory knownLengthInputSupplierFactory = getKnownLengthInputSupplierFactory();
    for (Path jarFileOrDirectory : allJarFilesOrDirectories) {
        Path jarFile;
        if (Files.isDirectory(jarFileOrDirectory)) {
            Path temp = Files.createTempFile(workDirectory, "generated-", ".jar");
            jarService.generateJar(jarFileOrDirectory, temp);
            jarFile = temp;
        } else {
            jarFile = jarFileOrDirectory;
        }
        jarInputSuppliers.add(knownLengthInputSupplierFactory.createPathKnownLengthInputSupplier(jarFile));
    }
    KnownLengthInputSupplier executableJarInputSupplier = jarInputSuppliers.remove(0);
    ScriptGenerator scriptGenerator = getScriptGeneratorFactory().createScriptGenerator();

    try (OutputStream out = Files.newOutputStream(targetPath)) {
        scriptGenerator.generateScript(executableJarInputSupplier, jarInputSuppliers, homeExpression, version,
                out);
    }
    Files.setPosixFilePermissions(targetPath, PosixFilePermissions.fromString("rwxr--r--"));
}

From source file:uk.co.unclealex.process.builder.BuildingProcessRequest.java

/**
 * {@inheritDoc}//from  www  . j av a  2s.  c om
 */
@Override
public BuildableProcessRequest withCallbacks(final Iterable<ProcessCallback> processCallbacks) {
    Iterables.addAll(getProcessCallbacks(), processCallbacks);
    return this;
}

From source file:com.zimbra.soap.admin.message.CheckBlobConsistencyRequest.java

public void setVolumes(Iterable<IntIdAttr> volumes) {
    this.volumes.clear();
    if (volumes != null) {
        Iterables.addAll(this.volumes, volumes);
    }/*w  w w. j av a2 s .c  om*/
}

From source file:com.zimbra.soap.admin.type.ContactGroupMember.java

public static List<ContactGroupMemberInterface> toInterfaces(Iterable<ContactGroupMember> params) {
    if (params == null)
        return null;
    List<ContactGroupMemberInterface> newList = Lists.newArrayList();
    Iterables.addAll(newList, params);
    return newList;
}

From source file:org.eclipse.ziggurat.ocl.ZigguratOCLPlugin.java

private static Collection<DefOperationCS> getOperations(BaseResource resource) {
    Collection<DefOperationCS> result = Lists.newArrayList();
    EList<EObject> contents = resource.getContents();
    if (contents.size() == 1) {
        EObject root = contents.get(0);//from   w  ww .  j  av  a  2 s  .  c o m
        if (root instanceof CompleteOCLDocumentCS) {
            EList<ContextDeclCS> contexts = ((CompleteOCLDocumentCS) root).getContexts();
            for (ContextDeclCS context : contexts) {
                if (context instanceof ClassifierContextDeclCS) {
                    EList<DefCS> definitions = ((ClassifierContextDeclCS) context).getDefinitions();
                    Iterables.addAll(result, Iterables.filter(definitions, DefOperationCS.class));
                }
            }
        }
    }
    return result;
}

From source file:com.zimbra.soap.mail.message.ImportDataRequest.java

public void setDataSources(Iterable<DataSourceNameOrId> dataSources) {
    this.dataSources.clear();
    if (dataSources != null) {
        Iterables.addAll(this.dataSources, dataSources);
    }// ww  w  .ja va  2s .com
}

From source file:org.xwiki.search.solr.internal.reference.SpaceSolrReferenceResolver.java

@Override
public List<EntityReference> getReferences(EntityReference spaceReference) throws SolrIndexerException {
    List<EntityReference> result = new ArrayList<EntityReference>();
    EntityReference wikiReference = spaceReference.extractReference(EntityType.WIKI);
    String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference);

    // Ignore the space reference because it is not indexable.

    // Make sure the list of spaces is from the requested wiki
    List<String> documentNames;
    try {/*  w w w.  j ava  2  s  .  c  om*/
        documentNames = this.queryManager.getNamedQuery("getSpaceDocsName").setWiki(wikiReference.getName())
                .bindValue("space", localSpaceReference).execute();
    } catch (QueryException e) {
        throw new SolrIndexerException("Failed to query space [" + spaceReference + "] documents", e);
    }

    for (String documentName : documentNames) {
        EntityReference documentReference = new EntityReference(documentName, EntityType.DOCUMENT,
                spaceReference);

        try {
            Iterables.addAll(result, this.documentResolverProvider.get().getReferences(documentReference));
        } catch (Exception e) {
            this.logger.error("Failed to resolve references for document [" + documentReference + "]", e);
        }
    }

    return result;
}