List of usage examples for java.util Collection add
boolean add(E e);
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceProviderCatalogTests.java
public static Collection<Object[]> getReferencedCatalogUrls(String base) throws IOException, ParserConfigurationException, SAXException, XPathException { Properties setupProps = SetupProperties.setup(null); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base, new UsernamePasswordCredentials(userId, pw), OSLCConstants.CT_DISC_CAT_XML); //If we're not looking at a catalog, return empty list. if (!resp.getEntity().getContentType().getValue().contains(OSLCConstants.CT_DISC_CAT_XML)) { System.out.println("The url: " + base + " does not refer to a ServiceProviderCatalog."); System.out.println(//from w w w .j av a 2s.c o m "The content-type of a ServiceProviderCatalog should be " + OSLCConstants.CT_DISC_CAT_XML); System.out.println("The content-type returned was " + resp.getEntity().getContentType()); EntityUtils.consume(resp.getEntity()); return new ArrayList<Object[]>(); } Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity())); //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); data.add(new Object[] { base }); //Get all ServiceProviderCatalog urls from the base document in order to test them as well, //recursively checking them for other ServiceProviderCatalogs further down. NodeList spcs = (NodeList) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry/oslc_disc:ServiceProviderCatalog/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { String uri = spcs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); if (!uri.equals(base)) { Collection<Object[]> subCollection = getReferencedCatalogUrls(uri); Iterator<Object[]> iter = subCollection.iterator(); while (iter.hasNext()) { data.add(iter.next()); } } } return data; }
From source file:com.netflix.simianarmy.basic.conformity.BasicConformityMonkey.java
private static void addCluster(Map<String, Collection<Cluster>> map, Cluster cluster) { Collection<Cluster> clusters = map.get(cluster.getRegion()); if (clusters == null) { clusters = Lists.newArrayList(); map.put(cluster.getRegion(), clusters); }//from www.j a v a 2s . com clusters.add(cluster); }
From source file:mitm.common.util.CollectionUtils.java
/** * Copies elements from the target collection to the source collection only when the elements implements all the * clazz classes./*from ww w . ja v a 2 s.com*/ * * @param <T> * @param source * @param target */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> void copyCollectionFiltered(Collection source, Collection target, Class<?>... clazz) { Check.notNull(source, "source"); Check.notNull(target, "target"); Check.notNull(clazz, "clazz"); for (Object object : source) { if (ReflectionUtils.isInstanceOf(object.getClass(), clazz)) { target.add((T) object); } } }
From source file:org.apache.solr.common.util.Utils.java
public static Collection getDeepCopy(Collection c, int maxDepth, boolean mutable) { if (c == null || maxDepth < 1) return c; Collection result = c instanceof Set ? new HashSet() : new ArrayList(); for (Object o : c) { if (o instanceof Map) { o = getDeepCopy((Map) o, maxDepth - 1, mutable); }//from w ww . j a v a 2 s .c om result.add(o); } return mutable ? result : result instanceof Set ? unmodifiableSet((Set) result) : unmodifiableList((List) result); }
From source file:ArrayHelper.java
public static void addAll(Collection collection, Object[] array) { for (int i = 0; i < array.length; i++) { collection.add(array[i]); }//from w w w . j a v a 2s . c om }
From source file:eu.medsea.util.EncodingGuesser.java
/** * Set the supported encodings/* w w w .j ava 2s . c om*/ * @param encodings. If this is null the supported encodings are left unchanged. * @return a copy of the currently supported encodings */ public static Collection setSupportedEncodings(Collection encodings) { Collection current = new TreeSet(); for (Iterator it = supportedEncodings.iterator(); it.hasNext();) { current.add(it.next()); } if (encodings != null) { supportedEncodings.clear(); for (Iterator it = encodings.iterator(); it.hasNext();) { supportedEncodings.add(it.next()); } } return current; }
From source file:Main.java
/** * Sorts <code>source</code> and adds the first n entries to * <code>dest</code>. If <code>source</code> contains less than n entries, * all of them are added to <code>dest</code>. * // www. j a va 2 s . c o m * If adding an entry to <code>dest</code> does not increase the * collection's size, for example if <code>dest</code> is a set and already * contained the inserted contact, an additional entry of * <code>source</code> will be added, if available. This guarantees that * <code>n</code> new, distinct entries are added to collection * <code>dest</code> as long as this can be fulfilled with the contents of * <code>source</code>, and as <code>dest</code> does recognise duplicate * entries. Consequently, this guarantee does not hold for simple lists. * * Both collections may not be <code>null</code>. * * @param <T> * the entry type of the collections. * @param source * the source collection. * @param dest * the destination collection. * @param order * the order in which <code>source</code> is to be sorted. * @param n * the number of new entries that are to be added to * <code>dest</code>. */ public static <T> void copyNSorted(final Collection<? extends T> source, final Collection<? super T> dest, final Comparator<? super T> order, final int n) { final List<? extends T> src = Collections.list(Collections.enumeration(source)); Collections.sort(src, order); final Iterator<? extends T> it = src.iterator(); final int maxEntries = dest.size() + n; while (it.hasNext() && dest.size() < maxEntries) { dest.add(it.next()); } }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderRdfXmlTests.java
public static Collection<Object[]> getReferencedUrls(String base) throws IOException { //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); ArrayList<String> serviceURLs = TestsBase.getServiceProviderURLsUsingRdfXml(base, false); for (String serviceURL : serviceURLs) { data.add(new Object[] { serviceURL }); if (onlyOnce) return data; }/*from w w w . ja va2s. c o m*/ return data; }
From source file:com.silverpeas.util.CollectionUtil.java
/** * Null elements are not taking into account. * @see Collections#addAll(java.util.Collection, Object[]) *//*from www . ja va 2s . c o m*/ public static <T> boolean addAllIgnoreNull(Collection<? super T> c, T... elements) { boolean result = false; for (T element : elements) { if (element != null) { result |= c.add(element); } } return result; }
From source file:com.ultrapower.eoms.common.plugin.ecside.core.TableModelUtils.java
/** * Retrieve the current page of rows./*from w w w . j ava 2 s. c o m*/ * * @param rows The Collection of Beans after filtering and sorting. * @return The current page of rows. */ public static Collection getCurrentRows(TableModel model, Collection rows) { Limit limit = model.getLimit(); int rowStart = limit.getRowStart(); int rowEnd = limit.getRowEnd(); // Normal case. Using Limit and paginating for a specific set of rows. if (rowStart >= rows.size()) { if (logger.isDebugEnabled()) { logger.debug("The Limit row start is >= items.size(). Return the items available."); } return rows; } if (rowEnd > rows.size()) { if (logger.isWarnEnabled()) { logger.warn("The Limit row end is > items.size(). Return as many items as possible."); } rowEnd = rows.size(); } Collection results = new ArrayList(); for (int i = rowStart; i < rowEnd; i++) { Object bean = ((List)rows).get(i); results.add(bean); } return results; }