Search in sources :

Example 91 with Stack

use of java.util.Stack in project geode by apache.

the class DataTypeJUnitTest method testStack.

@Test
public void testStack() throws IOException {
    Stack<Object> value = new Stack<Object>();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    DataSerializer.writeObject(value, out);
    byte[] bytes = baos.toByteArray();
    String type = DataType.getDataType(bytes);
    assertEquals("java.util.Stack", type);
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Stack(java.util.Stack) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 92 with Stack

use of java.util.Stack in project incubator-atlas by apache.

the class GraphHelper method getCompositeVertices.

/**
     * Get the GUIDs and vertices for all composite entities owned/contained by the specified root entity AtlasVertex.
     * The graph is traversed from the root entity through to the leaf nodes of the containment graph.
     *
     * @param entityVertex the root entity vertex
     * @return set of VertexInfo for all composite entities
     * @throws AtlasException
     */
public Set<VertexInfo> getCompositeVertices(AtlasVertex entityVertex) throws AtlasException {
    Set<VertexInfo> result = new HashSet<>();
    Stack<AtlasVertex> vertices = new Stack<>();
    vertices.push(entityVertex);
    while (vertices.size() > 0) {
        AtlasVertex vertex = vertices.pop();
        String typeName = GraphHelper.getTypeName(vertex);
        String guid = GraphHelper.getGuid(vertex);
        Id.EntityState state = GraphHelper.getState(vertex);
        if (state == Id.EntityState.DELETED) {
            //If the reference vertex is marked for deletion, skip it
            continue;
        }
        result.add(new VertexInfo(guid, vertex, typeName));
        ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
        for (AttributeInfo attributeInfo : classType.fieldMapping().fields.values()) {
            if (!attributeInfo.isComposite) {
                continue;
            }
            String edgeLabel = GraphHelper.getEdgeLabel(classType, attributeInfo);
            switch(attributeInfo.dataType().getTypeCategory()) {
                case CLASS:
                    AtlasEdge edge = getEdgeForLabel(vertex, edgeLabel);
                    if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                        AtlasVertex compositeVertex = edge.getInVertex();
                        vertices.push(compositeVertex);
                    }
                    break;
                case ARRAY:
                    IDataType elementType = ((DataTypes.ArrayType) attributeInfo.dataType()).getElemType();
                    DataTypes.TypeCategory elementTypeCategory = elementType.getTypeCategory();
                    if (elementTypeCategory != TypeCategory.CLASS) {
                        continue;
                    }
                    Iterator<AtlasEdge> edges = getOutGoingEdgesByLabel(vertex, edgeLabel);
                    if (edges != null) {
                        while (edges.hasNext()) {
                            edge = edges.next();
                            if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    DataTypes.MapType mapType = (DataTypes.MapType) attributeInfo.dataType();
                    DataTypes.TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    if (valueTypeCategory != TypeCategory.CLASS) {
                        continue;
                    }
                    String propertyName = GraphHelper.getQualifiedFieldName(classType, attributeInfo.name);
                    List<String> keys = vertex.getProperty(propertyName, List.class);
                    if (keys != null) {
                        for (String key : keys) {
                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
                            edge = getEdgeForLabel(vertex, mapEdgeLabel);
                            if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    return result;
}
Also used : TypeCategory(org.apache.atlas.typesystem.types.DataTypes.TypeCategory) ClassType(org.apache.atlas.typesystem.types.ClassType) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Stack(java.util.Stack) AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) Id(org.apache.atlas.typesystem.persistence.Id) HashSet(java.util.HashSet) DataTypes(org.apache.atlas.typesystem.types.DataTypes)

Example 93 with Stack

use of java.util.Stack in project incubator-atlas by apache.

the class DeleteHandlerV1 method getOwnedVertices.

/**
     * Get the GUIDs and vertices for all composite entities owned/contained by the specified root entity AtlasVertex.
     * The graph is traversed from the root entity through to the leaf nodes of the containment graph.
     *
     * @param entityVertex the root entity vertex
     * @return set of VertexInfo for all composite entities
     * @throws AtlasException
     */
public Set<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException {
    Set<GraphHelper.VertexInfo> result = new LinkedHashSet<>();
    Stack<AtlasVertex> vertices = new Stack<>();
    vertices.push(entityVertex);
    while (vertices.size() > 0) {
        AtlasVertex vertex = vertices.pop();
        AtlasEntity.Status state = AtlasGraphUtilsV1.getState(vertex);
        if (state == AtlasEntity.Status.DELETED) {
            //If the reference vertex is marked for deletion, skip it
            continue;
        }
        String typeName = GraphHelper.getTypeName(vertex);
        String guid = GraphHelper.getGuid(vertex);
        result.add(new GraphHelper.VertexInfo(guid, vertex, typeName));
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), typeName);
        }
        for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
            if (!attributeInfo.isOwnedRef()) {
                continue;
            }
            String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
            AtlasType attrType = attributeInfo.getAttributeType();
            switch(attrType.getTypeCategory()) {
                case OBJECT_ID_TYPE:
                    AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
                    if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                        AtlasVertex compositeVertex = edge.getInVertex();
                        vertices.push(compositeVertex);
                    }
                    break;
                case ARRAY:
                    AtlasArrayType arrType = (AtlasArrayType) attrType;
                    if (arrType.getElementType().getTypeCategory() != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(vertex, edgeLabel);
                    if (edges != null) {
                        while (edges.hasNext()) {
                            edge = edges.next();
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    AtlasMapType mapType = (AtlasMapType) attrType;
                    TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    if (valueTypeCategory != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
                    List<String> keys = vertex.getProperty(propertyName, List.class);
                    if (keys != null) {
                        for (String key : keys) {
                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
                            edge = graphHelper.getEdgeForLabel(vertex, mapEdgeLabel);
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) GraphHelper(org.apache.atlas.repository.graph.GraphHelper) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) Stack(java.util.Stack) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) TypeCategory(org.apache.atlas.model.TypeCategory) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 94 with Stack

use of java.util.Stack in project incubator-systemml by apache.

the class FunctionCallGraph method constructFunctionCallGraph.

private void constructFunctionCallGraph(DMLProgram prog) {
    if (!prog.hasFunctionStatementBlocks())
        //early abort if prog without functions
        return;
    try {
        Stack<String> fstack = new Stack<String>();
        HashSet<String> lfset = new HashSet<String>();
        _fGraph.put(MAIN_FUNCTION_KEY, new HashSet<String>());
        for (StatementBlock sblk : prog.getStatementBlocks()) rConstructFunctionCallGraph(MAIN_FUNCTION_KEY, sblk, fstack, lfset);
    } catch (HopsException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HopsException(org.apache.sysml.hops.HopsException) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 95 with Stack

use of java.util.Stack in project jackrabbit by apache.

the class JsonParser method parse.

/**
     *
     * @param reader The reader
     * @throws IOException If an error occurs.
     */
public void parse(Reader reader) throws IOException {
    //StringBuffer key = new StringBuffer();
    StringBuffer value = new StringBuffer();
    int state;
    Stack complexVStack = new Stack();
    int next = reader.read();
    if (next == '{') {
        handler.object();
        complexVStack.push(OBJECT);
        state = KEY_START;
        next = readIgnoreWhitespace(reader);
    } else {
        throw new IOException("JSON object must start with a '{'");
    }
    while (next != EOF) {
        switch(state) {
            case KEY_START:
                if (next == '"') {
                    String key = nextString(reader, '\"');
                    next = readIgnoreWhitespace(reader);
                    if (next == ':') {
                        handler.key(key);
                        state = VALUE_START;
                    } else {
                        throw new IOException("Key-Value pairs must be separated by ':'");
                    }
                    next = readIgnoreWhitespace(reader);
                } else if (next == '}') {
                    // empty object
                    state = VALUE;
                } else {
                    throw new IOException("Key must be in String format (double quotes)");
                }
                break;
            case VALUE_START:
                if (next == '[') {
                    handler.array();
                    complexVStack.push(ARRAY);
                    // status still value_start
                    next = readIgnoreWhitespace(reader);
                } else if (next == '{') {
                    handler.object();
                    complexVStack.push(OBJECT);
                    state = KEY_START;
                    next = readIgnoreWhitespace(reader);
                } else if (next == '\"') {
                    handler.value(nextString(reader, '\"'));
                    next = readIgnoreWhitespace(reader);
                    if (!(next == ',' || next == ']' || next == '}')) {
                        throw new IOException("Invalid json format");
                    }
                } else {
                    // start of boolean/long/double/null value
                    // will be notified as key-value pair
                    state = VALUE;
                }
                break;
            case VALUE:
                if (next == '"') {
                    throw new IOException("Invalid json format");
                } else if (next == ',') {
                    state = (complexVStack.peek() == OBJECT) ? KEY_START : VALUE_START;
                    value = resetValue(value);
                    next = readIgnoreWhitespace(reader);
                } else if (next == ']') {
                    if (complexVStack.pop() != ARRAY) {
                        throw new IOException("Invalid json format: Unexpected array termination.");
                    }
                    value = resetValue(value);
                    handler.endArray();
                    next = readIgnoreWhitespace(reader);
                    if (!(next == ',' || next == '}' || next == ']')) {
                        throw new IOException("Invalid json format");
                    }
                } else if (next == '}') {
                    if (complexVStack.pop() != OBJECT) {
                        throw new IOException("Invalid json format: Unexpected object termination.");
                    }
                    value = resetValue(value);
                    handler.endObject();
                    next = readIgnoreWhitespace(reader);
                    if (!(next == ',' || next == '}' || next == ']' || next == EOF)) {
                        throw new IOException("Invalid json format");
                    }
                } else {
                    // simple value
                    value.append((char) next);
                    next = reader.read();
                }
                break;
        }
    }
    // EOF reached -> minimal validation check
    if (value.length() != 0) {
        throw new IOException("Invalid json format");
    }
}
Also used : IOException(java.io.IOException) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7