use of com.amazon.tools.events.Event in project ion-java by amzn.
the class IonJavaCli method parseStruct.
private static IonStruct parseStruct(ContainerContext containerContext, CompareContext compareContext, int end, boolean isFirst) {
Event initEvent = isFirst ? compareContext.getEventStreamFirst().get(containerContext.getIndex()) : compareContext.getEventStreamSecond().get(containerContext.getIndex());
if (initEvent.getEventType() != EventType.CONTAINER_START || initEvent.getIonType() != IonType.STRUCT) {
return null;
}
IonStruct ionStruct = ION_SYSTEM.newEmptyStruct();
while (containerContext.increaseIndex() < end) {
Event event = isFirst ? compareContext.getEventStreamFirst().get(containerContext.getIndex()) : compareContext.getEventStreamSecond().get(containerContext.getIndex());
EventType eventType = event.getEventType();
if (eventType == EventType.CONTAINER_START) {
switch(event.getIonType()) {
case LIST:
ionStruct.add(event.getFieldName(), parseSequence(containerContext, compareContext, end, isFirst, ION_SYSTEM.newEmptyList()));
break;
case STRUCT:
ionStruct.add(event.getFieldName(), parseStruct(containerContext, compareContext, end, isFirst));
break;
case SEXP:
ionStruct.add(event.getFieldName(), parseSequence(containerContext, compareContext, end, isFirst, ION_SYSTEM.newEmptySexp()));
break;
}
} else if (eventType == EventType.CONTAINER_END) {
break;
} else if (eventType == EventType.STREAM_END) {
throw new IonException("Invalid struct: eventStream ends without CONTAINER_END");
} else {
IonValue cloneValue = event.getValue().clone();
cloneValue.setTypeAnnotationSymbols(event.getAnnotations());
ionStruct.add(event.getFieldName(), cloneValue);
}
}
return ionStruct;
}
Aggregations