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:com.seleniumtests.reporter.reporters.SeleniumTestsReporter2.java

/**
 * Generate summary report for all test methods
 * @param suites//from w w w.j  a  v a  2  s.  c  o m
 * @param suiteName
 * @param map
 * @return   map containing test results
 */
public Map<ITestContext, List<ITestResult>> generateSuiteSummaryReport(final List<ISuite> suites) {

    // build result list for each TestNG test
    Map<ITestContext, List<ITestResult>> methodResultsMap = new LinkedHashMap<>();

    for (ISuite suite : suites) {
        Map<String, ISuiteResult> tests = suite.getResults();
        for (ISuiteResult r : tests.values()) {
            ITestContext context = r.getTestContext();
            List<ITestResult> resultList = new ArrayList<>();

            Collection<ITestResult> methodResults = new ArrayList<>();
            methodResults.addAll(context.getFailedTests().getAllResults());
            methodResults.addAll(context.getPassedTests().getAllResults());
            methodResults.addAll(context.getSkippedTests().getAllResults());

            methodResults = methodResults.stream()
                    .sorted((r1, r2) -> Long.compare(r1.getStartMillis(), r2.getStartMillis()))
                    .collect(Collectors.toList());

            for (ITestResult result : methodResults) {
                SeleniumTestsContext testContext = (SeleniumTestsContext) result
                        .getAttribute(SeleniumRobotTestListener.TEST_CONTEXT);

                String fileName;
                if (testContext != null) {
                    fileName = testContext.getRelativeOutputDir() + "/TestReport.html";
                } else {
                    fileName = getTestName(result) + "/TestReport.html";
                }
                result.setAttribute(METHOD_RESULT_FILE_NAME, fileName);
                result.setAttribute(SeleniumRobotLogger.UNIQUE_METHOD_NAME, getTestName(result));

            }
            resultList.addAll(methodResults);

            methodResultsMap.put(context, resultList);
        }
    }

    try {
        VelocityEngine ve = initVelocityEngine();

        Template t = ve.getTemplate("/reporter/templates/report.part.suiteSummary.vm");
        VelocityContext context = new VelocityContext();

        context.put("tests", methodResultsMap);
        context.put("steps", TestLogging.getTestsSteps());

        StringWriter writer = new StringWriter();
        t.merge(context, writer);
        mOut.write(writer.toString());

    } catch (Exception e) {
        generationErrorMessage = "generateSuiteSummaryReport error:" + e.getMessage();
        logger.error("generateSuiteSummaryReport error: ", e);
    }

    return methodResultsMap;

}

From source file:de.hybris.platform.b2bacceleratorfacades.order.populators.B2BUnitPopulator.java

protected B2BUnitData populateUnitRelations(final B2BUnitModel source, final B2BUnitData target) {
    // unit's budgets
    if (CollectionUtils.isNotEmpty(source.getBudgets())) {
        target.setBudgets(Converters.convertAll(source.getBudgets(), getB2BBudgetConverter()));
    }//from  w  ww .  java2  s.  co m

    // unit's cost centers
    if (CollectionUtils.isNotEmpty(source.getCostCenters())) {
        target.setCostCenters(Converters.convertAll(
                CollectionUtils.select(source.getCostCenters(),
                        new BeanPropertyValueEqualsPredicate(B2BCostCenterModel.ACTIVE, Boolean.TRUE)),
                getB2BCostCenterConverter()));
    }

    // unit approvers
    if (CollectionUtils.isNotEmpty(source.getApprovers())) {
        final UserGroupModel approverGroup = userService.getUserGroupForUID(B2BConstants.B2BAPPROVERGROUP);
        target.setApprovers(
                Converters.convertAll(CollectionUtils.select(source.getApprovers(), new Predicate() {
                    @Override
                    public boolean evaluate(final Object object) {
                        final B2BCustomerModel b2bCustomerModel = (B2BCustomerModel) object;
                        return userService.isMemberOfGroup(b2bCustomerModel, approverGroup);
                    }
                }), getB2BCustomerConverter()));
    }

    // unit addresses
    if (CollectionUtils.isNotEmpty(source.getAddresses())) {
        target.setAddresses(Converters.convertAll(source.getAddresses(), getAddressConverter()));
    }

    // unit's  customers
    final Collection<B2BCustomerModel> b2BCustomers = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BCUSTOMERGROUP, false);
    if (CollectionUtils.isNotEmpty(b2BCustomers)) {
        target.setCustomers(Converters.convertAll(b2BCustomers, getB2BCustomerConverter()));
    }

    // unit's  managers
    final Collection<B2BCustomerModel> managers = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BMANAGERGROUP, false);
    if (CollectionUtils.isNotEmpty(managers)) {
        target.setManagers(Converters.convertAll(managers, getB2BCustomerConverter()));
    }

    // unit's administrators
    final Collection<B2BCustomerModel> administrators = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BADMINGROUP, false);
    if (CollectionUtils.isNotEmpty(administrators)) {
        target.setAdministrators(Converters.convertAll(administrators, getB2BCustomerConverter()));
    }

    final Collection<PrincipalModel> accountManagers = new HashSet<PrincipalModel>();
    if (source.getAccountManager() != null) {
        accountManagers.add(source.getAccountManager());
    }
    if (CollectionUtils.isNotEmpty(source.getAccountManagerGroups())) {
        for (final UserGroupModel userGroupModel : source.getAccountManagerGroups()) {
            accountManagers.addAll(userGroupModel.getMembers());
        }
    }
    if (CollectionUtils.isNotEmpty(accountManagers)) {
        target.setAccountManagers(Converters.convertAll(accountManagers, getPrincipalConverter()));
    }

    return target;
}

From source file:net.sf.jsptest.compiler.jsp20.mock.MockHttpServletRequest.java

private Collection join(Collection collection, Collection anotherCollection) {
    Collection joined = new ArrayList();
    if (collection != null) {
        joined.addAll(collection);
    }/*from  ww  w .  jav  a2  s.  c o m*/
    if (anotherCollection != null) {
        joined.addAll(anotherCollection);
    }
    return joined;
}

From source file:de.hybris.platform.category.impl.DefaultCategoryService.java

private Collection<CategoryModel> getAllSubcategories(final Collection<CategoryModel> categories) {
    Collection<CategoryModel> result = null;
    Collection<CategoryModel> currentLevel = new ArrayList<CategoryModel>();
    for (final CategoryModel categoryModel : categories) {
        final List<CategoryModel> subCategories = categoryModel.getCategories();
        if (subCategories != null) {
            currentLevel.addAll(subCategories);
        }/*from  w ww. ja va 2 s. c  o m*/
    }

    while (!CollectionUtils.isEmpty(currentLevel)) {
        for (final Iterator iterator = currentLevel.iterator(); iterator.hasNext();) {
            final CategoryModel categoryModel = (CategoryModel) iterator.next();
            if (result == null) {
                result = new HashSet<CategoryModel>();
            }
            if (!result.add(categoryModel)) {
                // avoid cycles by removing all which are already found
                iterator.remove();
            }
        }

        if (currentLevel.isEmpty()) {
            break;
        }
        final Collection<CategoryModel> nextLevel = getAllSubcategories(currentLevel);
        currentLevel = nextLevel;
    }

    return result == null ? Collections.EMPTY_LIST : result;
}

From source file:edu.ksu.cis.indus.common.soot.SootBasedDriver.java

/**
 * Loads up the classes specified via <code>setClassNames()</code> and also collects the possible entry points into the
 * system being analyzed. All <code>public static void main()</code> methods defined in <code>public</code> classes
 * that are named via <code>args</code>are considered as entry points. It uses the classpath set via
 * <code>addToSootClassPath</code>.
 * //ww  w . j  a v  a 2 s.  c  o  m
 * @param options to be used while setting up Soot infrastructure.
 * @return a soot scene that provides the classes to be analyzed.
 */
@NonNull
private Scene loadupClassesAndCollectMains(@NonNull final String[] options) {
    final Scene _result = Scene.v();
    String _temp = _result.getSootClassPath();
    Options.v().parse(options);

    if (_temp != null) {
        _temp += File.pathSeparator + classpathToAdd + File.pathSeparator
                + System.getProperty("java.class.path");
    } else {
        _temp = classpathToAdd;
    }
    _result.setSootClassPath(_temp);

    for (final Iterator<String> _i = classNames.iterator(); _i.hasNext();) {
        final SootClass _sc = _result.loadClassAndSupport(_i.next());
        _sc.setApplicationClass();
    }

    final Collection<SootClass> _mc = new HashSet<SootClass>();
    _mc.addAll(_result.getClasses());

    RootMethodTrapper _rmt = rootMethodTrapper;

    if (_rmt == null) {
        _rmt = DEFAULT_INSTANCE_OF_ROOT_METHOD_TRAPPER;
    }

    _rmt.setClassNames(Collections.unmodifiableCollection(classNames));

    for (final Iterator<SootClass> _i = _mc.iterator(); _i.hasNext();) {
        final SootClass _sc = _i.next();

        if (_rmt.considerClassForEntryPoint(_sc)) {
            final Collection<SootMethod> _methods = _sc.getMethods();

            for (final Iterator<SootMethod> _j = _methods.iterator(); _j.hasNext();) {
                final SootMethod _sm = _j.next();

                if (_rmt.isThisARootMethod(_sm)) {
                    rootMethods.add(_sm);
                }
            }
        }
    }
    Util.fixupThreadStartBody(_result);

    if (Constants.shouldLoadMethodBodiesDuringInitialization()) {
        loadupMethodBodies();
    }

    return _result;
}

From source file:biz.c24.io.mule.C24Connector.java

private Reflections getReflections() {
    debug("getting reflections");
    if (reflections == null) {
        synchronized (this) {
            if (reflections == null) {
                debug("reflections is null");
                // See if we can use pre-built metadata
                Reflections r = Reflections.collect();
                debug("tried to pick up collected metadata");
                if (r == null) {
                    debug("got none");
                    // No. Scan the classloader instead.
                    ConfigurationBuilder builder = new ConfigurationBuilder();

                    if (getBasePackage() != null) {
                        builder.filterInputsBy(new FilterBuilder().include(getBasePackage()));
                    }// w  w w .  ja va2  s.c o m

                    debug("build config");

                    Collection<URL> urls = ClasspathHelper.forJavaClassPath();
                    urls.addAll(ClasspathHelper.forClassLoader());

                    builder.setUrls(urls).setScanners(new SubTypesScanner());

                    r = new Reflections(builder);
                    debug("created reflections");
                    reflections = r;
                }
            }
        }
    }

    return reflections;

}

From source file:com.anhth12.lambda.app.serving.als.model.ALSServingModel.java

void pruneKnownItems(Collection<String> users, final Collection<String> items) {
    try (AutoLock al = new AutoLock(xLock.writeLock())) {
        knownItems.removeIf(new KeyOnlyBiPredicate<>(new AndPredicate<>(new NotContainsPredicate<>(users),
                new NotContainsPredicate<>(recentNewUsers))));
    }/*from w  w w.  j a v a2 s .  c  o  m*/

    final Collection<String> allRecentKnownItems = new HashSet<>();
    for (int partition = 0; partition < Y.length; partition++) {
        try (AutoLock al = new AutoLock(yLocks[partition].writeLock())) {
            allRecentKnownItems.addAll(recentNewItems[partition]);
        }
    }

    try (AutoLock al = new AutoLock(xLock.readLock())) {
        for (ObjSet<String> knownItemsForUser : knownItems.values()) {
            synchronized (knownItemsForUser) {
                knownItemsForUser.removeIf(new Predicate<String>() {
                    @Override
                    public boolean test(String value) {
                        return !items.contains(value) && !allRecentKnownItems.contains(value);
                    }
                });
            }
        }
    }

}

From source file:de.hybris.platform.category.impl.DefaultCategoryService.java

private Collection<CategoryModel> getAllSupercategories(final Collection<CategoryModel> categories) {
    Collection<CategoryModel> result = null;
    Collection<CategoryModel> currentLevel = new ArrayList<CategoryModel>();
    for (final CategoryModel categoryModel : categories) {
        final List<CategoryModel> superCategories = categoryModel.getSupercategories();
        if (superCategories != null) {
            currentLevel.addAll(superCategories);
        }/*from www  . j a v a  2 s. c om*/
    }

    while (!CollectionUtils.isEmpty(currentLevel)) {
        for (final Iterator iterator = currentLevel.iterator(); iterator.hasNext();) {
            final CategoryModel categoryModel = (CategoryModel) iterator.next();
            if (result == null) {
                result = new HashSet<CategoryModel>();
            }
            if (!result.add(categoryModel)) {
                // avoid cycles by removing all which are already found
                iterator.remove();
            }
        }

        if (currentLevel.isEmpty()) {
            break;
        }
        final Collection<CategoryModel> nextLevel = getAllSupercategories(currentLevel);
        currentLevel = nextLevel;
    }

    return result == null ? Collections.EMPTY_LIST : result;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.ShiftDistributionFirstYearDA.java

private Collection<Degree> readFirstYearFirstTimeValidDegrees() {
    final Collection<Degree> result = new ArrayList<Degree>();
    result.addAll(Degree.readAllByDegreeType(DegreeType.BOLONHA_DEGREE));
    result.addAll(Degree.readAllByDegreeType(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE));
    return removeDegreesWithNoVacancy(result);
}

From source file:com.knowbout.epg.processor.ScheduleParser.java

private void createSchedule(ChannelSchedule channel, List<NetworkLineup> lineups, boolean localHeadend) {
    Session session = HibernateUtil.currentSession();
    Program program = (Program) session.load(Program.class, channel.getProgramId());
    //Update program rating and runtime. Overloading this information
    Network network = Network.findByCallSign(channel.getStation().getCallSign());
    String tvRating = null;/*from  ww  w . jav a  2 s  . com*/
    int duration = 0;
    Collection<ScheduleAiring> airings;
    if (localHeadend) {
        airings = new ArrayList<ScheduleAiring>();
        airings.addAll(channel.getPacificAirings().values());
        airings.addAll(channel.getSingleStationAirings());
    } else {
        airings = channel.getValidAirings();
    }
    for (ScheduleAiring airing : airings) {
        String rawData = airing.getInputText();
        Schedule schedule = parseSchedule(airing, program, rawData);
        schedule.setNetwork(network);
        HashMap<Date, Schedule> dates = new HashMap<Date, Schedule>();
        for (NetworkLineup lineup : lineups) {
            Date airTime = null;
            //We only modify the time if there are multiple stations (TLC and TLCP)   if
            //It is like ESPN which only has a single feed, east and west coast get the same
            //exact content at the same time (GMT based), just at different local time because of the timezone
            if (channel.getStation().isOnMultipleHeadends()) {
                if (channel.getStation().isAffilateStation()) {
                    airTime = lineup.applyAffiliationDelay(schedule.getAirTime());
                } else {
                    airTime = lineup.applyDelay(schedule.getAirTime());
                }
            }
            Schedule existingSchedule = dates.get(airTime);
            if (existingSchedule != null) {
                NetworkSchedule ns = new NetworkSchedule(existingSchedule, lineup,
                        existingSchedule.getAirTime());
                ns.insert();
            } else {
                if (tvRating == null) {
                    tvRating = schedule.getTvRating();
                    duration = schedule.getDuration();
                }
                existingSchedule = insertSchedule(channel, schedule, lineup);
                if (existingSchedule != null) {
                    existingSchedule.insert();
                    NetworkSchedule ns = new NetworkSchedule(existingSchedule, lineup,
                            existingSchedule.getAirTime());
                    ns.insert();
                    dates.put(airTime, existingSchedule);
                }
            }
        }
    }
    //Since the program does not have this information on it, add it to the override the movie
    //specific values with TV values.
    program.setMpaaRating(tvRating);
    program.setRunTime(duration);
}