List of usage examples for java.util Collection add
boolean add(E e);
From source file:edu.northwestern.bioinformatics.studycalendar.web.taglibs.Functions.java
public static Collection pluck(Collection collection, String property) { Collection result = new ArrayList(collection.size()); for (Object o : collection) { try {//from w w w . jav a 2 s.c o m Object plucked = new Expression(o, "get" + capitalize(property), null).getValue(); result.add(plucked); } catch (Exception e) { throw new StudyCalendarError("Unable to get the '" + property + "' property", e); } } return result; }
From source file:Main.java
/** * Add elements from the source to the target as long as they don't already * exist there. Return the number of items actually added. * * @param source/*from w ww . j a v a 2 s . com*/ * @param target * @return int */ public static <T> int addWithoutDuplicates(Collection<T> source, Collection<T> target) { int added = 0; for (T item : source) { if (target.contains(item)) { continue; } target.add(item); added++; } return added; }
From source file:dk.dma.db.cassandra.CassandraConnection.java
/** * Creates a new Cassandra connection. The connection is not yet connected but must be started via {@link #start()} * and to close it use {@link #stop()}//from w w w .j a va 2s.co m * * @param keyspace * the name of the keyspace * @param connectionPoints * a comma-separated list of connection points expressed as <hostname>[:<port>] * @return a new connection */ public static CassandraConnection create(String keyspace, List<String> connectionPoints) { Cluster cluster; if (seedsContainPortNumbers(connectionPoints)) { Collection<InetSocketAddress> cassandraSeeds = new ArrayList<>(); connectionPoints.forEach(cp -> cassandraSeeds.add(connectionPointToInetAddress(cp))); cluster = Cluster.builder().addContactPointsWithPorts(cassandraSeeds) .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(1000 * 60)).build(); } else { cluster = Cluster.builder().addContactPoints(connectionPoints.toArray(new String[0])) .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(1000 * 60)).build(); } return new CassandraConnection(cluster, keyspace); }
From source file:doc.action.SelectedDocsUtils.java
public static Collection getSelectedDocuments(Collection documents, Collection selectedDocumentsIds) { Collection result = new ArrayList(); for (Iterator iter = selectedDocumentsIds.iterator(); iter.hasNext();) { String selectedPresident = (String) iter.next(); result.add(getDocument(documents, selectedPresident)); }/*from ww w . jav a 2s. c om*/ return result; }
From source file:Main.java
public static Collection<Node> search_nodes_by_attribute(Node root, String attr_name, String attr_value) { Collection<Node> result = new LinkedList<Node>(); if (root instanceof Element) { if (((Element) root).hasAttribute(attr_name) && ((Element) root).getAttribute(attr_name).equals(attr_value)) result.add(root); }/*from w ww .ja v a 2 s .c om*/ NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { Node child = list.item(i); Collection<Node> ret = search_nodes_by_attribute(child, attr_name, attr_value); result.addAll(ret); } return result; }
From source file:Main.java
public static Collection<Node> getChildNodes(Node node) { Collection<Node> list = new LinkedList<Node>(); NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) list.add(nl.item(i)); return list;/*from w w w .ja v a2 s . co m*/ }
From source file:Main.java
/** * Appends the given items to the given collection. * * @param collection The collection to append the items to. * @param includeNulls If true, null values will be appended, otherwise they will not. * @param items The items to be appended. * @param <E> The component type of the items stored in the collection. * @return The given collection. *///from w w w.ja v a 2 s.c o m public static <E> Collection append(Collection<E> collection, boolean includeNulls, E... items) { if (collection != null && items != null) { for (E item : items) { if (includeNulls || item != null) collection.add(item); } } return collection; }
From source file:com.msopentech.thali.utilities.universal.test.ThaliTestUtilities.java
/** * Creates a single test doc and adds it to the generatedDocs * @param couchDbConnector//from www.j av a2 s . c o m * @param generatedDocs */ public static void GenerateDoc(CouchDbConnector couchDbConnector, Collection<CouchDbDocument> generatedDocs) { generatedDocs.add(GenerateDoc(couchDbConnector)); }
From source file:edu.jhu.hlt.parma.inference.transducers.StringEditModelTrainer.java
public static Collection<String> aliasAtRandom(List<String> aliases) { int index = RandomNumberGenerator.nextInt(aliases.size()); Collection<String> ret = new ArrayList<String>(); ret.add(aliases.get(index)); return ret;/*from w ww .j ava2s . com*/ }
From source file:Main.java
/** * Adds all non-null objects into the specified list. * * @param collection list to fill//from ww w. j ava 2s . c om * @param objects objects * @param <T> objects type * @return true if list changed as the result of this operation, false otherwise */ public static <T> boolean addAllNonNull(final Collection<T> collection, final Collection<T> objects) { boolean result = false; for (final T object : objects) { if (!collection.contains(object) && object != null) { result |= collection.add(object); } } return result; }