Example usage for com.google.common.collect Iterables addAll

List of usage examples for com.google.common.collect Iterables addAll

Introduction

In this page you can find the example usage for com.google.common.collect Iterables addAll.

Prototype

public static <T> boolean addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd) 

Source Link

Document

Adds all elements in iterable to collection .

Usage

From source file:org.eclipse.sirius.table.business.internal.dialect.TableContributionsFinder.java

/**
 * {@inheritDoc}//from w  ww  .  ja  va2  s .c  o  m
 */
public Iterable<Contribution> apply(Iterable<EObject> from) {
    LinkedHashSet<EObject> sortedRepresentations = getRelevantRepresentations(getAllRepresentations(from));
    ArrayList<EObject> reversed = Lists.newArrayList(sortedRepresentations);
    Collections.reverse(reversed);

    List<Contribution> result = Lists.newArrayList();
    for (EObject root : reversed) {
        Iterables.addAll(result,
                Iterables.filter(AllContents.of(root, ContributionPackage.eINSTANCE.getContribution(), true),
                        Contribution.class));
    }
    return result;
}

From source file:org.apache.cassandra.db.MeteredFlusher.java

public void run() {
    // first, find how much memory non-active memtables are using
    Memtable activelyMeasuring = Memtable.activelyMeasuring;
    long flushingBytes = activelyMeasuring == null ? 0 : activelyMeasuring.getLiveSize();
    flushingBytes += countFlushingBytes();

    // next, flush CFs using more than 1 / (maximum number of memtables it could have in the pipeline)
    // of the total size allotted.  Then, flush other CFs in order of size if necessary.
    long liveBytes = 0;
    try {//ww  w  . j  a va2 s.c  o m
        for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) {
            long size = cfs.getTotalMemtableLiveSize();
            int maxInFlight = (int) Math.ceil((double) (1 // live memtable
                    + 1 // potentially a flushed memtable being counted by jamm
                    + DatabaseDescriptor.getFlushWriters() + DatabaseDescriptor.getFlushQueueSize())
                    / (1 + cfs.getIndexedColumns().size()));
            if (size > (DatabaseDescriptor.getTotalMemtableSpaceInMB() * 1048576L - flushingBytes)
                    / maxInFlight) {
                logger.info("flushing high-traffic column family {}", cfs);
                cfs.forceFlush();
            } else {
                liveBytes += size;
            }
        }

        if (flushingBytes + liveBytes <= DatabaseDescriptor.getTotalMemtableSpaceInMB() * 1048576L)
            return;

        logger.info("estimated {} bytes used by all memtables pre-flush", liveBytes);

        // sort memtables by size
        List<ColumnFamilyStore> sorted = new ArrayList<ColumnFamilyStore>();
        Iterables.addAll(sorted, ColumnFamilyStore.all());
        Collections.sort(sorted, new Comparator<ColumnFamilyStore>() {
            public int compare(ColumnFamilyStore o1, ColumnFamilyStore o2) {
                long size1 = o1.getTotalMemtableLiveSize();
                long size2 = o2.getTotalMemtableLiveSize();
                if (size1 < size2)
                    return -1;
                if (size1 > size2)
                    return 1;
                return 0;
            }
        });

        // flush largest first until we get below our threshold.
        // although it looks like liveBytes + flushingBytes will stay a constant, it will not if flushes finish
        // while we loop, which is especially likely to happen if the flush queue fills up (so further forceFlush calls block)
        while (true) {
            flushingBytes = countFlushingBytes();
            if (liveBytes + flushingBytes <= DatabaseDescriptor.getTotalMemtableSpaceInMB() * 1048576L
                    || sorted.isEmpty())
                break;

            ColumnFamilyStore cfs = sorted.remove(sorted.size() - 1);
            long size = cfs.getTotalMemtableLiveSize();
            logger.info("flushing {} to free up {} bytes", cfs, size);
            liveBytes -= size;
            cfs.forceFlush();
        }
    } finally {
        logger.trace("memtable memory usage is {} bytes with {} live", liveBytes + flushingBytes, liveBytes);
    }
}

From source file:com.zimbra.soap.admin.type.CosInfo.java

public static List<Attr> toAttrsList(Iterable<CosInfoAttr> params) {
    if (params == null)
        return null;
    List<Attr> newList = Lists.newArrayList();
    Iterables.addAll(newList, params);
    return Collections.unmodifiableList(newList);
}

From source file:io.druid.segment.IndexBuilder.java

public IndexBuilder add(Iterable<InputRow> rows) {
    Iterables.addAll(this.rows, rows);
    return this;
}

From source file:org.apache.jackrabbit.oak.upgrade.nodestate.AbstractDecoratedNodeState.java

/**
 * Convenience method to help implementations that hide nodes set the
 * :childOrder (OAK_CHILD_ORDER) property to its correct value.
 * <br>/*w  w  w.j a va2 s  .c  om*/
 * Intended to be used to implement {@link #decorateProperty(PropertyState)}.
 *
 * @param nodeState The current node state.
 * @param propertyState The property that chould be checked.
 * @return The original propertyState, unless the property is called {@code :childOrder}.
 */
protected static PropertyState fixChildOrderPropertyState(NodeState nodeState, PropertyState propertyState) {
    if (propertyState != null && OAK_CHILD_ORDER.equals(propertyState.getName())) {
        final Collection<String> childNodeNames = new ArrayList<String>();
        Iterables.addAll(childNodeNames, nodeState.getChildNodeNames());
        final Iterable<String> values = Iterables.filter(propertyState.getValue(Type.NAMES),
                Predicates.in(childNodeNames));
        return PropertyStates.createProperty(OAK_CHILD_ORDER, values, Type.NAMES);
    }
    return propertyState;
}

From source file:com.zimbra.soap.mail.type.ModifyContactSpec.java

public void setContactGroupMembers(Iterable<ModifyContactGroupMember> contactGroupMembers) {
    this.contactGroupMembers.clear();
    if (contactGroupMembers != null) {
        Iterables.addAll(this.contactGroupMembers, contactGroupMembers);
    }/*w  ww  .  j a va2  s.c o  m*/
}

From source file:com.zimbra.soap.admin.type.XProp.java

public static List<XPropInterface> toInterfaces(Iterable<XProp> params) {
    if (params == null)
        return null;
    List<XPropInterface> newList = Lists.newArrayList();
    Iterables.addAll(newList, params);
    return newList;
}

From source file:org.fit.cssbox.scriptbox.events.TaskQueues.java

/**
 * Filters given task source queue by a predicate.
 * /*  ww  w .j  a  v a  2  s  . c om*/
 * @param source Task source that should be filtered.
 * @param predicate Predicate which ensures filtering. On success
 *        the task is left untouched, otherwise will be removed.
 */
public synchronized void filter(TaskSource source, Predicate<Task> predicate) {
    List<Task> tasks = get(source);

    if (tasks != null) {
        List<Task> filteredTasks = new LinkedList<Task>();
        Iterables.addAll(filteredTasks, Iterables.filter(tasks, predicate));

        if (filteredTasks.isEmpty()) {
            remove(source);
        } else {
            put(source, filteredTasks);
        }
    }
}

From source file:com.zimbra.soap.mail.message.GetImportStatusResponse.java

public void setStatuses(Iterable<ImportStatusInfo> statuses) {
    this.statuses.clear();
    if (statuses != null) {
        Iterables.addAll(this.statuses, statuses);
    }/*from  w  w w .  j a va 2s  .  com*/
}

From source file:uk.co.unclealex.process.builder.BuildingProcessRequest.java

/**
 * {@inheritDoc}//from   w  w w.java 2 s  .c om
 */
@Override
public BuildableProcessRequest withArguments(final Iterable<String> arguments) {
    Iterables.addAll(getArguments(), arguments);
    return this;
}