Example usage for org.apache.commons.collections.collection CompositeCollection CompositeCollection

List of usage examples for org.apache.commons.collections.collection CompositeCollection CompositeCollection

Introduction

In this page you can find the example usage for org.apache.commons.collections.collection CompositeCollection CompositeCollection.

Prototype

public CompositeCollection() 

Source Link

Document

Create an empty CompositeCollection.

Usage

From source file:com.btoddb.fastpersitentqueue.FpqContext.java

public void addPoppedEntries(Collection<FpqEntry> entries) {
    if (!pushing) {
        if (null == queue) {
            queue = new CompositeCollection();
            popping = true;/*w  w w. j  a  v a  2 s. c o m*/
        }
    } else {
        throw new FpqException(
                "This context has already been used for 'pushing'.  can't switch to popping - create a new context");
    }

    if (null == entries || entries.isEmpty()) {
        return;
    }

    ((CompositeCollection) queue).addComposited(entries);
}

From source file:com.btoddb.fastpersitentqueue.Fpq.java

/**
 *
 * @param batchSize/*from   w  w  w.j a v a 2  s  . c o m*/
 * @return
 */
public Collection<FpqEntry> pop(int batchSize) {
    checkInitializing();
    checkShutdown();

    // - move (up to) context.maxBatchSize events from globalMemoryQueue to context.queue
    // - do not wait for events
    // - return context.queue

    // assumptions
    // - can call 'pop' with same context over and over until context.queue has size context.maxBatchSize

    FpqContext context = contextThrowException();

    if (batchSize > maxTransactionSize) {
        throw new FpqException(
                "size of " + batchSize + " exceeds maximum transaction size of " + maxTransactionSize);
    }

    CompositeCollection returnColl = new CompositeCollection();
    Collection<FpqEntry> tmp;
    int numPopped = 0;
    do {
        tmp = memoryMgr.pop(batchSize);
        if (null != tmp) {
            numPopped += tmp.size();

            // at this point, if system crashes, the entries are in the journal files

            // TODO:BTB - however this is not true if system has been previously shutdown and not all of the
            //   entries have been pop'ed.  on shutdown the journal files are drained into memory segments,
            //   which are then serialized to disk (this is done to avoid dupes)

            context.addPoppedEntries(tmp);
            returnColl.addComposited(tmp);
        }
    } while (null != tmp && tmp.size() > 0 && numPopped < batchSize);

    return returnColl;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<DbEntity> getDbEntities() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.

    if (maps.size() == 0) {
        return Collections.emptyList();
    }/*from   w w w  .j av  a2s.c  o  m*/

    if (maps.size() == 1) {
        return maps.iterator().next().getDbEntities();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getDbEntities());
    }

    return c;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<Procedure> getProcedures() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.
    if (maps.size() == 0) {
        return Collections.emptyList();
    }/* www  . j  a  v  a 2 s.  c  o  m*/

    if (maps.size() == 1) {
        return maps.iterator().next().getProcedures();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getProcedures());
    }

    return c;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<QueryDescriptor> getQueryDescriptors() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.
    if (maps.size() == 0) {
        return Collections.emptyList();
    }//from  w w w .j a v a  2 s .  com

    if (maps.size() == 1) {
        return maps.iterator().next().getQueryDescriptors();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getQueryDescriptors());
    }

    return c;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<ObjEntity> getObjEntities() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.
    if (maps.size() == 0) {
        return Collections.emptyList();
    }/*from w  w w  . ja v a 2  s .c o m*/

    if (maps.size() == 1) {
        return maps.iterator().next().getObjEntities();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getObjEntities());
    }

    return c;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<Embeddable> getEmbeddables() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.
    if (maps.size() == 0) {
        return Collections.emptyList();
    }// www.  jav  a2  s  .c o m

    if (maps.size() == 1) {
        return maps.iterator().next().getEmbeddables();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getEmbeddables());
    }

    return c;
}

From source file:org.apache.cayenne.map.MappingCache.java

public Collection<SQLResult> getResults() {
    // TODO: LEGACY SUPPORT:
    // some downstream code (like Modeler and merge framework) expect
    // always fresh list here, so instead of doing the right thing of
    // refreshing the cache and returning cache.entries(), we are scanning
    // the list of DataMaps.

    if (maps.size() == 0) {
        return Collections.emptyList();
    }/*from  w w w. j a  v  a 2 s  .c om*/

    if (maps.size() == 1) {
        return maps.iterator().next().getResults();
    }

    CompositeCollection c = new CompositeCollection();
    for (DataMap map : maps) {
        c.addComposited(map.getResults());
    }

    return c;
}

From source file:org.archive.modules.fetcher.BdbCookieStore.java

/**
 * Returns a {@link LimitedCookieStoreFacade} whose
 * {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies
 * from {@code host} and its parent domains, if applicable.
 *//*ww  w.java 2 s. c  o  m*/
public CookieStore cookieStoreFor(String host) {
    CompositeCollection cookieCollection = new CompositeCollection();

    if (InternetDomainName.isValid(host)) {
        InternetDomainName domain = InternetDomainName.from(host);

        while (domain != null) {
            Collection<Cookie> subset = hostSubset(domain.toString());
            cookieCollection.addComposited(subset);

            if (domain.hasParent()) {
                domain = domain.parent();
            } else {
                domain = null;
            }
        }
    } else {
        Collection<Cookie> subset = hostSubset(host.toString());
        cookieCollection.addComposited(subset);
    }

    @SuppressWarnings("unchecked")
    List<Cookie> cookieList = new RestrictedCollectionWrappedList<Cookie>(cookieCollection);
    LimitedCookieStoreFacade store = new LimitedCookieStoreFacade(cookieList);
    return store;
}

From source file:org.gradle.api.internal.CompositeDomainObjectSet.java

public static <T> CompositeDomainObjectSet<T> create(Class<T> type,
        DomainObjectCollection<? extends T>... collections) {
    //noinspection unchecked
    DefaultDomainObjectSet<T> backingSet = new DefaultDomainObjectSet<T>(type, new CompositeCollection());
    CompositeDomainObjectSet<T> out = new CompositeDomainObjectSet<T>(backingSet);
    for (DomainObjectCollection<? extends T> c : collections) {
        out.addCollection(c);/*from   w w  w .j av a 2s. c  om*/
    }
    return out;
}