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.haulmont.cuba.gui.ComponentsHelper.java

private static void fillChildComponents(Component.Container container, Collection<Component> components) {
    final Collection<Component> ownComponents = container.getOwnComponents();
    components.addAll(ownComponents);

    for (Component component : ownComponents) {
        if (component instanceof Component.Container) {
            fillChildComponents((Component.Container) component, components);
        }//from ww  w  . j  av  a 2 s.c  o  m
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java

/**
 * Retrieves the name that serves as the base for the file names into which info will be dumped along with the root
 * methods to be considered in one execution of the analyses.
 * /*from www  . j a va  2 s .  c  o m*/
 * @param root is the object based on which base name should be generated.
 * @param methods is the collection that will contain the root methods upon return.
 * @return a name along with the root methods via <code>methods</code>.
 * @pre root != null and methods != null
 * @post result != null and (methods.contains(root) or methods.containsAll(root))
 */
public static String getBaseNameOfFileAndRootMethods(final Object root, final Collection<SootMethod> methods) {
    final String _result;

    if (root instanceof SootMethod) {
        final SootMethod _sm = (SootMethod) root;
        _result = (_sm.getDeclaringClass().getJavaStyleName() + "_" + _sm.getSubSignature()).replaceAll(" ",
                "_");
        methods.add(_sm);
    } else {
        _result = "cumulative_" + System.currentTimeMillis();
        methods.addAll((Collection) root);
    }
    return _result;
}

From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java

static private void reportApprovedCurriculumLines(final Collection<ICurriculumEntry> result,
        final Collection<CurriculumLine> lines) {
    for (final CurriculumLine line : lines) {
        if (line.isApproved()) {
            if (line.isEnrolment()) {
                result.add((IEnrolment) line);
            } else if (line.isDismissal() && ((Dismissal) line).getCredits().isSubstitution()) {
                result.addAll(((Dismissal) line).getSourceIEnrolments());
            }/*from   www . j av a 2s . com*/
        }
    }
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.person.SearchPersonMatchingAnyParameter.java

public static CollectionPager<Person> run(String name, String email, String username, String documentIdNumber,
        IDDocumentType idDocumentType, String roleType, String degreeTypeString, String degreeId,
        String departmentId, Boolean activePersons, Integer studentNumber, Boolean externalPersons) {

    SearchParameters searchParameters = new SearchPersonMatchingAnyParameter.SearchParameters(name, email,
            username, documentIdNumber, idDocumentType == null ? null : idDocumentType.name(), roleType,
            degreeTypeString, degreeId, departmentId, activePersons, studentNumber, externalPersons,
            (String) null);// www. jav a  2s .  co  m

    if (searchParameters.emptyParameters()) {
        return new CollectionPager<Person>(new HashSet<Person>(), 25);
    }

    final Collection<Person> persons = new HashSet<Person>();

    if (searchParameters.getUsername() != null && searchParameters.getUsername().length() > 0) {

        final Person person = Person.readPersonByUsername(searchParameters.getUsername());
        if (person != null) {
            persons.add(person);
        }

    } else {

        if (searchParameters.getDocumentIdNumber() != null
                && searchParameters.getDocumentIdNumber().length() > 0) {
            persons.addAll(Person.findPersonByDocumentID(searchParameters.getDocumentIdNumber()));
        }
        if (searchParameters.getStudentNumber() != null) {
            final Student student = Student.readStudentByNumber(searchParameters.getStudentNumber());
            if (student != null) {
                persons.add(student.getPerson());
            }

        }
        if (searchParameters.getEmail() != null && searchParameters.getEmail().length() > 0) {
            final Person person = Person.readPersonByEmailAddress(searchParameters.getEmail());
            if (person != null) {
                persons.add(person);
            }

        }
        if (searchParameters.getMechanoGraphicalNumber() != null) {
            final Employee employee = Employee.readByNumber(searchParameters.getMechanoGraphicalNumber());
            final Student student = Student.readStudentByNumber(searchParameters.getMechanoGraphicalNumber());
            if (employee != null) {
                persons.add(employee.getPerson());
            }
            if (student != null) {
                persons.add(student.getPerson());
            }

        }
        if (searchParameters.getName() != null) {
            if (searchParameters.getExternalPersons() == null || !searchParameters.getExternalPersons()) {
                persons.addAll(Person.findInternalPerson(searchParameters.getName()));
                final Role roleBd = searchParameters.getRole();
                if (roleBd != null) {
                    for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator
                            .hasNext();) {
                        final Person person = peopleIterator.next();
                        if (!person.hasPersonRoles(roleBd)) {
                            peopleIterator.remove();
                        }
                    }
                }
                final Department department = searchParameters.getDepartment();
                if (department != null) {
                    for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator
                            .hasNext();) {
                        final Person person = peopleIterator.next();
                        final Teacher teacher = person.getTeacher();
                        if (teacher == null || teacher.getCurrentWorkingDepartment() != department) {
                            peopleIterator.remove();
                        }
                    }
                }
            }

            if (searchParameters.getExternalPersons() == null || searchParameters.getExternalPersons()) {
                persons.addAll(Person.findExternalPerson(searchParameters.getName()));
            }
        }
    }

    SearchPersonPredicate predicate = new SearchPersonMatchingAnyParameterPredicate(searchParameters);
    TreeSet<Person> result = new TreeSet<Person>(Person.COMPARATOR_BY_NAME_AND_ID);
    result.addAll(CollectionUtils.select(persons, predicate));
    return new CollectionPager<Person>(result, 25);
}

From source file:javadepchecker.Main.java

private static boolean depsFound(Collection<String> pkgs, Collection<String> deps) throws IOException {
    boolean found = true;
    Collection<String> jars = new ArrayList<String>();
    String[] bootClassPathJars = System.getProperty("sun.boot.class.path").split(":");
    // Do we need "java-config -r" here?
    for (String jar : bootClassPathJars) {
        File jarFile = new File(jar);
        if (jarFile.exists()) {
            jars.add(jar);/*  www. ja v  a 2 s  .  c o m*/
        }
    }
    for (Iterator<String> pkg = pkgs.iterator(); pkg.hasNext();) {
        jars.addAll(getPackageJars(pkg.next()));
    }

    if (jars.size() == 0) {
        return false;
    }
    ArrayList<String> jarClasses = new ArrayList<String>();
    for (String jarName : jars) {
        JarFile jar = new JarFile(jarName);
        for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
            jarClasses.add(e.nextElement().getName());
        }
    }
    for (String dep : deps) {
        if (!jarClasses.contains(dep)) {
            if (found) {
                System.out.println("Class files not found via DEPEND in package.env");
            }
            System.out.println("\t" + dep);
            found = false;
        }
    }
    return found;
}

From source file:javadepchecker.Main.java

/**
 * Check for orphaned class files not owned by any package in dependencies
 *
 * @param pkg Gentoo package name// w  ww .java2 s.  c  om
 * @param deps collection of dependencies for the package
 * @return boolean if the dependency is found or not
 * @throws IOException
 */
private static boolean depsFound(Collection<String> pkgs, Collection<String> deps) throws IOException {
    boolean found = true;
    Collection<String> jars = new ArrayList<>();
    String[] bootClassPathJars = System.getProperty("sun.boot.class.path").split(":");
    // Do we need "java-config -r" here?
    for (String jar : bootClassPathJars) {
        File jarFile = new File(jar);
        if (jarFile.exists()) {
            jars.add(jar);
        }
    }
    pkgs.forEach((String pkg) -> {
        jars.addAll(getPackageJars(pkg));
    });

    if (jars.isEmpty()) {
        return false;
    }
    ArrayList<String> jarClasses = new ArrayList<>();
    jars.forEach((String jarName) -> {
        try {
            JarFile jar = new JarFile(jarName);
            Collections.list(jar.entries()).forEach((JarEntry entry) -> {
                jarClasses.add(entry.getName());
            });
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    for (String dep : deps) {
        if (!jarClasses.contains(dep)) {
            if (found) {
                System.out.println("Class files not found via DEPEND in package.env");
            }
            System.out.println("\t" + dep);
            found = false;
        }
    }
    return found;
}

From source file:com.github.strawberry.guice.config.ConfigLoader.java

private static Collection<?> collectionOf(Field field, Map properties, String key) {
    Collection collection = collectionImplementationOf(field.getType());
    Object list = properties.get(key);
    Option<Type> genericType = genericTypeOf(field, 0);
    if (list != null) {
        if (list instanceof List) {
            if (genericType.exists(isAssignableTo(Collection.class))
                    || genericType.exists(isEqualTo(Object.class))) {
                collection.add(list);/*  w w w  . jav  a 2  s  . c o  m*/
            } else {
                collection.addAll((List) list);
            }
        } else if (list instanceof Collection) {
            if (genericType.exists(isAssignableTo(Collection.class))
                    || genericType.exists(isEqualTo(Object.class))) {
                collection.add(list);
            } else {
                collection.addAll((Collection) list);
            }
        } else if (list instanceof Map) {
            collection.add(((Map) list));
        } else {
            collection.add(list);
        }
        return collection;
    } else {
        return collection;
    }
}

From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java

private static void addRequestAdapters(Collection<ServletRequestBehaviorTrackingAdapter> accum,
        ListableBeanFactory beanFactory, boolean hasFilter) {
    @SuppressWarnings("unchecked")
    Collection<ServletRequestBehaviorTrackingAdapter> beans = beanFactory
            .getBeansOfType(ServletRequestBehaviorTrackingAdapter.class, false, false).values();
    if (!beans.isEmpty()) {
        if (hasFilter)
            throw new IllegalStateException(
                    "You have configured both BehaviorTrackingFilters and BehaviorTrackingListeners in the same web application.  Only one of these methods may be used in a single application.");
        accum.addAll(beans);
    }/*from w  w  w. j  a v a  2s .  com*/
}

From source file:com.bosscs.spark.commons.utils.Utils.java

/**
 * Returns an instance clone./*w  w w .  j  a va 2  s .  co  m*/
 * this method gets every class property by reflection, including its parents properties
 * @param t
 * @param <T>
 * @return T object.
 */
public static <T> T cloneObjectWithParents(T t) throws IllegalAccessException, InstantiationException {
    T clone = (T) t.getClass().newInstance();

    List<Field> allFields = new ArrayList<>();

    Class parentClass = t.getClass().getSuperclass();

    while (parentClass != null) {
        Collections.addAll(allFields, parentClass.getDeclaredFields());
        parentClass = parentClass.getSuperclass();
    }

    Collections.addAll(allFields, t.getClass().getDeclaredFields());

    for (Field field : allFields) {
        int modifiers = field.getModifiers();
        //We skip final and static fields
        if ((Modifier.FINAL & modifiers) != 0 || (Modifier.STATIC & modifiers) != 0) {
            continue;
        }
        field.setAccessible(true);

        Object value = field.get(t);

        if (Collection.class.isAssignableFrom(field.getType())) {
            Collection collection = (Collection) field.get(clone);
            if (collection == null) {
                collection = (Collection) field.get(t).getClass().newInstance();
            }
            collection.addAll((Collection) field.get(t));
            value = collection;
        } else if (Map.class.isAssignableFrom(field.getType())) {
            Map clonMap = (Map) field.get(t).getClass().newInstance();
            clonMap.putAll((Map) field.get(t));
            value = clonMap;
        }
        field.set(clone, value);
    }

    return clone;
}

From source file:com.opendesign.utils.CmnUtil.java

/**
 * addAll/*from  ww  w  .ja  va2  s . co  m*/
 * 
 * @param toAddList
 * @param col
 */
public static <T> void addAll(Collection<T> toAddList, Collection<T> col) {
    if (col != null && toAddList != null) {
        toAddList.addAll(col);
    }
}