Search in sources :

Example 1 with TokenBuffer

use of com.yahoo.document.json.TokenBuffer in project vespa by vespa-engine.

the class MapReader method createMapUpdate.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static ValueUpdate createMapUpdate(TokenBuffer buffer, DataType currentLevel, FieldValue keyParent, FieldValue topLevelKey) {
    TokenBuffer.Token element = buffer.prefetchScalar(UPDATE_ELEMENT);
    if (UPDATE_ELEMENT.equals(buffer.currentName())) {
        buffer.next();
    }
    FieldValue key = keyTypeForMapUpdate(element, currentLevel);
    if (keyParent != null) {
        ((CollectionFieldValue) keyParent).add(key);
    }
    // match will always have element, and either match or action
    if (!UPDATE_MATCH.equals(buffer.currentName())) {
        // we have reached an action...
        if (topLevelKey == null) {
            return ValueUpdate.createMap(key, readSingleUpdate(buffer, valueTypeForMapUpdate(currentLevel), buffer.currentName()));
        } else {
            return ValueUpdate.createMap(topLevelKey, readSingleUpdate(buffer, valueTypeForMapUpdate(currentLevel), buffer.currentName()));
        }
    } else {
        // next level of matching
        if (topLevelKey == null) {
            return createMapUpdate(buffer, valueTypeForMapUpdate(currentLevel), key, key);
        } else {
            return createMapUpdate(buffer, valueTypeForMapUpdate(currentLevel), key, topLevelKey);
        }
    }
}
Also used : TokenBuffer(com.yahoo.document.json.TokenBuffer) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Aggregations

CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 TokenBuffer (com.yahoo.document.json.TokenBuffer)1