Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

In this page you can find the example usage for java.util Collection addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:net.groupbuy.service.impl.BaseServiceImpl.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyProperties(Object source, Object target, String[] ignoreProperties) throws BeansException {
    Assert.notNull(source, "Source must not be null");
    Assert.notNull(target, "Target must not be null");

    PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(target.getClass());
    List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null;
    for (PropertyDescriptor targetPd : targetPds) {
        if (targetPd.getWriteMethod() != null
                && (ignoreProperties == null || (!ignoreList.contains(targetPd.getName())))) {
            PropertyDescriptor sourcePd = BeanUtils.getPropertyDescriptor(source.getClass(),
                    targetPd.getName());
            if (sourcePd != null && sourcePd.getReadMethod() != null) {
                try {
                    Method readMethod = sourcePd.getReadMethod();
                    if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
                        readMethod.setAccessible(true);
                    }//w  w  w  . j  ava2  s  .  c o  m
                    Object sourceValue = readMethod.invoke(source);
                    Object targetValue = readMethod.invoke(target);
                    if (sourceValue != null && targetValue != null && targetValue instanceof Collection) {
                        Collection collection = (Collection) targetValue;
                        collection.clear();
                        collection.addAll((Collection) sourceValue);
                    } else {
                        Method writeMethod = targetPd.getWriteMethod();
                        if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
                            writeMethod.setAccessible(true);
                        }
                        writeMethod.invoke(target, sourceValue);
                    }
                } catch (Throwable ex) {
                    throw new FatalBeanException("Could not copy properties from source to target", ex);
                }
            }
        }
    }
}

From source file:com.vaynberg.wicket.select2.Select2MultiChoice.java

@Override
public void updateModel() {
    Collection<T> choices = getModelObject();
    Collection<T> selection = getConvertedInput();

    if (choices == null) {
        setModelObject(selection);/*from w  w  w .j  av a 2 s. c  o m*/
    } else {
        choices.clear();
        choices.addAll(selection);
        setModelObject(choices);
    }
}

From source file:io.mindmaps.migration.csv.CSVDataMigrator.java

/**
 * Migrate a CSV schema into a Mindmaps ontology
 * @return var patterns representing the migrated Mindmaps ontology
 *///w  w w. jav a  2  s.c  o  m
public Collection<Var> migrate() {
    Collection<Var> collection = new HashSet<>();

    Iterator<Collection<Var>> iterator = iterator();

    while (iterator.hasNext()) {
        collection.addAll(iterator.next());
    }
    return collection;
}

From source file:com.epam.cme.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final String categoryCode,
        final ProductSearchPageData<SearchStateData, ProductData> searchPageData)
        throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    final boolean emptyBreadcrumbs = CollectionUtils.isEmpty(searchPageData.getBreadcrumbs());
    Breadcrumb breadcrumb;//from  w  w  w .  j  ava  2 s . c  o  m
    if (categoryCode == null) {
        breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchPageData.getFreeTextSearch()),
                StringEscapeUtils.escapeHtml(searchPageData.getFreeTextSearch()),
                (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }
    return breadcrumbs;
}

From source file:com.netflix.genie.web.jobs.workflow.impl.JobTask.java

/**
 * {@inheritDoc}/*from   w w w.  j  ava2  s  .com*/
 */
@Override
public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException {
    final long start = System.nanoTime();
    final Set<Tag> tags = Sets.newHashSet();
    try {
        final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context
                .get(JobConstants.JOB_EXECUTION_ENV_KEY);
        final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath();
        final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY);
        final String jobId = jobExecEnv.getJobRequest().getId()
                .orElseThrow(() -> new GeniePreconditionException("No job id found. Unable to continue"));
        log.info("Starting Job Task for job {}", jobId);

        final Optional<String> setupFile = jobExecEnv.getJobRequest().getSetupFile();
        if (setupFile.isPresent()) {
            final String jobSetupFile = setupFile.get();
            if (StringUtils.isNotBlank(jobSetupFile)) {
                final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + jobSetupFile
                        .substring(jobSetupFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1);

                fts.getFile(jobSetupFile, localPath);

                writer.write("# Sourcing setup file specified in job request" + System.lineSeparator());
                writer.write(
                        JobConstants.SOURCE
                                + localPath.replace(jobWorkingDirectory,
                                        "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}")
                                + System.lineSeparator());

                // Append new line
                writer.write(System.lineSeparator());
            }
        }

        // Iterate over and get all configs and dependencies
        final Collection<String> configsAndDependencies = Sets.newHashSet();
        configsAndDependencies.addAll(jobExecEnv.getJobRequest().getDependencies());
        configsAndDependencies.addAll(jobExecEnv.getJobRequest().getConfigs());
        for (final String dependentFile : configsAndDependencies) {
            if (StringUtils.isNotBlank(dependentFile)) {
                final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + dependentFile
                        .substring(dependentFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1);

                fts.getFile(dependentFile, localPath);
            }
        }

        // Copy down the attachments if any to the current working directory
        this.attachmentService.copy(jobId, jobExecEnv.getJobWorkingDir());
        // Delete the files from the attachment service to save space on disk
        this.attachmentService.delete(jobId);

        // Print out the current Envrionment to a env file before running the command.
        writer.write("# Dump the environment to a env.log file" + System.lineSeparator());
        writer.write("env | sort > " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}"
                + JobConstants.GENIE_ENV_PATH + System.lineSeparator());

        // Append new line
        writer.write(System.lineSeparator());

        writer.write("# Kick off the command in background mode and wait for it using its pid"
                + System.lineSeparator());

        writer.write(StringUtils.join(jobExecEnv.getCommand().getExecutable(), StringUtils.SPACE)
                + JobConstants.WHITE_SPACE + jobExecEnv.getJobRequest().getCommandArgs().orElse(EMPTY_STRING)
                + JobConstants.STDOUT_REDIRECT + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}/"
                + JobConstants.STDOUT_LOG_FILE_NAME + JobConstants.STDERR_REDIRECT + "${"
                + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}/" + JobConstants.STDERR_LOG_FILE_NAME + " &"
                + System.lineSeparator());

        // Save PID of children process, used in trap handlers to kill and verify termination
        writer.write(JobConstants.EXPORT + JobConstants.CHILDREN_PID_ENV_VAR + "=$!" + System.lineSeparator());
        // Wait for the above process started in background mode. Wait lets us get interrupted by kill signals.
        writer.write("wait ${" + JobConstants.CHILDREN_PID_ENV_VAR + "}" + System.lineSeparator());

        // Append new line
        writer.write(System.lineSeparator());

        // capture exit code and write to temporary genie.done
        writer.write("# Write the return code from the command in the done file." + System.lineSeparator());
        writer.write(JobConstants.GENIE_DONE_FILE_CONTENT_PREFIX + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR
                + "}" + "/" + JobConstants.GENIE_TEMPORARY_DONE_FILE_NAME + System.lineSeparator());

        // atomically swap temporary and actual genie.done file if one doesn't exist
        writer.write(
                "# Swapping done file, unless one exist created by trap handler." + System.lineSeparator());
        writer.write("mv -n " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + "/"
                + JobConstants.GENIE_TEMPORARY_DONE_FILE_NAME + " " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR
                + "}" + "/" + JobConstants.GENIE_DONE_FILE_NAME + System.lineSeparator());

        // Print the timestamp once its done running.
        writer.write("echo End: `date '+%Y-%m-%d %H:%M:%S'`\n");

        log.info("Finished Job Task for job {}", jobId);
        MetricsUtils.addSuccessTags(tags);
    } catch (final Throwable t) {
        MetricsUtils.addFailureTagsWithException(tags, t);
        throw t;
    } finally {
        this.getRegistry().timer(JOB_TASK_TIMER_NAME, tags).record(System.nanoTime() - start,
                TimeUnit.NANOSECONDS);
    }
}

From source file:corner.cache.services.impl.local.LocalCacheImpl.java

public Collection<Object> values() {
    checkAll();// ww w . j  a  v  a2  s . c  om
    Collection<Object> values = new ArrayList<Object>();
    values.addAll(cache.values());
    return values;
}

From source file:eu.dime.ps.semantic.query.BasicQueryTest.java

@Test
public void testMultipleResourceTypes() throws Exception {
    Collection<Resource> results = new ArrayList<Resource>();
    results.addAll(resourceStore.find(Folder.class).results());
    results.addAll(resourceStore.find(FileDataObject.class).results());
    assertEquals(14, results.size());/*  ww w  .java2 s . co m*/
}

From source file:com.exxonmobile.ace.hybris.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText,
        final boolean emptyBreadcrumbs) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    if (categoryCode == null) {
        final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText),
                StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);// w  w w.  ja  v  a 2s.c  o  m
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            } else {
                categoryModels.remove(categoryModel);
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }

    return breadcrumbs;
}

From source file:com.pedra.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText,
        final boolean emptyBreadcrumbs) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    if (categoryCode == null) {
        final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText),
                StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);//from   w w  w .j  a  v a 2s.c  o m
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();

            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            } else {
                categoryModels.remove(categoryModel);
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }
    return breadcrumbs;
}

From source file:hudson.plugins.clearcase.ucm.service.BaselineService.java

public Baseline[] getDependentBaselines(Baseline... baselines) throws IOException, InterruptedException {
    Collection<Baseline> result = new ArrayList<Baseline>();
    for (Baseline baseline : baselines) {
        Baseline[] dependentBaselines = getDependentBaselines(baseline);
        result.addAll(Arrays.asList(dependentBaselines));
    }//from   w w w  .j a va2  s .c o m
    return result.toArray(new Baseline[result.size()]);
}