Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.Bytecode#addSource()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.Bytecode#addSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteCodeSerializer.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
protected Bytecode readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
    final Bytecode result = new Bytecode();

    final int stepsLength = buffer.readInt();
    for (int i = 0; i < stepsLength; i++) {
        result.addStep(context.readValue(buffer, String.class, false), getInstructionArguments(buffer, context));
    }

    final int sourcesLength = buffer.readInt();
    for (int i = 0; i < sourcesLength; i++) {
        result.addSource(context.readValue(buffer, String.class, false), getInstructionArguments(buffer, context));
    }

    return result;
}
 
Example 2
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Bytecode bytecode = new Bytecode();

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        final String current = jsonParser.getCurrentName();
        if (current.equals(GraphSONTokens.SOURCE) || current.equals(GraphSONTokens.STEP)) {
            jsonParser.nextToken();

            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {

                // there should be a list now and the first item in the list is always string and is the step name
                // skip the start array
                jsonParser.nextToken();
                
                final String stepName = jsonParser.getText();

                // iterate through the rest of the list for arguments until it gets to the end
                final List<Object> arguments = new ArrayList<>();
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    // we don't know the types here, so let the deserializer figure that business out
                    arguments.add(deserializationContext.readValue(jsonParser, Object.class));
                }

                // if it's not a "source" then it must be a "step"
                if (current.equals(GraphSONTokens.SOURCE))
                    bytecode.addSource(stepName, arguments.toArray());
                else
                    bytecode.addStep(stepName, arguments.toArray());
            }
        }
    }
    return bytecode;
}
 
Example 3
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Bytecode bytecode = new Bytecode();

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        final String current = jsonParser.getCurrentName();
        if (current.equals(GraphSONTokens.SOURCE) || current.equals(GraphSONTokens.STEP)) {
            jsonParser.nextToken();

            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {

                // there should be a list now and the first item in the list is always string and is the step name
                // skip the start array
                jsonParser.nextToken();

                final String stepName = jsonParser.getText();

                // iterate through the rest of the list for arguments until it gets to the end
                final List<Object> arguments = new ArrayList<>();
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    // we don't know the types here, so let the deserializer figure that business out
                    arguments.add(deserializationContext.readValue(jsonParser, Object.class));
                }

                // if it's not a "source" then it must be a "step"
                if (current.equals(GraphSONTokens.SOURCE))
                    bytecode.addSource(stepName, arguments.toArray());
                else
                    bytecode.addStep(stepName, arguments.toArray());
            }
        }
    }
    return bytecode;
}