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.iggroup.oss.restdoclet.plugin.util.XmlUtils.java

/**
 * Returns the child-elements of a XML node with a particular name.
 * //from w w w  . j av a 2s .c o m
 * @param node the XML node.
 * @param name the name of the child-elements.
 * @return the collection of child-elements or an empty collection if no
 *         children with the name were found.
 */
public static Collection<Element> children(final Node node, final String name) {
    final Collection<Element> elements = new ArrayList<Element>();

    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        if (node.getChildNodes().item(i).getNodeType() == ELEMENT_NODE) {
            final Element child = (Element) node.getChildNodes().item(i);

            if (StringUtils.equals(name, child.getNodeName())) {
                elements.add(child);
            }
        }
    }
    return elements;
}

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

public static Contact extractContact(String src) {
    if (CommonUtil.isEmpty(src)) {
        return new Contact();
    }//from  w  w w  .j a  v  a2s  . co m
    List<String> lines = new ArrayList<String>();
    String emailMatch = null;
    Matcher matcher = email.matcher(src);
    if (matcher.find()) {
        emailMatch = matcher.group(1);
        lines.add(matcher.group(0));
    }
    String phoneMatch = null;
    matcher = phone.matcher(src);
    if (matcher.find()) {
        phoneMatch = matcher.group(1);
        lines.add(matcher.group(0));
    }
    Collection<String> names = new HashSet<String>();
    for (String line : lines) {
        String name = extractName(line, false, false);
        if (!CommonUtil.isEmpty(name)) {
            names.add(name);
        }
    }
    String name = null;
    if (names.size() == 1) {
        name = names.iterator().next();
    }
    if (name == null) {
        name = extractName(src, true, false);
    }
    Contact person = new Contact();
    person.name = name;
    person.email = emailMatch;
    person.phone = phoneMatch;
    return person;
}

From source file:org.opencredo.demos.twityourl.TwitYourl.java

private static TwitterStreamConfiguration parseCommandLine(String[] args) {

    try {//from   w  w  w  .  ja v a  2s.  co  m
        Collection<String> followIds = null;
        Collection<String> trackKeywords = null;

        String[] credentials = args[0].split(":");

        Collection<String> list = null;
        for (int i = 1; i < args.length; i++) {
            String arg = args[i];
            if (arg.equals("-f")) {
                followIds = new ArrayList<String>();
                list = followIds;
            } else if (arg.equals("-t")) {
                trackKeywords = new ArrayList<String>();
                list = trackKeywords;
            } else {
                list.add(arg);
            }
        }

        if (followIds != null) {
            return new FilterTwitterStreamConfiguration(new TwitterCredentials(credentials[0], credentials[1]),
                    followIds.toArray(new String[followIds.size()]),
                    (trackKeywords == null) ? null : trackKeywords.toArray(new String[trackKeywords.size()]),
                    0);
        } else {
            return new TwitterStreamConfiguration(new TwitterCredentials(credentials[0], credentials[1]));
        }

    } catch (Exception e) {
        System.err.println("Usage: Example username:password ... [-f twitter_id ...] [-t keyword]");
        System.exit(1);
        return null;
    }
}

From source file:com.bluexml.side.form.workflow.utils.WorkflowInitialization.java

public static Collection<FormElement> filterAttributes(Collection<FormElement> createChildsForClass,
        String filterURI) {//from   w w  w.  j  av a2  s  .c  o  m
    Collection<FormElement> filtered = new ArrayList<FormElement>();
    for (FormElement formElement : createChildsForClass) {
        boolean filterFormElement = filterFormElement(filterURI, formElement);
        if (filterFormElement) {
            filtered.add(formElement);
        }
    }
    return filtered;
}

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

public static Collection<Object> getCollection(final GroupBean group, final String section) {

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

    if (section != null) {
        if (section.compareTo("Items") == 0) {
            if (group.getItems() != null) {
                for (String key : group.getItems().keySet()) {
                    ItemBean item = group.getItems().get(key);
                    collection.add(item);
                }// w w w  . j a v  a2s  .  c o m
            }
        }

        if (section.compareTo("Memos") == 0) {
            if (group.getMemo() != null) {
                for (MemoBean memo : group.getMemo()) {
                    collection.add(memo);
                }
            }
        }
    }
    return collection;
}

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

/**
 * @param target/*from w ww .j  a v a2 s.  co  m*/
 * @param e
 * @param incident
 */
private static <S, T> void populateTarget(Graph<S, Collection<T>> target, T e, ArrayList<S> incident) {
    for (int i = 0; i < incident.size(); i++) {
        S v1 = incident.get(i);
        for (int j = i + 1; j < incident.size(); j++) {
            S v2 = incident.get(j);
            Collection<T> e_coll = target.findEdge(v1, v2);
            if (e_coll == null) {
                e_coll = new ArrayList<T>();
                target.addEdge(e_coll, v1, v2);
            }
            e_coll.add(e);
        }
    }
}

From source file:Main.java

/**
 * This method creates a collection of child nodes from a parent node
 * @param root the parent node//  w  w w  .  j  ava2s  .  c o  m
 * @return Collection - childern nodes
 */
public static Collection getCollection(Node root) {
    Collection collection = new ArrayList();
    if (root != null) {
        NodeList children = root.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            String nodeName = child.getNodeName();
            if (!nodeName.equalsIgnoreCase("#comment") && !nodeName.equalsIgnoreCase("#text")) {
                if (child.getChildNodes().getLength() > 1) {
                    collection.add(child);
                } else {
                    Node textChild = child.getFirstChild();
                    if (textChild == null) {
                        // don't accept nulls
                    } else {
                        collection.add(child.getFirstChild().getNodeValue());
                    }
                }
            }
        }
    }
    return collection;
}

From source file:org.shept.util.BeanUtilsExtended.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static boolean isInstanceVisited(Collection coll, Object value) throws Exception {
    for (Iterator<?> it = coll.iterator(); it.hasNext();) {
        Object v = it.next();//from   w  w  w . jav  a 2s  .c o m
        if (v.equals(value)) {
            return true;
        }
    }
    // sometimes ConcurrentModificationExceptions here
    coll.add(value);
    return false;
}

From source file:com.denimgroup.threadfix.selenium.tests.BaseTest.java

@Parameterized.Parameters
public static Collection<String[]> drivers() {
    Collection<String[]> params = new ArrayList<String[]>();
    String ff = System.getProperty("FIREFOX");
    String chrome = System.getProperty("CHROME");
    String ie = System.getProperty("IE");
    if (!(ff == null) && ff.equals("true")) {
        String[] f = { "firefox" };
        params.add(f);
    }/*from  w  w  w .  ja  v a  2 s.c o  m*/

    if (!(chrome == null) && chrome.equals("true")) {
        String[] f = { "chrome" };
        params.add(f);
    }

    if (!(ie == null) && ie.equals("true")) {
        String[] f = { "IE" };
        params.add(f);
    }
    return params;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java

/**
 * Get a collection of entities with the area shape equal to the bounding rectangle
 * for the shape of original entity. This is necessary because the Javascript for the sample 
 * selection lasso can only handle rect objects.
 * @param entities/*from  ww w  . j a  v  a2s .  c o  m*/
 * @return a collection of entities containing the bounding rectangles of the original entities
 */
private static Collection<ChartEntity> getBoundingEntities(Collection entities) {
    ChartEntity entity;
    ChartEntity boundingEntity;
    Shape shape;
    Rectangle2D boundingRect;
    Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>();
    for (Iterator i = entities.iterator(); i.hasNext();) {
        entity = (ChartEntity) i.next();
        shape = entity.getArea();
        boundingRect = shape.getBounds2D();
        boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText());
        boundingEntities.add(boundingEntity);
    }
    return boundingEntities;
}