Example usage for java.util Deque addAll

List of usage examples for java.util Deque addAll

Introduction

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

Prototype

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

Source Link

Document

Adds all of the elements in the specified collection at the end of this deque, as if by calling #addLast on each one, in the order that they are returned by the collection's iterator.

Usage

From source file:org.graphwalker.io.factory.yed.YEdContextFactory.java

private Vertex addVertices(Model model, Context context, GraphmlDocument document, Map<String, Vertex> elements)
        throws XmlException {
    Vertex startVertex = null;//from   w ww.j  a v  a  2 s  . c  om
    Deque<XmlObject> workQueue = new ArrayDeque<>();
    workQueue.addAll(Arrays.asList(document.selectPath(NAMESPACE + "$this/xq:graphml/xq:graph/xq:node")));
    while (!workQueue.isEmpty()) {
        XmlObject object = workQueue.pop();
        if (object instanceof NodeType) {
            NodeType node = (NodeType) object;
            if (0 < node.getGraphArray().length) {
                for (GraphType subgraph : node.getGraphArray()) {
                    workQueue.addAll(Arrays.asList(subgraph.getNodeArray()));
                }
            } else {
                String description = "";
                for (DataType data : node.getDataArray()) {
                    if (0 < data.getDomNode().getChildNodes().getLength()) {
                        if (data.getKey().equals("d5")) {
                            description = ((DataTypeImpl) data).getStringValue();
                        }
                        if (isSupportedNode(data.xmlText())) {
                            StringBuilder label = new StringBuilder();
                            for (NodeLabelType nodeLabel : getSupportedNode(data.xmlText())
                                    .getNodeLabelArray()) {
                                label.append(((NodeLabelTypeImpl) nodeLabel).getStringValue());
                            }
                            YEdVertexParser parser = new YEdVertexParser(getTokenStream(label.toString()));
                            parser.removeErrorListeners();
                            parser.addErrorListener(YEdDescriptiveErrorListener.INSTANCE);
                            YEdVertexParser.ParseContext parseContext = parser.parse();
                            Vertex vertex = new Vertex();
                            if (!description.isEmpty()) {
                                vertex.setProperty("description", description);
                            }
                            vertex.setProperty("x", getSupportedNode(data.xmlText()).getGeometry().getX());
                            vertex.setProperty("y", getSupportedNode(data.xmlText()).getGeometry().getY());
                            boolean blocked = false;
                            if (null != parseContext.start()) {
                                elements.put(node.getId(), vertex);
                                vertex.setId(node.getId());
                                startVertex = vertex;
                            } else {
                                for (YEdVertexParser.FieldContext field : parseContext.field()) {
                                    if (null != field.names()) {
                                        vertex.setName(field.names().getText());
                                    }
                                    if (null != field.shared() && null != field.shared().Identifier()) {
                                        vertex.setSharedState(field.shared().Identifier().getText());
                                    }
                                    if (null != field.reqtags()) {
                                        vertex.setRequirements(convertVertexRequirement(
                                                field.reqtags().reqtagList().reqtag()));
                                    }
                                    if (null != field.actions()) {
                                        model.addActions(convertVertexAction(field.actions().action()));
                                    }
                                    if (null != field.blocked()) {
                                        blocked = true;
                                    }
                                }
                                if (!blocked) {
                                    elements.put(node.getId(), vertex);
                                    vertex.setId(node.getId());
                                    model.addVertex(vertex);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return startVertex;
}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.result.collection.SetCollectionTypeListener.java

/** {@inheritDoc} */
@Override//from w  w w.  j a v a 2s .  com
public void handleEvent(final UpdatedCollectionResultTypeEvent<C, R, E, B> event) throws EventException {
    SetCollectionTypeListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    final AnnotationCollectionResultDescriptorBuilder<C, R, E, B> builder = event.getBuilder();
    final Deque<Member> members = new LinkedList<Member>();
    members.addAll(builder.getBuilderContext().getAccessorContext().getDescribedProperties());
    members.add(builder.getOperation());
    final Class<?> collectionType;
    final java.lang.reflect.Type tmpType = GenericsUtil.getPropertyGenericType(Collection.class, 0, members);
    if (tmpType instanceof Class) {
        collectionType = (Class<?>) tmpType;
    } else if (tmpType instanceof ParameterizedType) {
        final ParameterizedType ptype = (ParameterizedType) tmpType;
        final Type rawType = ptype.getRawType();
        if (rawType instanceof Class) {
            collectionType = (Class<?>) rawType;
        } else {
            collectionType = Object.class;
        }
    } else {
        collectionType = Object.class;
    }
    builder.collectionType(collectionType);
}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.result.SetResultListener.java

/** {@inheritDoc} */
@Override/*from  ww w.  ja  v  a2 s  .c o m*/
public void handleEvent(final UpdatedOperationReferenceEvent<E, B> event) throws EventException {
    SetResultListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    final AnnotationOperationDescriptorBuilder<E, B> builder = event.getBuilder();
    final Deque<Member> members = new LinkedList<Member>();
    members.add(builder.getOperation());
    members.addAll(builder.getBuilderContext().getAccessorContext().getDescribedProperties());
    final java.lang.reflect.Type type = GenericsUtil.getRealType(members);
    final AnnotationResultDescriptorBuilder<R, E, B> resultDescriptor = builder.getResultBuilder();
    if (type instanceof Class) {
        resultDescriptor.type((Class<?>) type);
    } else {
        final Class<?> guessedClazz = GenericsUtil.guessClazz(type);
        resultDescriptor.type(guessedClazz);
    }

}

From source file:org.marketcetera.marketdata.core.webservice.impl.MarketDataServiceImpl.java

/**
 * Gets the most recent snapshot for the given attributes.
 *
 * @param inInstrument an <code>Instrument</code> value
 * @param inContent a <code>Content</code> value
 * @param inProvider a <code>String</code> value or <code>null</code>
 * @return a <code>Deque&lt;Event&gt;</code> value
 *//*from  w ww  .  j  a v  a 2  s .c om*/
private Deque<Event> doGetSnapshot(Instrument inInstrument, Content inContent, String inProvider) {
    Event event = marketDataManager.requestMarketDataSnapshot(inInstrument, inContent, inProvider);
    if (event == null) {
        return new LinkedList<>();
    }
    Deque<Event> eventsToReturn = Lists.newLinkedList();
    if (event instanceof AggregateEvent) {
        eventsToReturn.addAll(((AggregateEvent) event).decompose());
    } else {
        eventsToReturn.add(event);
    }
    return eventsToReturn;
}

From source file:org.marketcetera.marketdata.core.webservice.impl.MarketDataServiceImpl.java

/**
 * Gets the requested page of the most recent snapshot for the given attribute.
 *
 * @param inInstrument an <code>Instrument</code> value
 * @param inContent a <code>Content</code> value
 * @param inProvider a <code>String</code> value or <code>null</code>
 * @param inPageRequest a <code>PageRequest</code> value
 * @return a <code>Deque&lt;Event&gt;</code> value
 *//*from   www .ja  v  a 2 s  . c om*/
private Deque<Event> doGetSnapshotPage(Instrument inInstrument, Content inContent, String inProvider,
        PageRequest inPageRequest) {
    Event event = marketDataManager.requestMarketDataSnapshot(inInstrument, inContent, inProvider);
    if (event == null) {
        return new LinkedList<>();
    }
    Deque<Event> eventsToReturn = Lists.newLinkedList();
    if (event instanceof AggregateEvent) {
        eventsToReturn.addAll(((AggregateEvent) event).decompose());
    } else {
        eventsToReturn.add(event);
    }
    // TODO pick out page
    return eventsToReturn;
}

From source file:org.nuxeo.ecm.core.storage.sql.PersistenceContext.java

/**
 * Removes a property node and its children.
 * <p>/*w  ww.jav  a  2  s  . c  o m*/
 * There's less work to do than when we have to remove a generic document
 * node (less selections, and we can assume the depth is small so recurse).
 */
public void removePropertyNode(SimpleFragment hierFragment) throws StorageException {
    // collect children
    Deque<SimpleFragment> todo = new LinkedList<SimpleFragment>();
    List<SimpleFragment> children = new LinkedList<SimpleFragment>();
    todo.add(hierFragment);
    while (!todo.isEmpty()) {
        SimpleFragment fragment = todo.removeFirst();
        todo.addAll(getChildren(fragment.getId(), null, true)); // complex
        children.add(fragment);
    }
    Collections.reverse(children);
    // iterate on children depth first
    for (SimpleFragment fragment : children) {
        // remove from context
        boolean primary = fragment == hierFragment;
        removeFragmentAndDependents(fragment, primary);
        // remove from selections
        // removed from its parent selection
        hierComplex.recordRemoved(fragment);
        // no children anymore
        hierComplex.recordRemovedSelection(fragment.getId());
    }
}

From source file:org.openscore.lang.compiler.utils.ExecutableBuilder.java

private Workflow compileWorkFlow(LinkedHashMap<String, Map<String, Object>> workFlowRawData,
        Map<String, String> imports, Workflow onFailureWorkFlow, boolean onFailureSection) {

    Deque<Task> tasks = new LinkedList<>();

    Validate.notEmpty(workFlowRawData, "Flow must have tasks in its workflow");

    PeekingIterator<Map.Entry<String, Map<String, Object>>> iterator = new PeekingIterator<>(
            workFlowRawData.entrySet().iterator());

    boolean isOnFailureDefined = onFailureWorkFlow != null;

    String defaultFailure = isOnFailureDefined ? onFailureWorkFlow.getTasks().getFirst().getName()
            : FAILURE_RESULT;/*from  w ww.  j  a va2  s. c o m*/

    while (iterator.hasNext()) {
        Map.Entry<String, Map<String, Object>> taskRawData = iterator.next();
        Map.Entry<String, Map<String, Object>> nextTaskData = iterator.peek();
        String taskName = taskRawData.getKey();
        Map<String, Object> taskRawDataValue;
        try {
            taskRawDataValue = taskRawData.getValue();
        } catch (ClassCastException ex) {
            throw new RuntimeException("Task: " + taskName
                    + " syntax is illegal.\nBelow task name, there should be a map of values in the format:\ndo:\n\top_name:");
        }

        String defaultSuccess;
        if (nextTaskData != null) {
            defaultSuccess = nextTaskData.getKey();
        } else {
            defaultSuccess = onFailureSection ? FAILURE_RESULT : SUCCESS_RESULT;
        }
        Task task = compileTask(taskName, taskRawDataValue, defaultSuccess, imports, defaultFailure);
        tasks.add(task);
    }

    if (isOnFailureDefined) {
        tasks.addAll(onFailureWorkFlow.getTasks());
    }

    return new Workflow(tasks);
}

From source file:org.polymap.model2.store.geotools.FeatureTypeBuilder.java

protected ComplexType buildComplexType(Class<? extends Composite> compositeClass, String indent)
        throws Exception {
    // fields -> properties
    Collection<PropertyDescriptor> properties = new ArrayList();

    // super classes and mixins
    Deque<Class> stack = new ArrayDeque();
    stack.push(compositeClass);//from   ww  w .java 2  s .c om

    while (!stack.isEmpty()) {
        Class type = stack.pop();
        log.debug(indent + "Composite: " + type);

        // super class
        if (type.getSuperclass() != null && !Entity.class.equals(type.getSuperclass())
                && !Composite.class.equals(type.getSuperclass())) {
            stack.push(type.getSuperclass());
        }

        // mixins
        CompositeInfoImpl typeInfo = new CompositeInfoImpl(type);
        //log.debug( indent + "  " + "Mixins: " + typeInfo.getMixins() );
        stack.addAll(typeInfo.getMixins());

        // fields
        for (Field field : type.getDeclaredFields()) {
            // Property or CollectionProperty
            if (Property.class.isAssignableFrom(field.getType())
                    || CollectionProperty.class.isAssignableFrom(field.getType())) {

                PropertyInfoImpl propInfo = new PropertyInfoImpl(field);
                Class<?> binding = propInfo.getType();

                // attribute
                if (binding.isPrimitive() || binding.equals(String.class)
                        || Number.class.isAssignableFrom(binding) || Boolean.class.isAssignableFrom(binding)
                        || Date.class.isAssignableFrom(binding) || binding.isEnum()) {

                    if (binding.isEnum()) {
                        binding = String.class;
                    }
                    AttributeType propType = buildAttributeType(field, binding);
                    AttributeDescriptor desc = factory.createAttributeDescriptor(propType, propType.getName(),
                            0, propInfo.getMaxOccurs(), propInfo.isNullable(), propInfo.getDefaultValue());
                    properties.add(desc);
                    log.debug(indent + "  " + "Attribute: " + desc);
                }
                // geometry
                else if (Geometry.class.isAssignableFrom(binding)) {
                    AttributeType propType = buildAttributeType(field, binding);

                    GeometryType geomType = factory.createGeometryType(propType.getName(),
                            propType.getBinding(), crs, propType.isIdentified(), propType.isAbstract(),
                            propType.getRestrictions(), propType.getSuper(), propType.getDescription());

                    GeometryDescriptor desc = factory.createGeometryDescriptor(geomType, geomType.getName(), 0,
                            1, propInfo.isNullable(), propInfo.getDefaultValue());
                    properties.add(desc);
                    log.debug(indent + "  " + "Geometry: " + desc);
                }
                // complex
                else if (Composite.class.isAssignableFrom(binding)) {
                    ComplexType propType = buildComplexType((Class<? extends Composite>) binding,
                            indent + "    ");
                    AttributeDescriptor desc = factory.createAttributeDescriptor(propType, nameInStore(field),
                            0, propInfo.getMaxOccurs(), propInfo.isNullable(), propInfo.getDefaultValue());
                    properties.add(desc);
                    log.debug(indent + "  " + "Complex Property: " + desc);
                } else {
                    throw new RuntimeException("Property value type is not supported: " + binding);
                }
            }
        }
    }

    NameInStore nameInStore = compositeClass.getAnnotation(NameInStore.class);
    Name name = buildName(nameInStore != null ? nameInStore.value() : compositeClass.getSimpleName());
    boolean isIdentified = false;
    boolean isAbstract = false;
    List<Filter> restrictions = null;
    AttributeType superType = null;
    Description annotation = compositeClass.getAnnotation(Description.class);
    InternationalString description = annotation != null ? SimpleInternationalString.wrap(annotation.value())
            : null;

    return factory.createComplexType(name, properties, isIdentified, isAbstract, restrictions, superType,
            description);
}

From source file:org.polymap.rhei.form.BasePageContainer.java

protected void updateEnabled() {
    if (pageBody == null || pageBody.isDisposed()) {
        return;/* www. j ava2s . co  m*/
    }

    Deque<Control> deque = new LinkedList(Collections.singleton(pageBody));
    while (!deque.isEmpty()) {
        Control control = deque.pop();

        String variant = (String) control.getData(RWT.CUSTOM_VARIANT);
        log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")");

        log.warn("!!! NOT YET (RE)IMPLEMENTED !!!");
        //            // form fields
        //            if (variant == null 
        //                    || variant.equals( CSS_FORMFIELD ) || variant.equals( CSS_FORMFIELD_DISABLED ) 
        //                    || variant.equals( CUSTOM_VARIANT_VALUE ) || variant.equals( CUSTOM_VARIANT_VALUE )) {
        //                UIUtils.setVariant( control, enabled ? CSS_FORMFIELD : CSS_FORMFIELD_DISABLED  );
        //            }
        //            // form
        //            else if (variant.equals( CSS_FORM ) || variant.equals( CSS_FORM_DISABLED )) {
        //                UIUtils.setVariant( control, enabled ? CSS_FORM : CSS_FORM_DISABLED  );
        //            }

        //            // labeler Label
        //            String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT );
        //            if (control instanceof Label
        //                    && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) {
        //                control.setFont( enabled 
        //                        ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT )
        //                        : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) );
        //
        //                if (!enabled) {
        //                    control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) );
        //                }
        //            }
        // Composite
        if (control instanceof Composite) {
            control.setEnabled(enabled);

            deque.addAll(Arrays.asList(((Composite) control).getChildren()));
        }
        variant = (String) control.getData(RWT.CUSTOM_VARIANT);
        log.debug("      -> " + variant + " (" + control.getClass().getSimpleName() + ")");
    }
}

From source file:org.polymap.rhei.form.batik.BatikFilterContainer.java

@Override
protected void updateEnabled() {
    if (pageBody == null || pageBody.isDisposed()) {
        return;//from  w w  w . jav  a2 s  .  c  om
    }

    Deque<Control> deque = new LinkedList(Collections.singleton(pageBody));
    while (!deque.isEmpty()) {
        Control control = deque.pop();

        String variant = (String) control.getData(RWT.CUSTOM_VARIANT);
        log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")");

        // form fields
        if (variant == null || variant.equals(BatikFormContainer.CSS_FORMFIELD)
                || variant.equals(BatikFormContainer.CSS_FORMFIELD_DISABLED)
                || variant.equals(BaseFieldComposite.CUSTOM_VARIANT_VALUE)) {
            UIUtils.setVariant(control,
                    enabled ? BatikFormContainer.CSS_FORMFIELD : BatikFormContainer.CSS_FORMFIELD_DISABLED);
        }
        // form
        else if (variant.equals(BatikFormContainer.CSS_FORM)
                || variant.equals(BatikFormContainer.CSS_FORM_DISABLED)) {
            UIUtils.setVariant(control,
                    enabled ? BatikFormContainer.CSS_FORM : BatikFormContainer.CSS_FORM_DISABLED);
        }

        //            // labeler Label
        //            String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT );
        //            if (control instanceof Label
        //                    && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) {
        //                control.setFont( enabled 
        //                        ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT )
        //                        : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) );
        //
        //                if (!enabled) {
        //                    control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) );
        //                }
        //            }
        // Composite
        if (control instanceof Composite) {
            control.setEnabled(enabled);

            deque.addAll(Arrays.asList(((Composite) control).getChildren()));
        }
        variant = (String) control.getData(RWT.CUSTOM_VARIANT);
        log.debug("      -> " + variant + " (" + control.getClass().getSimpleName() + ")");
    }
}