Example usage for java.util Queue addAll

List of usage examples for java.util Queue addAll

Introduction

In this page you can find the example usage for java.util Queue addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:org.apache.jackrabbit.oak.run.SegmentUtils.java

private static void debugFileStore(FileStore store) {
    Map<SegmentId, List<SegmentId>> idmap = Maps.newHashMap();
    int dataCount = 0;
    long dataSize = 0;
    int bulkCount = 0;
    long bulkSize = 0;

    ((Logger) getLogger(SegmentTracker.class)).setLevel(Level.OFF);
    RecordUsageAnalyser analyser = new RecordUsageAnalyser();

    for (SegmentId id : store.getSegmentIds()) {
        if (id.isDataSegmentId()) {
            Segment segment = id.getSegment();
            dataCount++;// w ww  . j a va 2  s. com
            dataSize += segment.size();
            idmap.put(id, segment.getReferencedIds());
            analyseSegment(segment, analyser);
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
            idmap.put(id, Collections.<SegmentId>emptyList());
        }
    }
    System.out.println("Total size:");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
    System.out.println(analyser.toString());

    Set<SegmentId> garbage = newHashSet(idmap.keySet());
    Queue<SegmentId> queue = Queues.newArrayDeque();
    queue.add(store.getHead().getRecordId().getSegmentId());
    while (!queue.isEmpty()) {
        SegmentId id = queue.remove();
        if (garbage.remove(id)) {
            queue.addAll(idmap.get(id));
        }
    }
    dataCount = 0;
    dataSize = 0;
    bulkCount = 0;
    bulkSize = 0;
    for (SegmentId id : garbage) {
        if (id.isDataSegmentId()) {
            dataCount++;
            dataSize += id.getSegment().size();
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
        }
    }
    System.out.format("%nAvailable for garbage collection:%n");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
    System.out.format("%n%s", new PCMAnalyser(store).toString());
}

From source file:org.apache.jackrabbit.oak.run.SegmentTarUtils.java

private static void debugFileStore(FileStore store) {
    Map<SegmentId, List<SegmentId>> idmap = Maps.newHashMap();
    int dataCount = 0;
    long dataSize = 0;
    int bulkCount = 0;
    long bulkSize = 0;

    ((Logger) getLogger(SegmentTracker.class)).setLevel(Level.OFF);
    RecordUsageAnalyser analyser = new RecordUsageAnalyser(store.getReader());

    for (SegmentId id : store.getSegmentIds()) {
        if (id.isDataSegmentId()) {
            Segment segment = id.getSegment();
            dataCount++;/*  ww  w.j  av a 2s  .com*/
            dataSize += segment.size();
            idmap.put(id, segment.getReferencedIds());
            analyseSegment(segment, analyser);
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
            idmap.put(id, Collections.<SegmentId>emptyList());
        }
    }
    System.out.println("Total size:");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
    System.out.println(analyser.toString());

    Set<SegmentId> garbage = newHashSet(idmap.keySet());
    Queue<SegmentId> queue = Queues.newArrayDeque();
    queue.add(store.getRevisions().getHead().getSegmentId());
    while (!queue.isEmpty()) {
        SegmentId id = queue.remove();
        if (garbage.remove(id)) {
            queue.addAll(idmap.get(id));
        }
    }
    dataCount = 0;
    dataSize = 0;
    bulkCount = 0;
    bulkSize = 0;
    for (SegmentId id : garbage) {
        if (id.isDataSegmentId()) {
            dataCount++;
            dataSize += id.getSegment().size();
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
        }
    }
    System.out.format("%nAvailable for garbage collection:%n");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * places a key, value pair in each context map of a list of components
 *
 * @param elements the list of elements//from w  w  w . j  a  v a  2 s  .co m
 * @param contextName a value to be used as a key to retrieve the object
 * @param contextValue the value to be placed in the context
 */
public static void pushObjectToContext(Collection<? extends LifecycleElement> elements, String contextName,
        Object contextValue) {
    if (elements == null || elements.isEmpty()) {
        return;
    }

    Queue<LifecycleElement> elementQueue = new LinkedList<LifecycleElement>();

    try {
        elementQueue.addAll(elements);
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();

            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component) {
                ((Component) currentElement).pushObjectToContext(contextName, contextValue);
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Replace all IDs from a component and its children with new generated ID values.
 *
 * <p>If there are features that depend on a static id of this
 * component, this call may cause errors.</p>
 *
 * @param components A list of component to clear all IDs from.
 * @see AssignIdsTask For a complete description of the algorithm.
 *///from  ww w .  java 2s . com
public static void clearAndAssignIds(List<? extends Component> components) {
    if (components == null || components.isEmpty()) {
        return;
    }

    int hash = 1;
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> toClear = RecycleUtils.getInstance(LinkedList.class);
    toClear.addAll(components);
    try {
        while (!toClear.isEmpty()) {
            LifecycleElement element = toClear.poll();

            hash = generateId(element, hash);

            for (LifecycleElement nested : ViewLifecycleUtils.getElementsForLifecycle(element).values()) {
                if (nested != null) {
                    toClear.add(nested);
                }
            }

            if (element instanceof Component) {
                List<Component> propertyReplacerComponents = ((Component) element)
                        .getPropertyReplacerComponents();
                if (propertyReplacerComponents == null) {
                    continue;
                }

                for (Component nested : propertyReplacerComponents) {
                    if (nested != null) {
                        toClear.add(nested);
                    }
                }
            }
        }
    } finally {
        toClear.clear();
        RecycleUtils.recycle(toClear);
    }
}

From source file:com.github.rvesse.airline.model.MetadataLoader.java

/**
 * Loads global meta-data//w  ww.j ava2 s  .co  m
 * 
 * @param name
 *            CLI name
 * @param description
 *            CLI description
 * @param defaultCommand
 *            Default Command
 * @param defaultGroupCommands
 *            Default Group Commands
 * @param groups
 *            Command Groups
 * @param parserConfig
 *            Parser Configuration
 * @param restrictions
 *            Restrictions
 * @return Global meta-data
 */
public static <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand,
        Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups,
        Iterable<GlobalRestriction> restrictions, ParserMetadata<C> parserConfig) {
    List<OptionMetadata> globalOptions = new ArrayList<>();
    if (defaultCommand != null) {
        globalOptions.addAll(defaultCommand.getGlobalOptions());
    }
    for (CommandMetadata command : defaultGroupCommands) {
        globalOptions.addAll(command.getGlobalOptions());
    }
    for (CommandGroupMetadata group : groups) {
        for (CommandMetadata command : group.getCommands()) {
            globalOptions.addAll(command.getGlobalOptions());
        }

        // Remember to also search sub-groups for global options
        Queue<CommandGroupMetadata> subGroups = new LinkedList<CommandGroupMetadata>();
        subGroups.addAll(group.getSubGroups());
        while (subGroups.size() > 0) {
            CommandGroupMetadata subGroup = subGroups.poll();
            for (CommandMetadata command : subGroup.getCommands()) {
                globalOptions.addAll(command.getGlobalOptions());
            }
            subGroups.addAll(subGroup.getSubGroups());
        }
    }
    globalOptions = ListUtils.unmodifiableList(mergeOptionSet(globalOptions));
    return new GlobalMetadata<C>(name, description, globalOptions, defaultCommand, defaultGroupCommands, groups,
            restrictions, parserConfig);
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Traverse a component tree, setting a property on all components for which the property is writable.
 *
 * @param <T> component type//from  www  . jav a2  s. co  m
 * @param <T> component type
 * @param components The components to traverse.
 * @param propertyPath The property path to set.
 * @param propertyValue The property value to set.
 * @see ObjectPropertyUtils#isWritableProperty(Object, String)
 * @see ObjectPropertyUtils#setPropertyValue(Object, String, Object)
 */
public static <T extends Component> void setComponentsPropertyDeep(List<T> components, String propertyPath,
        Object propertyValue) {
    if (components == null || components.isEmpty()) {
        return;
    }

    Set<Class<?>> skipTypes = null;
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.addAll(components);

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());

            Class<?> componentClass = currentElement.getClass();
            if (skipTypes != null && skipTypes.contains(componentClass)) {
                continue;
            }

            if (!ObjectPropertyUtils.isWritableProperty(currentElement, propertyPath)) {
                if (skipTypes == null) {
                    skipTypes = new HashSet<Class<?>>();
                }
                skipTypes.add(componentClass);
                continue;
            }

            ObjectPropertyUtils.setPropertyValue(currentElement, propertyPath, propertyValue, true);
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

public static void updateChildIdsWithSuffixNested(Component component, String idSuffix) {
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    try {//  www .  j ava 2s . c o m
        elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values());

        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component) {
                updateIdWithSuffix((Component) currentElement, idSuffix);
                elementQueue.addAll(((Component) currentElement).getPropertyReplacerComponents());
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * places a all entries from a map into each context map of a list of components
 *
 * @param components The list components.
 * @param sourceContext The source context map.
 *//*ww  w. j a  v  a2  s .c  o  m*/
public static void pushAllToContext(List<? extends Component> components, Map<String, Object> sourceContext) {
    if (components == null || components.isEmpty()) {
        return;
    }

    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    try {
        elementQueue.addAll(components);
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();

            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component) {
                ((Component) currentElement).pushAllToContext(sourceContext);
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:org.jboss.qa.brms.performance.examples.projectjobscheduling.domain.solver.PredecessorsDoneDateUpdatingVariableListener.java

protected void updateAllocation(ScoreDirector scoreDirector, Allocation originalAllocation) {
    Queue<Allocation> uncheckedSuccessorQueue = new ArrayDeque<Allocation>();
    uncheckedSuccessorQueue.addAll(originalAllocation.getSuccessorAllocationList());
    while (!uncheckedSuccessorQueue.isEmpty()) {
        Allocation allocation = uncheckedSuccessorQueue.remove();
        boolean updated = updatePredecessorsDoneDate(scoreDirector, allocation);
        if (updated) {
            uncheckedSuccessorQueue.addAll(allocation.getSuccessorAllocationList());
        }/*ww  w . ja  v a 2  s  .com*/
    }
}

From source file:org.ros.internal.message.new_style.ServiceLoader.java

private void findMessages(File searchPath) {
    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    FindServicesFilter filter = new FindServicesFilter();
    Queue<File> childPaths = Lists.newLinkedList();
    childPaths.addAll(listPathEntries(searchPath, filter));
    while (!childPaths.isEmpty()) {
        File servicePath = childPaths.poll();
        if (servicePath.isDirectory()) {
            childPaths.addAll(listPathEntries(servicePath, filter));
        } else {//www . j  a  v  a  2  s.  com
            try {
                addServiceDefinitionFromPaths(searchPath, servicePath, decoder);
            } catch (IOException e) {
                log.error("Failed to read service: " + servicePath.getAbsolutePath(), e);
            }
        }
    }
}