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:Main.java

private static void walkTreeAndReturnJARS(File dir, Collection<File> dst) {
    for (File e : dir.listFiles()) {
        if (e.isDirectory())
            walkTreeAndReturnJARS(e, dst);
        else {/*from  ww  w .j av a2  s.  c o m*/
            if (e.getName().toLowerCase().endsWith(".jar")) {
                dst.add(e);
            }
        }
    }
}

From source file:net.maritimecloud.endorsement.controllers.TokenGenerator.java

/**
 * Helper function of build fake PreAuthenticatedAuthenticationToken - used for x509 authentication
 * @param orgMrn/*from   w  w w . ja v  a  2s.  com*/
 * @param roles
 * @param permissions
 * @return
 */
/*public static PreAuthenticatedAuthenticationToken generatePreAuthenticatedAuthenticationToken(String orgMrn, String roles, String permissions) {
Collection<GrantedAuthority> authorities = generateGrantedAuthority(roles);
InetOrgPerson.Essence essence = new InetOrgPerson.Essence();
String username = "urn:mrn:mcl:user:dma:dmauser";
essence.setUsername(username);
essence.setUid(username);
essence.setDn("O="+orgMrn);
essence.setO(orgMrn);
essence.setCn(new String[] {"dmauser"});
essence.setAuthorities(authorities);
        
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(essence.createUserDetails(), null, authorities);
return token;
}*/

public static Collection<GrantedAuthority> generateGrantedAuthority(String roles) {
    Collection<GrantedAuthority> authorities = new ArrayList<>();
    String[] roleArr = roles.split(",");
    for (String role : roleArr) {
        authorities.add(new SimpleGrantedAuthority(role.trim()));
    }
    return authorities;
}

From source file:Main.java

/**
 * Creates new collection that contains only element whose string
 * representation starts with prefix It uses raw collection - not
 * parameterized. There is no {@link SuppressWarnings} annotation so IDE
 * will probably report rawtype and/or unchecked warnings.
 * //from ww w .j av a  2  s . c  o m
 * @param c
 *            raw collection to create prefixed collection from
 * @param prefix
 *            to use as filter
 * @return collection without nulls
 */
public static Collection withPrefixRaw(Collection c, String prefix) {
    Collection prefixed = new ArrayList();
    Iterator iterator = c.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        if (o != null && o.toString().startsWith(prefix)) {
            prefixed.add(o);
        }
    }
    return prefixed;
}

From source file:Main.java

public static Collection<Node> getNodesByName(Node node, String name) {
    Collection<Node> list = new LinkedList<Node>();

    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
        if (nl.item(i).getNodeName().equals(name))
            list.add(nl.item(i));

    return list;//w  w w.j  a va2  s.c  o m
}

From source file:com.eviware.soapui.plugins.PluginProxies.java

public static <T> Collection<T> proxyInstancesWhereApplicable(Collection<T> instancesToProxy) {
    Collection<T> proxiedInstances = new HashSet<T>();
    for (T instance : instancesToProxy) {
        proxiedInstances.add(proxyIfApplicable(instance));
    }/* www .ja v  a2s . c o  m*/
    return proxiedInstances;
}

From source file:Main.java

/**
 * Creates new collection that contains only element whose string
 * representation starts with prefix It is parameterized.
 * //  ww w . j a va2  s  .  c  o  m
 * @param c
 *            raw collection to create prefixed collection from
 * @param prefix
 *            to use as filter
 * @return collection without nulls
 */
public static <T> Collection<T> withPrefix(Collection<T> c, String prefix) {
    Collection<T> prefixed = new ArrayList<T>();
    Iterator<T> iterator = c.iterator();
    while (iterator.hasNext()) {
        T o = iterator.next();
        if (o != null && o.toString().startsWith(prefix)) {
            prefixed.add(o);
        }
    }
    return prefixed;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * /*from  w ww .j a  v a  2s.c o  m*/
 * @param collection
 *            the collection to add to, must not be null
 * @param enumeration
 *            the enumeration of elements to add, must not be null
 * @throws NullPointerException
 *             if the collection or enumeration is null
 */
public static <E> void addAll(Collection<E> collection, Enumeration<E> enumeration) {
    if (collection == null || enumeration == null) {
        return;
    }

    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }
}

From source file:com.xiaoxiaomo.flink.batch.relational.EmptyFieldsCountAccumulator.java

private static Collection<StringTriple> getExampleInputTuples() {
    Collection<StringTriple> inputTuples = new ArrayList<StringTriple>();
    inputTuples.add(new StringTriple("John", "Doe", "Foo Str."));
    inputTuples.add(new StringTriple("Joe", "Johnson", ""));
    inputTuples.add(new StringTriple(null, "Kate Morn", "Bar Blvd."));
    inputTuples.add(new StringTriple("Tim", "Rinny", ""));
    inputTuples.add(new StringTriple("Alicia", "Jackson", "  "));
    return inputTuples;
}

From source file:Main.java

/** Recursive implementation for {@link #permutations(List, Collection)} */
private static <T> void permutationsImpl(List<Collection<T>> ori, Collection<List<T>> res, int d,
        List<T> current) {//from www  .  j ava 2s.c om
    // if depth equals number of original collections, final reached, add
    // and return
    if (d == ori.size()) {
        res.add(current);
        return;
    }

    // iterate from current collection and copy 'current' element N times,
    // one for each element
    Collection<T> currentCollection = ori.get(d);
    for (T element : currentCollection) {
        List<T> copy = Lists.newLinkedList(current);
        copy.add(element);
        permutationsImpl(ori, res, d + 1, copy);
    }
}

From source file:Main.java

/**
 * Removes all the given keys from the given map and adds their
 * corresponding values to the given collection.
 *
 * @param <TKey> The type of the keys of the map.
 * @param <TValue> The types of the values of the map.
 * @param target The map to remove the specified keys from.
 * @param keys An iterator providing the keys to be removed.
 * @param values A collection where the values corresponding to the given
 * keys are added.//from  www  .  j a  va2 s  . co  m
 * @note In case the target or the keys are not effective, nothing happens.
 * @note In case values is not effective, the keys are removed without
 * adding them.
 */
public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target, final Iterator<? extends TKey> keys,
        Collection<? super TValue> values) {
    if (values != null) {
        if (target != null && keys != null) {
            while (keys.hasNext()) {
                values.add(target.remove(keys.next()));
            }
        }
    } else {
        removeAll(target, keys);
    }
}