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);
}
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;
}
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;
}
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);
}
}
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");
}
}
Aggregations