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.ros.internal.message.new_style.MessageLoader.java

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

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

public static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass) {
    Annotation annotation = cliClass.getAnnotation(com.github.rvesse.airline.annotations.Cli.class);
    if (annotation == null)
        throw new IllegalArgumentException(
                String.format("Class %s does not have the @Cli annotation", cliClass));

    com.github.rvesse.airline.annotations.Cli cliConfig = (com.github.rvesse.airline.annotations.Cli) annotation;

    // Prepare commands
    CommandMetadata defaultCommand = null;
    if (!cliConfig.defaultCommand().equals(com.github.rvesse.airline.annotations.Cli.NO_DEFAULT.class)) {
        defaultCommand = loadCommand(cliConfig.defaultCommand());
    }//from   w w w .j a  va2s .  com
    List<CommandMetadata> defaultGroupCommands = new ArrayList<CommandMetadata>();
    for (Class<?> cls : cliConfig.commands()) {
        defaultGroupCommands.add(loadCommand(cls));
    }

    // Prepare parser configuration
    ParserMetadata<C> parserConfig = cliConfig.parserConfiguration() != null
            ? MetadataLoader.<C>loadParser(cliConfig.parserConfiguration())
            : MetadataLoader.<C>loadParser(cliClass);

    // Prepare restrictions
    // We find restrictions in the following order:
    // 1 - Those declared via annotations
    // 2 - Those declared via the restrictions field of the @Cli annotation
    // 3 - Standard restrictions if the includeDefaultRestrctions field of
    // the @Cli annotation is true
    List<GlobalRestriction> restrictions = new ArrayList<GlobalRestriction>();
    for (Class<? extends Annotation> annotationClass : RestrictionRegistry
            .getGlobalRestrictionAnnotationClasses()) {
        annotation = cliClass.getAnnotation(annotationClass);
        if (annotation == null)
            continue;
        GlobalRestriction restriction = RestrictionRegistry.getGlobalRestriction(annotationClass, annotation);
        if (restriction != null)
            restrictions.add(restriction);
    }
    for (Class<? extends GlobalRestriction> cls : cliConfig.restrictions()) {
        restrictions.add(ParserUtil.createInstance(cls));
    }
    if (cliConfig.includeDefaultRestrictions()) {
        restrictions.addAll(AirlineUtils.arrayToList(GlobalRestriction.DEFAULTS));
    }

    // Prepare groups
    // We sort sub-groups by name length then lexically
    // This means that when we build the groups hierarchy we'll ensure we
    // build the parent groups first wherever possible
    Map<String, CommandGroupMetadata> subGroups = new TreeMap<String, CommandGroupMetadata>(
            new StringHierarchyComparator());
    List<CommandGroupMetadata> groups = new ArrayList<CommandGroupMetadata>();
    for (Group groupAnno : cliConfig.groups()) {
        String groupName = groupAnno.name();
        String subGroupPath = null;
        if (StringUtils.containsWhitespace(groupName)) {
            // Normalize the path
            subGroupPath = StringUtils.join(StringUtils.split(groupAnno.name()), ' ');
        }

        // Maybe a top level group we've already seen
        CommandGroupMetadata group = CollectionUtils.find(groups, new GroupFinder(groupName));
        if (group == null) {
            // Maybe a sub-group we've already seen
            group = subGroups.get(subGroupPath);
        }

        List<CommandMetadata> groupCommands = new ArrayList<CommandMetadata>();
        for (Class<?> cls : groupAnno.commands()) {
            groupCommands.add(loadCommand(cls));
        }

        if (group == null) {
            // Newly discovered group
            //@formatter:off
            group = loadCommandGroup(subGroupPath != null ? subGroupPath : groupName, groupAnno.description(),
                    groupAnno.hidden(), Collections.<CommandGroupMetadata>emptyList(),
                    !groupAnno.defaultCommand().equals(Group.NO_DEFAULT.class)
                            ? loadCommand(groupAnno.defaultCommand())
                            : null,
                    groupCommands);
            //@formatter:on
            if (subGroupPath == null) {
                groups.add(group);
            } else {
                // Remember sub-groups for later
                subGroups.put(subGroupPath, group);
            }
        } else {
            for (CommandMetadata cmd : groupCommands) {
                group.addCommand(cmd);
            }
        }
    }
    // Build sub-group hierarchy
    buildGroupsHierarchy(groups, subGroups);

    // Find all commands
    List<CommandMetadata> allCommands = new ArrayList<CommandMetadata>();
    allCommands.addAll(defaultGroupCommands);
    if (defaultCommand != null && !defaultGroupCommands.contains(defaultCommand)) {
        allCommands.add(defaultCommand);
    }
    for (CommandGroupMetadata group : groups) {
        allCommands.addAll(group.getCommands());
        if (group.getDefaultCommand() != null) {
            allCommands.add(group.getDefaultCommand());
        }

        Queue<CommandGroupMetadata> subGroupsQueue = new LinkedList<CommandGroupMetadata>();
        subGroupsQueue.addAll(group.getSubGroups());
        while (subGroupsQueue.size() > 0) {
            CommandGroupMetadata subGroup = subGroupsQueue.poll();
            allCommands.addAll(subGroup.getCommands());
            if (subGroup.getDefaultCommand() != null)
                allCommands.add(subGroup.getDefaultCommand());
            subGroupsQueue.addAll(subGroup.getSubGroups());
        }
    }

    // Post-process to find possible further group assignments
    loadCommandsIntoGroupsByAnnotation(allCommands, groups, defaultGroupCommands);

    return loadGlobal(cliConfig.name(), cliConfig.description(), defaultCommand, defaultGroupCommands, groups,
            restrictions, parserConfig);
}

From source file:org.polymap.core.model2.engine.EntityRepositoryImpl.java

public EntityRepositoryImpl(final EntityRepositoryConfiguration config) {
    this.config = config;

    // init store
    getStore().init(new StoreRuntimeContextImpl());

    // init infos
    log.info("Initialializing Composite types:");
    Queue<Class<? extends Composite>> queue = new LinkedList();
    queue.addAll(Arrays.asList(config.getEntities()));

    while (!queue.isEmpty()) {
        log.info("    Composite type: " + queue.peek());
        CompositeInfoImpl info = new CompositeInfoImpl(queue.poll());
        infos.put(info.getType(), info);

        // mixins
        queue.addAll(info.getMixins());/*from   ww  w .jav a2 s. c o m*/

        // Composite properties
        for (PropertyInfo propInfo : info.getProperties()) {
            if (Composite.class.isAssignableFrom(propInfo.getType())) {
                queue.offer(propInfo.getType());
            }
        }
    }
}

From source file:org.intellij.erlang.psi.impl.ErlangPsiImplUtil.java

private static boolean processDeclarationRecursive(ErlangCompositeElement o, PsiScopeProcessor processor,
        ResolveState state) {//from w  w  w .  j  a v a  2s  .  co  m
    Queue<ErlangCompositeElement> queue = new LinkedList<ErlangCompositeElement>();
    queue.add(o);
    while (!queue.isEmpty()) {
        ErlangCompositeElement top = queue.remove();
        if (!processor.execute(top, state))
            return false;
        queue.addAll(PsiTreeUtil.getChildrenOfTypeAsList(top, ErlangCompositeElement.class));
    }
    return true;
}

From source file:org.wicketopia.mapping.ClassBasedTypeMapping.java

@SuppressWarnings("unchecked")
private Queue<Class<?>> createTypeQueue(final Class<?> originalType) {
    Queue<Class<?>> queue = new LinkedList<Class<?>>();
    Class currentType = originalType;
    do {/*from w  ww  . j  a  v a  2 s  .com*/
        queue.add(currentType);
        currentType = currentType.getSuperclass();
    } while (currentType != null);
    queue.addAll(ClassUtils.getAllInterfaces(originalType));
    return queue;
}

From source file:com.github.rvesse.airline.builder.CliBuilder.java

@Override
public Cli<C> build() {
    CommandMetadata defaultCommandMetadata = null;
    List<CommandMetadata> allCommands = new ArrayList<CommandMetadata>();
    if (defaultCommand != null) {
        defaultCommandMetadata = MetadataLoader.loadCommand(defaultCommand);
    }/*from   www  .  j a  va2s . c o  m*/

    List<CommandMetadata> defaultCommandGroup = defaultCommandGroupCommands != null
            ? MetadataLoader.loadCommands(defaultCommandGroupCommands)
            : new ArrayList<CommandMetadata>();

    allCommands.addAll(defaultCommandGroup);
    if (defaultCommandMetadata != null)
        allCommands.add(defaultCommandMetadata);

    // Build groups
    List<CommandGroupMetadata> commandGroups;
    if (groups != null) {
        commandGroups = new ArrayList<CommandGroupMetadata>();
        for (GroupBuilder<C> groupBuilder : groups.values()) {
            commandGroups.add(groupBuilder.build());
        }
    } else {
        commandGroups = new ArrayList<>();
    }

    // Find all commands registered in groups and sub-groups, we use this to
    // check this is a valid CLI with at least 1 command
    for (CommandGroupMetadata group : commandGroups) {
        allCommands.addAll(group.getCommands());
        if (group.getDefaultCommand() != null)
            allCommands.add(group.getDefaultCommand());

        // Make sure to scan sub-groups
        Queue<CommandGroupMetadata> subGroups = new LinkedList<CommandGroupMetadata>();
        subGroups.addAll(group.getSubGroups());
        while (!subGroups.isEmpty()) {
            CommandGroupMetadata subGroup = subGroups.poll();
            allCommands.addAll(subGroup.getCommands());
            if (subGroup.getDefaultCommand() != null)
                allCommands.add(subGroup.getDefaultCommand());
            subGroups.addAll(subGroup.getSubGroups());
        }
    }

    // add commands to groups based on the value of groups in the @Command
    // annotations
    // rather than change the entire way metadata is loaded, I figured just
    // post-processing was an easier, yet uglier, way to go
    MetadataLoader.loadCommandsIntoGroupsByAnnotation(allCommands, commandGroups, defaultCommandGroup);

    // Build restrictions
    // Use defaults if none specified
    if (restrictions.size() == 0)
        withDefaultRestrictions();

    if (allCommands.size() == 0)
        throw new IllegalArgumentException("Must specify at least one command to create a CLI");

    // Build metadata objects
    GlobalMetadata<C> metadata = MetadataLoader.<C>loadGlobal(name, description, defaultCommandMetadata,
            ListUtils.unmodifiableList(defaultCommandGroup), ListUtils.unmodifiableList(commandGroups),
            ListUtils.unmodifiableList(restrictions), this.parserBuilder.build());

    return new Cli<C>(metadata);
}

From source file:eu.stratosphere.nephele.jobmanager.splitassigner.DefaultInputSplitAssigner.java

@Override
public void registerGroupVertex(final ExecutionGroupVertex groupVertex) {

    final InputSplit[] inputSplits = groupVertex.getInputSplits();

    if (inputSplits == null) {
        return;//from ww  w .  jav a2 s. co  m
    }

    if (inputSplits.length == 0) {
        return;
    }

    final Queue<InputSplit> queue = new ConcurrentLinkedQueue<InputSplit>();
    if (this.splitMap.putIfAbsent(groupVertex, queue) != null) {
        LOG.error("Group vertex " + groupVertex.getName() + " already has a split queue");
    }

    queue.addAll(Arrays.asList(inputSplits));
}

From source file:org.protempa.backend.ksb.SimpleKnowledgeSourceBackend.java

private Collection<String> collectSubtreePropositionIdsInt(String[] propIds, boolean narrower,
        boolean inDataSource) {
    Set<String> result = new HashSet<>(Arrays.asSet(propIds));
    Queue<String> queue = new LinkedList<>();
    queue.addAll(result);
    while (!queue.isEmpty()) {
        String propId = queue.poll();
        PropositionDefinition pd = this.propDefsMap.get(propId);
        if (!inDataSource || pd.getInDataSource()) {
            result.add(propId);//from w w  w  .  j  a  va  2  s.  c  o m
        }
        if (narrower) {
            Arrays.addAll(queue, pd.getChildren());
        } else {
            Arrays.addAll(queue, pd.getInverseIsA());
        }
    }
    return result;
}

From source file:org.jbpm.services.task.jaxb.ComparePair.java

public void recursiveCompare() {
    Queue<ComparePair> compares = new LinkedList<ComparePair>();
    compares.add(this);
    while (!compares.isEmpty()) {
        compares.addAll(compares.poll().compare());
    }/*w w  w.j a  v  a2  s  . c  o m*/
}

From source file:org.apache.hadoop.corona.PoolGroupManager.java

/**
 * Put all the pool groups into the priority queue sorted by a comparator
 * @param comparator the comparator to sort all the pool groups in the queue
 * @return the queue of the pool groups sorted by a comparator
 *///from w w w .  ja v a2 s. c  o  m
private Queue<PoolGroupSchedulable> createPoolGroupQueue(ScheduleComparator comparator) {
    int initCapacity = snapshotPoolGroups.size() == 0 ? 1 : snapshotPoolGroups.size();
    Queue<PoolGroupSchedulable> poolGroupQueue = new PriorityQueue<PoolGroupSchedulable>(initCapacity,
            comparator);
    poolGroupQueue.addAll(snapshotPoolGroups);
    return poolGroupQueue;
}