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:com.wavemaker.common.util.StringUtils.java

/**
 * split by ',', except if within {},[] or quotes.
 *//*from ww w . j a va  2s . c o  m*/
public static List<String> split(String s) {
    Collection<Character> sep = new HashSet<Character>(1);
    sep.add(',');
    return split(s, sep);
}

From source file:CollectionsX.java

/** Adds all elements returned by the iterator to a collection.
 * @param iter the iterator; null is OK// w w w . java 2s.co  m
 * @return the number element being added
 */
public static final int addAll(Collection col, Iterator iter) {
    int cnt = 0;
    if (iter != null)
        for (; iter.hasNext(); ++cnt)
            col.add(iter.next());
    return cnt;
}

From source file:CollectionsX.java

/** Adds all elements of an array to a collection.
 * @param ary the array; null is OK/*from   w  ww . j  a v  a  2  s .c o  m*/
 * @return the number element being added
 */
public static final int addAll(Collection col, Object[] ary) {
    int cnt = 0;
    if (ary != null)
        for (; cnt < ary.length; ++cnt)
            col.add(ary[cnt]);
    return cnt;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static void mergeNestedMap(Map<Object, Object> baseMap, Map<Object, Object> overrideMap,
        boolean overrideEmpty) {
    if (baseMap == null || overrideMap == null)
        return;/* w  w  w .j  av  a2  s . c  om*/
    for (Map.Entry<Object, Object> entry : overrideMap.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (baseMap.containsKey(key)) {
            if (value == null) {
                if (overrideEmpty)
                    baseMap.put(key, null);
            } else {
                if (value instanceof CharSequence) {
                    if (overrideEmpty || ((CharSequence) value).length() > 0)
                        baseMap.put(key, value);
                } else if (value instanceof Map) {
                    Object baseValue = baseMap.get(key);
                    if (baseValue != null && baseValue instanceof Map) {
                        mergeNestedMap((Map) baseValue, (Map) value, overrideEmpty);
                    } else {
                        baseMap.put(key, value);
                    }
                } else if (value instanceof Collection) {
                    Object baseValue = baseMap.get(key);
                    if (baseValue != null && baseValue instanceof Collection) {
                        Collection baseCol = (Collection) baseValue;
                        Collection overrideCol = (Collection) value;
                        for (Object overrideObj : overrideCol) {
                            // NOTE: if we have a Collection of Map we have no way to merge the Maps without knowing the 'key' entries to use to match them
                            if (!baseCol.contains(overrideObj))
                                baseCol.add(overrideObj);
                        }
                    } else {
                        baseMap.put(key, value);
                    }
                } else {
                    // NOTE: no way to check empty, if not null not empty so put it
                    baseMap.put(key, value);
                }
            }
        } else {
            baseMap.put(key, value);
        }
    }
}

From source file:br.msf.commons.netbeans.util.FileObjectUtils.java

public static Collection<FileObject> getFiles(final FileObject rootDir, final boolean recursive,
        final FileType... types) {
    assert rootDir != null && rootDir.isFolder() && !ArrayUtils.contains(types, FileType.OTHER);
    Collection<FileObject> fileObjects = new ArrayList<FileObject>();
    Enumeration<FileObject> entries = (Enumeration<FileObject>) rootDir.getChildren(recursive);
    while (entries.hasMoreElements()) {
        FileObject curr = entries.nextElement();
        if (curr.isData()) {
            FileType t = FileType.parse(curr.getExt());
            if (ArrayUtils.isEmpty(types) || ArrayUtils.contains(types, t)) {
                fileObjects.add(curr);
            }/*from  w  ww  .  ja v a 2 s  . co m*/
        }
    }
    return fileObjects;
}

From source file:edu.ncsa.uiuc.rdfrepo.testing.USeekMSailFac.java

private static Collection<String> tokenizePatternString(String patterString) {
    boolean escape = false;
    int startpoint = 0;
    Collection<String> strings = new ArrayList<String>();
    for (int i = 0; i < patterString.length(); i++) {
        if (patterString.charAt(i) == '<') {
            escape = true;/*from w  w  w  . ja  va  2s  .  c o m*/
        } else if (patterString.charAt(i) == '>') {
            escape = false;
        } else if (patterString.charAt(i) == '.' && !escape) {
            strings.add(patterString.substring(startpoint, i));
            startpoint = i + 1;
        }
    }
    String lastString = patterString.substring(startpoint);
    if (!lastString.trim().isEmpty()) {
        strings.add(lastString);
    }

    return strings;
}

From source file:com.jaeksoft.searchlib.util.ActiveDirectory.java

public static void collectMemberOf(Attributes attrs, Collection<ADGroup> groups) throws NamingException {
    Attribute tga = attrs.get("memberOf");
    if (tga == null)
        return;//from   w  ww .j  a  v a2  s. c  o  m
    NamingEnumeration<?> membersOf = tga.getAll();
    while (membersOf.hasMore()) {
        Object memberObject = membersOf.next();
        groups.add(new ADGroup(memberObject.toString()));
    }
    membersOf.close();
}

From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java

/**
 * Converts <code>g</code> into a unipartite graph whose vertices are the
 * vertices of <code>g</code>'s partition <code>p</code>, and whose edges
 * consist of collections of the intermediate vertices from other partitions.  
 * For vertices/*  w ww  .j  a v  a 2 s . c  om*/
 * <code>a</code> and <code>b</code> in this partition, the resultant
 * graph will include the edge <code>(a,b)</code> if the original graph
 * contains edges <code>(a,c)</code> and <code>(c,b)</code> for at least
 * one vertex <code>c</code>.
 * 
 * <p>The vertices of the new graph are the same as the vertices of the
 * appropriate partition in the old graph; the edges in the new graph are
 * collections of the intermediate vertices <code>c</code>.</p>
 * 
 * <p>This function will not create self-loops.</p>
 * 
 * @param <V> vertex type
 * @param <E> input edge type
 * @param g input k-partite graph
 * @param p predicate specifying vertex partition
 * @param graph_factory factory used to create the output graph 
 * @return the result of folding g into unipartite graph whose vertices
 * are those of the <code>p</code> partition of g
 */
public static <V, E> Graph<V, Collection<V>> foldKPartiteGraph(KPartiteGraph<V, E> g, Predicate<V> p,
        Factory<Graph<V, Collection<V>>> graph_factory) {
    Graph<V, Collection<V>> newGraph = graph_factory.create();

    // get vertices for the specified partition, copy into new graph
    Collection<V> vertices = g.getVertices(p);

    for (V v : vertices) {
        newGraph.addVertex(v);
        for (V s : g.getSuccessors(v)) {
            for (V t : g.getSuccessors(s)) {
                if (!vertices.contains(t) || t.equals(v))
                    continue;
                newGraph.addVertex(t);
                Collection<V> v_coll = newGraph.findEdge(v, t);
                if (v_coll == null) {
                    v_coll = new ArrayList<V>();
                    newGraph.addEdge(v_coll, v, t);
                }
                v_coll.add(s);
            }
        }
    }
    return newGraph;
}

From source file:com.sfs.whichdoctor.formatter.AgedDebtorsAnalysisFormatter.java

/**
 * Gets the collection./*from  www.  ja va 2s.  c  o m*/
 *
 * @param revenue the revenue
 * @param section the section
 * @return the collection
 */
public static Collection<Object> getCollection(final AgedDebtorsGrouping grouping, final String section) {

    Collection<Object> collection = new ArrayList<Object>();

    if (StringUtils.equalsIgnoreCase(section, "Records")) {
        if (grouping.getRecords() != null) {
            for (String order : grouping.getRecords().keySet()) {
                AgedDebtorsRecord record = grouping.getRecords().get(order);
                if (record != null) {
                    collection.add(record);
                }
            }
        }
    }
    return collection;
}

From source file:com.moviejukebox.tools.StringTools.java

public static String[] tokenizeToArray(String sourceString, String delimiter) {
    StringTokenizer st = new StringTokenizer(sourceString, delimiter);
    Collection<String> keywords = new ArrayList<>();
    while (st.hasMoreTokens()) {
        keywords.add(st.nextToken());
    }/*from w ww. j a  v  a 2s.  c  o m*/
    return keywords.toArray(new String[keywords.size()]);
}