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:org.eclipse.lyo.testsuite.server.oslcv1tests.CreationAndUpdateTests.java

public static Collection<Object[]> getReferencedUrls(String base)
        throws IOException, XPathException, ParserConfigurationException, SAXException {
    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 + ", " + OSLCConstants.CT_DISC_DESC_XML);

    //If our 'base' is a ServiceDescription, find and add the factory service url
    if (resp.getEntity().getContentType().getValue().contains(OSLCConstants.CT_DISC_DESC_XML)) {
        Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity()));
        Node factoryUrl = (Node) OSLCUtils.getXPath().evaluate("//oslc_cm:factory/oslc_cm:url", baseDoc,
                XPathConstants.NODE);
        Collection<Object[]> data = new ArrayList<Object[]>();
        data.add(new Object[] { factoryUrl.getTextContent() });
        return data;
    }/*from   w  ww  .j  a  va  2s . co  m*/

    Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity()));

    //ArrayList to contain the urls from all of the SPCs
    Collection<Object[]> data = new ArrayList<Object[]>();

    //Get all the ServiceDescriptionDocuments from this ServiceProviderCatalog
    NodeList sDescs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_disc:services/@rdf:resource", baseDoc,
            XPathConstants.NODESET);
    for (int i = 0; i < sDescs.getLength(); i++) {
        Collection<Object[]> subCollection = getReferencedUrls(sDescs.item(i).getNodeValue());
        Iterator<Object[]> iter = subCollection.iterator();
        while (iter.hasNext()) {
            data.add(iter.next());
        }
    }

    //Get all ServiceProviderCatalog urls from the base document in order to recursively add all the
    //simple query services from the eventual service description documents from them as well.
    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++) {
        if (!spcs.item(i).getNodeValue().equals(base)) {
            Collection<Object[]> subCollection = getReferencedUrls(spcs.item(i).getNodeValue());
            Iterator<Object[]> iter = subCollection.iterator();
            while (iter.hasNext()) {
                data.add(iter.next());
            }
        }
    }
    return data;
}

From source file:net.sourceforge.fenixedu.domain.DistrictSubdivision.java

static public Collection<DistrictSubdivision> findByName(String name, int size) {
    String normalizedName = StringNormalizer.normalize(name);
    Collection<DistrictSubdivision> result = new TreeSet<DistrictSubdivision>(COMPARATOR_BY_NAME);

    for (DistrictSubdivision districtSubdivision : Bennu.getInstance().getDistrictSubdivisionsSet()) {
        if (StringNormalizer.normalize(districtSubdivision.getName()).contains(normalizedName)) {
            result.add(districtSubdivision);
            if (result.size() >= size) {
                break;
            }/*from  w w w  .  j a va  2 s . c o m*/
        }
    }

    return result;
}

From source file:Main.java

public static boolean addAll(final Collection<? super Double> c, final double[] array, final int off,
        final int len) {
    final int end = off + len;
    boolean result = false;

    for (int i = off; i < end; i++) {
        result |= c.add(array[i]);
    }//from   www . ja  v  a 2 s  .  c om

    return result;
}

From source file:Main.java

public static boolean addAll(final Collection<? super Character> c, final char[] array, final int off,
        final int len) {
    final int end = off + len;
    boolean result = false;

    for (int i = off; i < end; i++) {
        result |= c.add(array[i]);
    }// ww w  . jav  a 2  s .co  m

    return result;
}

From source file:edu.sdsc.scigraph.services.jersey.writers.BbopJsGraphWriter.java

static Collection<String> getCategories(Vertex vertex) {
    Collection<String> categories = new HashSet<>();
    if (vertex.getPropertyKeys().contains(Concept.CATEGORY)) {
        Object value = vertex.getProperty(Concept.CATEGORY);
        if (value.getClass().isArray()) {
            for (int i = 0; i < Array.getLength(value); i++) {
                categories.add((String) Array.get(value, i));
            }//from   w ww  .  j ava 2s .  c o  m
        } else if (value instanceof Iterable) {
            categories.addAll(newArrayList((Iterable<String>) value));
        } else {
            categories.add((String) value);
        }
    }
    return categories;
}

From source file:Main.java

public static boolean addAll(final Collection<? super Boolean> c, final boolean[] array, final int off,
        final int len) {
    final int end = off + len;
    boolean result = false;

    for (int i = off; i < end; i++) {
        result |= c.add(array[i]);
    }/*from  www  .  ja va2 s .  c  o  m*/

    return result;
}

From source file:com.ikanow.aleph2.aleph2_rest_utils.RestUtils.java

public static <T> JsonNode convertCursorToJson(final Cursor<T> cursor) throws JsonProcessingException {
    final Collection<T> list = new ArrayList<T>();
    cursor.forEach(a -> list.add(a));
    return BeanTemplateUtils.toJson(list);
}

From source file:com.sun.socialsite.web.listeners.SessionListener.java

public static void addListener(HttpSession session, Object listener) {
    Collection<Object> listenersForSession = listenersMap.get(session);
    if (listenersForSession == null) {
        listenersMap.putIfAbsent(session, new ConcurrentLinkedQueue<Object>());
        listenersForSession = listenersMap.get(session);
    }//from w ww  . j a v a  2 s .c  o  m
    listenersForSession.add(listener);
    log.debug(String.format("addListener(%s, %s): listenersForSession.size=%d", session, listener,
            listenersForSession.size()));
}

From source file:com.xpn.xwiki.doc.merge.MergeUtils.java

/**
 * Merge a {@link Collection}.//from www  . j  a va 2s.c  om
 * 
 * @param <T> the type of the lists elements
 * @param previousList previous version of the collection
 * @param newList new version of the collection
 * @param currentList current version of the collection to modify
 * @param mergeResult the merge report
 */
public static <T> void mergeCollection(Collection<T> previousList, Collection<T> newList,
        Collection<T> currentList, MergeResult mergeResult) {
    for (T previousElement : previousList) {
        if (!newList.contains(previousElement)) {
            currentList.remove(previousElement);
        }
    }

    for (T newElement : newList) {
        if (!previousList.contains(newElement)) {
            currentList.add(newElement);
        }
    }
}

From source file:net.landora.video.utils.UIUtils.java

public static void addContentObject(Object obj, Collection<Object> addTo) {
    if (obj == null) {
        return;/*w  w  w  . j av  a  2 s.c  o  m*/
    }

    if (obj instanceof ContextProducer) {
        ((ContextProducer) obj).addContentObjects(addTo);
    } else {
        addTo.add(obj);
    }
}