Example usage for java.util Collection add

List of usage examples for java.util Collection add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Ensures that this collection contains the specified element (optional operation).

Usage

From source file:cc.pinel.mangue.util.MangaSearch.java

/**
 * Searches mangas remotely using the query.
 * //ww w.j  av a2 s .c o m
 * @param query the query to be searched
 * @return the list of mangas filtered
 * @throws MalformedURLException
 * @throws IOException
 */
public static Collection search(String query) throws MalformedURLException, IOException {
    Collection mangas = new ArrayList();

    InputStream is = new URL("http://www.mangapanda.com/actions/search/?q=" + query + "&limit=20").openStream();

    String lines[] = StringUtils.split(IOUtils.toString(is), '\n');

    for (int i = 0, length = lines.length; i < length && i < 20; i++) {
        String tokens[] = StringUtils.splitPreserveAllTokens(lines[i], '|');

        if (tokens.length >= MIN_TOKEN_LENGHT)
            mangas.add(new Manga(tokens[5], tokens[2], convertOldPath(tokens[4])));
    }

    return mangas;
}

From source file:com.evolveum.midpoint.schema.SelectorOptions.java

public static <T> Collection<SelectorOptions<T>> createCollection(T options, ItemPath... paths) {
    Collection<SelectorOptions<T>> optionsCollection = new ArrayList<>(paths.length);
    for (ItemPath path : paths) {
        optionsCollection.add(create(path, options));
    }/*  w  ww. j a v  a 2 s .  c om*/
    return optionsCollection;
}

From source file:gov.nih.nci.caintegrator.common.PermissibleValueUtil.java

private static void addDateValue(Collection<PermissibleValue> abstractPermissibleValues, String displayString)
        throws ParseException {
    PermissibleValue newPermissibleValue = new PermissibleValue();
    newPermissibleValue.setValue(DateUtil.toString(DateUtil.createDate(displayString)));
    abstractPermissibleValues.add(newPermissibleValue);
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

/**
 * From Apache commons-collection./*w ww  . j av  a2 s .co  m*/
 * 
 * Adds an element to the collection unless the element is null.
 * 
 * @param collection the collection to add to, must not be null
 * @param object the object to add, if null it will not be added
 * @return true if the collection changed
 * @throws NullPointerException if the collection is null
 * @since Commons Collections 3.2
 */
private static <T> boolean addIgnoreNull(Collection<? super T> collection, T object) {
    return (object == null ? false : collection.add(object));
}

From source file:Main.java

public static void innerListFiles(Collection<File> files, File directory, FileFilter filter) {
    File[] found = directory.listFiles();
    if (found != null) {
        for (int i = 0; i < found.length; i++) {
            if (found[i].isDirectory()) {
                innerListFiles(files, found[i], filter);
            } else {
                File[] found2 = directory.listFiles((FileFilter) filter);
                for (int j = 0; j < found2.length; j++) {
                    files.add(found2[j]);
                }//from   www .  j av  a2s . co  m
            }
        }
    }
}

From source file:com.wavemaker.common.util.StringUtils.java

public static String getUniqueName(String name, String names) {
    Collection<String> c = new HashSet<String>(1);
    c.add(names);
    return getUniqueName(name, c);
}

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);/*from   w  ww  .j av  a 2 s.com*/

    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:com.evolveum.midpoint.schema.SelectorOptions.java

public static <T> Collection<SelectorOptions<T>> createCollection(T options, QName... pathQNames) {
    Collection<SelectorOptions<T>> optionsCollection = new ArrayList<>(pathQNames.length);
    for (QName qname : pathQNames) {
        optionsCollection.add(create(qname, options));
    }/* www . jav  a2s . c o m*/
    return optionsCollection;
}

From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java

/**
 * ?field,//from ww  w  .j a  v a2  s  .co m
 * 
 * @param fields
 * @param type
 * @return
 */
public static Field[] getAllFields(Collection<Field> fields, Class<?> type) {
    if (Argument.isEmpty(fields)) {
        fields = new HashSet<Field>();
    }
    for (Field field : type.getDeclaredFields()) {
        fields.add(field);
    }
    if (type.getSuperclass() != null) {
        fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass())));
    }
    return fields.toArray(new Field[fields.size()]);
}

From source file:com.screenslicer.core.nlp.NlpUtil.java

public static Collection<String> tokens(String src, boolean unique) {
    Collection<String> tokens = unique ? new LinkedHashSet<String>() : new ArrayList<String>();
    String[] sentences = sentences(src);
    for (int i = 0; i < sentences.length; i++) {
        String[] tokensFromSentence = tokensFromSentence(sentences[i]);
        for (int j = 0; j < tokensFromSentence.length; j++) {
            tokens.add(tokensFromSentence[j]);
        }/*from   w  ww .  j a  v  a  2s  .c  o m*/
    }
    return tokens;
}