Example usage for java.util Stack push

List of usage examples for java.util Stack push

Introduction

In this page you can find the example usage for java.util Stack push.

Prototype

public E push(E item) 

Source Link

Document

Pushes an item onto the top of this stack.

Usage

From source file:com.datatorrent.stram.plan.logical.LogicalPlan.java

public void findInvalidDelays(OperatorMeta om, List<List<String>> invalidDelays, Stack<OperatorMeta> stack) {
    stack.push(om);

    // depth first successors traversal
    boolean isDelayOperator = om.getOperator() instanceof Operator.DelayOperator;
    if (isDelayOperator) {
        if (om.getValue(OperatorContext.APPLICATION_WINDOW_COUNT) != 1) {
            LOG.debug("detected DelayOperator having APPLICATION_WINDOW_COUNT not equal to 1");
            invalidDelays.add(Collections.singletonList(om.getName()));
        }/*from ww w.  ja  v a2  s.co  m*/
    }

    for (StreamMeta downStream : om.outputStreams.values()) {
        for (InputPortMeta sink : downStream.sinks) {
            OperatorMeta successor = sink.getOperatorWrapper();
            if (isDelayOperator) {
                sink.attributes.put(IS_CONNECTED_TO_DELAY_OPERATOR, true);
                // Check whether all downstream operators are already visited in the path
                if (successor != null && !stack.contains(successor)) {
                    LOG.debug(
                            "detected DelayOperator does not immediately output to a visited operator {}.{}->{}.{}",
                            om.getName(), downStream.getSource().getPortName(), successor.getName(),
                            sink.getPortName());
                    invalidDelays.add(Arrays.asList(om.getName(), successor.getName()));
                }
            } else {
                findInvalidDelays(successor, invalidDelays, stack);
            }
        }
    }
    stack.pop();
}

From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java

private DefaultHandler getNewDefaultHandler(final Map<String, List<String>> headers,
        final Stack<Map<String, List<Object>>> aggregateStack) {
    return new DefaultHandler() {
        @Override/*from   w  w  w  .ja v  a 2  s  .  c  o  m*/
        public void onHeader(String name, String value) {
            LOG.debug(name + ":" + value);
            List<String> list = headers.get(name);
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(name, list);
            }
            list.add(value);
        }

        @Override
        public void onElement(String name, String value) {
            LOG.debug("onElement " + aggregateStack.size());
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + name + "=" + value);

            List<Object> list = aggregateStack.peek().get(name);
            if (list == null) {
                list = new ArrayList<Object>();
                aggregateStack.peek().put(name, list);
            }
            list.add(value);
        }

        @Override
        public void startAggregate(String aggregateName) {
            LOG.debug("startAggregate " + aggregateName + " " + aggregateStack.size());
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + aggregateName + " {");

            TreeMap<String, List<Object>> aggregate = new TreeMap<String, List<Object>>();
            List<Object> list = aggregateStack.peek().get(aggregateName);
            if (list == null) {
                list = new ArrayList<Object>();
                aggregateStack.peek().put(aggregateName, list);
            }
            list.add(aggregate);
            aggregateStack.push(aggregate);
        }

        @Override
        public void endAggregate(String aggregateName) {
            LOG.debug("endAggregate " + aggregateName + " " + aggregateStack.size());
            aggregateStack.pop();

            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + "}");
        }
    };
}

From source file:org.apache.pulsar.sql.presto.PulsarMetadata.java

@VisibleForTesting
static List<PulsarColumnMetadata> getColumns(String fieldName, Schema fieldSchema, Set<String> fieldTypes,
        Stack<String> fieldNames, Stack<Integer> positionIndices) {

    List<PulsarColumnMetadata> columnMetadataList = new LinkedList<>();

    if (isPrimitiveType(fieldSchema.getType())) {
        columnMetadataList.add(new PulsarColumnMetadata(fieldName,
                convertType(fieldSchema.getType(), fieldSchema.getLogicalType()), null, null, false, false,
                fieldNames.toArray(new String[fieldNames.size()]),
                positionIndices.toArray(new Integer[positionIndices.size()])));
    } else if (fieldSchema.getType() == Schema.Type.UNION) {
        boolean canBeNull = false;
        for (Schema type : fieldSchema.getTypes()) {
            if (isPrimitiveType(type.getType())) {
                PulsarColumnMetadata columnMetadata;
                if (type.getType() != Schema.Type.NULL) {
                    if (!canBeNull) {
                        columnMetadata = new PulsarColumnMetadata(fieldName,
                                convertType(type.getType(), type.getLogicalType()), null, null, false, false,
                                fieldNames.toArray(new String[fieldNames.size()]),
                                positionIndices.toArray(new Integer[positionIndices.size()]));
                    } else {
                        columnMetadata = new PulsarColumnMetadata(fieldName,
                                convertType(type.getType(), type.getLogicalType()), "field can be null", null,
                                false, false, fieldNames.toArray(new String[fieldNames.size()]),
                                positionIndices.toArray(new Integer[positionIndices.size()]));
                    }//from   w w  w .j av  a2  s . c  o m
                    columnMetadataList.add(columnMetadata);
                } else {
                    canBeNull = true;
                }
            } else {
                List<PulsarColumnMetadata> columns = getColumns(fieldName, type, fieldTypes, fieldNames,
                        positionIndices);
                columnMetadataList.addAll(columns);

            }
        }
    } else if (fieldSchema.getType() == Schema.Type.RECORD) {
        // check if we have seen this type before to prevent cyclic class definitions.
        if (!fieldTypes.contains(fieldSchema.getFullName())) {
            // add to types seen so far in traversal
            fieldTypes.add(fieldSchema.getFullName());
            List<Schema.Field> fields = fieldSchema.getFields();
            for (int i = 0; i < fields.size(); i++) {
                Schema.Field field = fields.get(i);
                fieldNames.push(field.name());
                positionIndices.push(i);
                List<PulsarColumnMetadata> columns;
                if (fieldName == null) {
                    columns = getColumns(field.name(), field.schema(), fieldTypes, fieldNames, positionIndices);
                } else {
                    columns = getColumns(String.format("%s.%s", fieldName, field.name()), field.schema(),
                            fieldTypes, fieldNames, positionIndices);

                }
                positionIndices.pop();
                fieldNames.pop();
                columnMetadataList.addAll(columns);
            }
            fieldTypes.remove(fieldSchema.getFullName());
        } else {
            log.debug("Already seen type: %s", fieldSchema.getFullName());
        }
    } else if (fieldSchema.getType() == Schema.Type.ARRAY) {

    } else if (fieldSchema.getType() == Schema.Type.MAP) {

    } else if (fieldSchema.getType() == Schema.Type.ENUM) {
        PulsarColumnMetadata columnMetadata = new PulsarColumnMetadata(fieldName,
                convertType(fieldSchema.getType(), fieldSchema.getLogicalType()), null, null, false, false,
                fieldNames.toArray(new String[fieldNames.size()]),
                positionIndices.toArray(new Integer[positionIndices.size()]));
        columnMetadataList.add(columnMetadata);

    } else if (fieldSchema.getType() == Schema.Type.FIXED) {

    } else {
        log.error("Unknown column type: {}", fieldSchema);
    }
    return columnMetadataList;
}

From source file:com.joliciel.jochre.graphics.ShapeImpl.java

@Override
public TreeSet<VerticalLineSegment> getVerticalLineSegments() {
    if (lines == null) {
        WritableImageGrid mirror = this.graphicsService.getEmptyMirror(this);

        int[] startingPoint = this.getStartingPoint();
        int startX = startingPoint[0];
        int startY = startingPoint[1];

        // let's imagine
        // 0 X 0 0 x x
        // x x x 0 0 x
        // 0 0 x x x x

        //as we build the shape, we keep track in memory of all of the vertical line segments that we find
        //and which vertical line segments touch them to the right and left
        //a segment can have more than one left segment (if they're broken by a white space)
        Stack<VerticalLineSegment> lineStack = new Stack<VerticalLineSegment>();
        lines = new TreeSet<VerticalLineSegment>();
        VerticalLineSegment firstLine = new VerticalLineSegment(startX, startY);

        lineStack.push(firstLine);

        while (!lineStack.isEmpty()) {
            VerticalLineSegment line = lineStack.pop();
            // Add this line's pixels to the mirror so that we don't touch it again.
            for (int rely = line.yTop; rely <= line.yBottom; rely++)
                mirror.setPixel(line.x, rely, 1);

            // extend the vertical line segment up and down from this point
            for (int rely = line.yTop - 1; rely >= 0; rely--) {
                if (this.isPixelBlack(line.x, rely, this.getJochreImage().getSeparationThreshold())) {
                    mirror.setPixel(line.x, rely, 1);
                    line.yTop = rely;/*from   ww  w. jav  a2 s.  c  om*/
                } else {
                    break;
                }
            }
            for (int rely = line.yBottom + 1; rely < this.getHeight(); rely++) {
                if (this.isPixelBlack(line.x, rely, this.getJochreImage().getSeparationThreshold())) {
                    mirror.setPixel(line.x, rely, 1);
                    line.yBottom = rely;
                } else {
                    break;
                }
            }

            //LOG.debug("Adding line x = " + line.x + ", top = " + line.yTop + ", bottom = " + line.yBottom);
            lines.add(line);

            // find any points to the left of this segment
            int relx = line.x - 1;
            VerticalLineSegment leftLine = null;
            for (int rely = line.yTop - 1; rely <= line.yBottom + 1; rely++) {
                if (this.isPixelBlack(relx, rely, this.getJochreImage().getSeparationThreshold())) {
                    if (leftLine == null) {
                        leftLine = new VerticalLineSegment(relx, rely);
                    } else {
                        leftLine.yBottom = rely;
                    }
                } else {
                    if (leftLine != null) {
                        if (mirror.getPixel(relx, leftLine.yTop) > 0) {
                            // if we already found this line before - let's find it again.
                            for (VerticalLineSegment lineSegment : lines) {
                                if (lineSegment.x == relx) {
                                    if (lineSegment.yTop <= leftLine.yTop
                                            && leftLine.yTop <= lineSegment.yBottom) {
                                        leftLine = lineSegment;
                                        break;
                                    }
                                }
                            }
                        } else if (lineStack.contains(leftLine)) {
                            leftLine = lineStack.get(lineStack.indexOf(leftLine));
                        } else {
                            lineStack.push(leftLine);
                        }
                        line.leftSegments.add(leftLine);
                        leftLine = null;
                    }
                }
            } // next rely

            // add the last line
            if (leftLine != null) {
                if (mirror.getPixel(relx, leftLine.yTop) > 0) {
                    // if we already found this line before - let's find it again.
                    for (VerticalLineSegment lineSegment : lines) {
                        if (lineSegment.x == relx) {
                            if (lineSegment.yTop <= leftLine.yTop && leftLine.yTop <= lineSegment.yBottom) {
                                leftLine = lineSegment;
                                break;
                            }
                        }
                    }
                } else if (lineStack.contains(leftLine)) {
                    leftLine = lineStack.get(lineStack.indexOf(leftLine));
                } else {
                    lineStack.push(leftLine);
                }
                line.leftSegments.add(leftLine);
            }

            // find any points to the right of this segment
            relx = line.x + 1;
            VerticalLineSegment rightLine = null;
            for (int rely = line.yTop - 1; rely <= line.yBottom + 1; rely++) {
                if (this.isPixelBlack(relx, rely, this.getJochreImage().getSeparationThreshold())) {
                    if (rightLine == null) {
                        rightLine = new VerticalLineSegment(relx, rely);
                    } else {
                        rightLine.yBottom = rely;
                    }
                } else {
                    if (rightLine != null) {
                        if (mirror.getPixel(relx, rightLine.yTop) > 0) {
                            // if we already found this line before - let's find it again.
                            for (VerticalLineSegment lineSegment : lines) {
                                if (lineSegment.x == relx) {
                                    if (lineSegment.yTop <= rightLine.yTop
                                            && rightLine.yTop <= lineSegment.yBottom) {
                                        rightLine = lineSegment;
                                        break;
                                    }
                                }
                            }
                        } else if (lineStack.contains(rightLine)) {
                            rightLine = lineStack.get(lineStack.indexOf(rightLine));
                        } else {
                            lineStack.push(rightLine);
                        }
                        line.rightSegments.add(rightLine);
                        rightLine = null;
                    }
                }
            } // next rely

            // add the last line
            if (rightLine != null) {
                if (mirror.getPixel(relx, rightLine.yTop) > 0) {
                    // if we already found this line before - let's find it again.
                    for (VerticalLineSegment lineSegment : lines) {
                        if (lineSegment.x == relx) {
                            if (lineSegment.yTop <= rightLine.yTop && rightLine.yTop <= lineSegment.yBottom) {
                                rightLine = lineSegment;
                                break;
                            }
                        }
                    }
                } else if (lineStack.contains(rightLine)) {
                    rightLine = lineStack.get(lineStack.indexOf(rightLine));
                } else {
                    lineStack.push(rightLine);
                }
                line.rightSegments.add(rightLine);
            }
        } // next line on stack
        LOG.debug("Found " + lines.size() + " lines");
    }
    return lines;
}

From source file:com.square.core.service.implementations.ActionServiceImplementation.java

@Override
public List<Stack<ActionSyntheseDto>> recupererActionsSynthese(CritereActionSyntheseDto critere) {
    // Vrifications
    if (critere == null) {
        throw new BusinessException(messageSourceUtil.get(ActionKeyUtil.MESSAGE_ERREUR_ACTION_DTO_NULL));
    }/*w  w w  .j  a  v a  2s. com*/
    if (critere.getIdPersonne() == null) {
        throw new BusinessException(messageSourceUtil.get(ActionKeyUtil.MESSAGE_ERREUR_ACTION_IDPERSONNE_NULL));
    }
    if (personneDao.rechercherPersonneParId(critere.getIdPersonne()) == null) {
        throw new BusinessException(
                messageSourceUtil.get(ActionKeyUtil.MESSAGE_ERREUR_ACTION_IDPERSONNE_INEXISTANT));
    }
    // Vrification sur l'opportunite
    if (critere.getIdOpportunite() != null
            && opportuniteDao.rechercherOpportuniteParId(critere.getIdOpportunite()) == null) {
        throw new BusinessException(
                messageSourceUtil.get(ActionKeyUtil.MESSAGE_ERREUR_ACTION_OPPORTUNITE_INEXISTANTE));
    }

    // Rcupration des actions sources
    final List<Action> actionsSources = actionDao.rechercherActionsSources(critere);

    // Liste rsultat
    final List<Stack<ActionSyntheseDto>> listeActions = new ArrayList<Stack<ActionSyntheseDto>>();

    // Parcours des actions sources pour recherche les actions lies
    for (Action actionSource : actionsSources) {
        // Cration d'une nouvelle pile
        final Stack<ActionSyntheseDto> stack = new Stack<ActionSyntheseDto>();
        // Ajout de l'action source dans la pile
        final ActionSyntheseDto actionSyntheseDto = mapperDozerBean.map(actionSource, ActionSyntheseDto.class);
        actionSyntheseDto.setNiveau(0);
        actionSyntheseDto.setAttribueA(genererLibelleAttribueA(actionSource.getActionAttribution()));
        stack.push(actionSyntheseDto);
        // Recherche des actions lies  l'action source
        rechercherActionsLiees(stack, actionSource.getId(), actionSyntheseDto.getNiveau(),
                critere.getIdOpportunite(), critere.getFiltrerDateCreation());
        // Enregistrement de la pile
        listeActions.add(stack);
    }

    return listeActions;
}

From source file:aula1.Aula1.java

public static String conversor(String entrada, String info) throws Exception {
    Pilha<String> input = new Pilha<>();
    Pilha<String> simbolos = new Pilha<>();
    Stack<Op> operadores = new Stack<>();
    Pilha<String> saida = new Pilha<>();
    String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" };

    for (int i = 0; i < entrada.length(); i++) {
        String s = "";
        try {// w w  w  .ja  va 2s  . c o  m
            if (Character.isDigit(entrada.charAt(i))) {
                s = String.valueOf(entrada.charAt(i));
                while (Character.isDigit(entrada.charAt(i + 1))) {
                    s += String.valueOf(entrada.charAt(i + 1));
                    i++;
                }
            } else {
                if (entrada.charAt(i) == 's' && entrada.contains("sen")) {
                    int ind = entrada.indexOf("sen");
                    String ent = entrada.substring(ind);
                    int ini = ent.indexOf("sen(") + 4;
                    int fim = ent.indexOf(")/");
                    CharSequence x = ent.subSequence(ini, fim);
                    if (entrada.contains("sen(" + x + ")/" + x)) {
                        entrada = entrada.replace("sen(" + x + ")/" + x, "1");
                        s = "1";
                    } else {
                        ind += 2;
                        i = -1;
                        entrada = entrada.substring(ind + 1);
                        if (entrada.charAt(0) != '(')
                            throw new Exception("Falta de '(' aps sen");
                        s = "sen";
                    }
                } else
                    s = String.valueOf(entrada.charAt(i));
            }
            simbolos.push(s);
            input.push(s);
        } catch (IndexOutOfBoundsException ex) {
            s = String.valueOf(entrada.charAt(i));
            simbolos.push(s);
            input.push(s);
        }
    }
    while (!simbolos.isEMpty()) {
        String simbolo = simbolos.pop();

        if (Character.isDigit(simbolo.charAt(0)) || simbolo.charAt(0) == 'x')
            saida.push(simbolo);
        else if (Arrays.asList(operadoresSuportados).contains(simbolo)) {
            Op operador = new Op(simbolo);
            Op topOperador;
            try {
                topOperador = operadores.peek();
            } catch (EmptyStackException e) {
                topOperador = null;
            }
            if (simbolo.equals(")")) {
                while (topOperador != null && !topOperador.op().equals("(")) {
                    saida.push(topOperador.op());
                    operadores.pop();
                    topOperador = operadores.peek();
                }
                operadores.pop();
            } else if (simbolo.equals("(")) {
                operadores.push(operador);
            } else {
                while (topOperador != null && topOperador.Precedencia() > operador.Precedencia()) {
                    saida.push(topOperador.op());
                    operadores.pop();
                    try {
                        topOperador = operadores.peek();
                    } catch (EmptyStackException e) {
                        topOperador = null;
                    }
                }
                operadores.push(operador);
            }
        }
    }
    while (!operadores.isEmpty()) {
        Op operador = operadores.pop();
        saida.push(operador.op());
    }
    String resultado = "";
    for (String s : saida) {
        System.out.println("saida: " + s);
        resultado += s + " ";
    }
    resultado = calculaPolonesaINversa(resultado, info);
    return resultado;

}

From source file:fi.ni.IFC_ClassModel.java

/**
 * Parse_ if c_ line statement.//from   www  .java 2s. c om
 * 
 * @param line
 *            the line
 */
private void parse_IFC_LineStatement(String line) {
    IFC_X3_VO ifcvo = new IFC_X3_VO();
    int state = 0;
    StringBuffer sb = new StringBuffer();
    int cl_count = 0;
    LinkedList<Object> current = ifcvo.getList();
    Stack<LinkedList<Object>> list_stack = new Stack<LinkedList<Object>>();
    for (int i = 0; i < line.length(); i++) {
        char ch = line.charAt(i);
        switch (state) {
        case 0:
            if (ch == '=') {
                ifcvo.setLine_num(toLong(sb.toString()));
                sb.setLength(0);
                state++;
                continue;
            } else if (Character.isDigit(ch))
                sb.append(ch);
            break;
        case 1: // (
            if (ch == '(') {
                ifcvo.setName(sb.toString());
                sb.setLength(0);
                state++;
                continue;
            } else if (ch == ';') {
                ifcvo.setName(sb.toString());
                sb.setLength(0);
                state = Integer.MAX_VALUE;
            } else if (!Character.isWhitespace(ch))
                sb.append(ch);
            break;
        case 2: // (... line started and doing (...
            if (ch == '\'') {
                state++;
            }
            if (ch == '(') {
                list_stack.push(current);
                LinkedList<Object> tmp = new LinkedList<Object>();
                if (sb.toString().trim().length() > 0)
                    current.add(sb.toString().trim());
                sb.setLength(0);
                current.add(tmp); // listaan listn lista
                current = tmp;
                cl_count++;
                // sb.append(ch);
            } else if (ch == ')') {
                if (cl_count == 0) {
                    if (sb.toString().trim().length() > 0)
                        current.add(sb.toString().trim());
                    sb.setLength(0);
                    state = Integer.MAX_VALUE; // line is done
                    continue;
                } else {
                    if (sb.toString().trim().length() > 0)
                        current.add(sb.toString().trim());
                    sb.setLength(0);
                    cl_count--;
                    current = list_stack.pop();
                }
            } else if (ch == ',') {
                if (sb.toString().trim().length() > 0)
                    current.add(sb.toString().trim());
                current.add(Character.valueOf(ch));

                sb.setLength(0);
            } else {
                sb.append(ch);

            }
            break;
        case 3: // (...
            if (ch == '\'') {
                state--;
            } else {
                sb.append(ch);

            }
            break;
        default:
            // Do nothing
        }
    }
    linemap.put(ifcvo.line_num, ifcvo);
}

From source file:cn.teamlab.wg.framework.struts2.breadcrumb.BreadCrumbInterceptor.java

protected void beforeInvocation(ActionInvocation invocation) throws Exception {

    if (!enable) {
        invocation.getInvocationContext().getSession().remove(CRUMB_KEY);
        return;/*  w ww. j  a  v a2 s.co  m*/
    }

    BreadCrumb annotation = processAnnotation(invocation);

    if (annotation != null) {

        if (annotation.isEnable() == false) {
            invocation.getInvocationContext().getSession().remove(CRUMB_KEY);
            return;
        }

        BreadCrumbTrail trail = getBreadCrumbTrail(invocation);

        Stack<Crumb> crumbs = trail.getCrumbs();
        crumbs.clear();

        List<Crumb> crumbsList = new ArrayList<Crumb>();

        ActionInvocation inv = invocation;
        Crumb current = makeCrumb(inv, annotation.name(), annotation.key());
        crumbsList.add(current);

        while (!"".equals(annotation.parent())) {

            String namespace = annotation.parentNamespace();

            if (StringUtils.isBlank(namespace)) {
                namespace = invocation.getProxy().getNamespace();
            }

            ActionConfig parentConfig = configuration.getRuntimeConfiguration().getActionConfig(namespace,
                    annotation.parent());

            String actionName = parentConfig.getName();
            String methodName = parentConfig.getMethodName();

            MockActionInvocation mockInv = new MockActionInvocation();
            MockActionProxy mockProxy = new MockActionProxy();

            Object action = objectFactory.buildAction(actionName, namespace, parentConfig,
                    invocation.getInvocationContext().getContextMap());

            mockProxy.setAction(action);
            mockProxy.setActionName(actionName);
            mockProxy.setMethod(methodName);
            mockProxy.setNamespace(namespace);
            mockProxy.setInvocation(mockInv);

            mockInv.setAction(action);
            mockInv.setProxy(mockProxy);
            mockInv.setInvocationContext(invocation.getInvocationContext());
            inv = mockInv;

            // inv = proxy.getInvocation();
            annotation = processAnnotation(inv);

            current = makeCrumb(inv, annotation.name(), annotation.key());
            crumbsList.add(current);

        }

        for (int i = crumbsList.size() - 1; i >= 0; i--) {
            crumbs.push(crumbsList.get(i));
        }
    }

}

From source file:org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.java

static void checkForCircularNodeAutoCreation(EffectiveNodeType childNodeENT, Stack<Name> definingParentNTs,
        EffectiveNodeTypeCache anEntCache, Map<Name, QNodeTypeDefinition> ntDefCache)
        throws InvalidNodeTypeDefException {
    // check for circularity through default node types of auto-created child nodes
    // (node type 'a' defines auto-created child node with default node type 'a')
    Name[] childNodeNTs = childNodeENT.getAllNodeTypes();
    for (Name nt : childNodeNTs) {
        int pos = definingParentNTs.lastIndexOf(nt);
        if (pos >= 0) {
            StringBuilder buf = new StringBuilder();
            for (int j = 0; j < definingParentNTs.size(); j++) {
                if (j == pos) {
                    buf.append("--> ");
                }//from w w w . ja  va  2 s .  c  o m
                buf.append("node type ");
                buf.append(definingParentNTs.get(j));
                buf.append(" defines auto-created child node with default ");
            }
            buf.append("--> ");
            buf.append("node type ");
            buf.append(nt);
            throw new InvalidNodeTypeDefException("circular node auto-creation detected: " + buf.toString());
        }
    }

    QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateNodeDefs();
    for (QNodeDefinition nodeDef : nodeDefs) {
        Name dnt = nodeDef.getDefaultPrimaryType();
        Name definingNT = nodeDef.getDeclaringNodeType();
        try {
            if (dnt != null) {
                // check recursively
                definingParentNTs.push(definingNT);
                checkForCircularNodeAutoCreation(getEffectiveNodeType(dnt, anEntCache, ntDefCache),
                        definingParentNTs, anEntCache, ntDefCache);
                definingParentNTs.pop();
            }
        } catch (NoSuchNodeTypeException nsnte) {
            String msg = definingNT + " defines invalid default node type for child node " + nodeDef.getName();
            log.debug(msg);
            throw new InvalidNodeTypeDefException(msg, nsnte);
        }
    }
}

From source file:org.apache.tajo.engine.planner.rewrite.ProjectionPushDownRule.java

public LogicalNode visitJoin(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node,
        Stack<LogicalNode> stack) throws PlanningException {
    Context newContext = new Context(context);

    String joinQualReference = null;
    if (node.hasJoinQual()) {
        for (EvalNode eachQual : AlgebraicUtil.toConjunctiveNormalFormArray(node.getJoinQual())) {
            if (eachQual instanceof BinaryEval) {
                BinaryEval binaryQual = (BinaryEval) eachQual;

                for (int i = 0; i < 2; i++) {
                    EvalNode term = binaryQual.getChild(i);
                    pushDownIfComplexTermInJoinCondition(newContext, eachQual, term);
                }//from   ww w  . j av  a  2 s .c om
            }
        }

        joinQualReference = newContext.addExpr(node.getJoinQual());
        newContext.addNecessaryReferences(node.getJoinQual());
    }

    String[] referenceNames = null;
    if (node.hasTargets()) {
        referenceNames = new String[node.getTargets().length];
        int i = 0;
        for (Iterator<Target> it = getFilteredTarget(node.getTargets(), context.requiredSet); it.hasNext();) {
            Target target = it.next();
            referenceNames[i++] = newContext.addExpr(target);
        }
    }

    stack.push(node);
    LogicalNode left = visit(newContext, plan, block, node.getLeftChild(), stack);
    LogicalNode right = visit(newContext, plan, block, node.getRightChild(), stack);
    stack.pop();

    Schema merged = SchemaUtil.merge(left.getOutSchema(), right.getOutSchema());

    node.setInSchema(merged);

    if (node.hasJoinQual()) {
        Target target = context.targetListMgr.getTarget(joinQualReference);
        if (newContext.targetListMgr.isEvaluated(joinQualReference)) {
            throw new PlanningException(
                    "Join condition must be evaluated in the proper Join Node: " + joinQualReference);
        } else {
            node.setJoinQual(target.getEvalTree());
            newContext.targetListMgr.markAsEvaluated(target);
        }
    }

    LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet();
    for (Iterator<String> it = getFilteredReferences(context.targetListMgr.getNames(), context.requiredSet); it
            .hasNext();) {
        String referenceName = it.next();
        Target target = context.targetListMgr.getTarget(referenceName);

        if (context.targetListMgr.isEvaluated(referenceName)) {
            Target fieldReference = new Target(new FieldEval(target.getNamedColumn()));
            if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, fieldReference.getEvalTree(), node,
                    stack.peek().getType() != NodeType.JOIN)) {
                projectedTargets.add(fieldReference);
            }
        } else if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, target.getEvalTree(), node,
                stack.peek().getType() != NodeType.JOIN)) {
            projectedTargets.add(target);
            context.targetListMgr.markAsEvaluated(target);
        }
    }

    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
    LogicalPlanner.verifyProjectedFields(block, node);
    return node;
}