Search in sources :

Example 1 with ValueFactory

use of com.amazon.ion.ValueFactory in project ion-java by amzn.

the class SymbolTableStructCache method addSymbol.

/**
 * Adds a new symbol table with the given symbol ID to the IonStruct's 'symbols' list.
 * @param symbolName can be null when there's a gap in the local symbols list.
 * @param sid the symbol ID to assign to the new symbol.
 */
void addSymbol(String symbolName, int sid) {
    assert sid >= firstLocalSid;
    ValueFactory sys = image.getSystem();
    IonValue syms = image.get(SYMBOLS);
    // the symbols field if necessary.
    while (syms != null && syms.getType() != IonType.LIST) {
        image.remove(syms);
        syms = image.get(SYMBOLS);
    }
    if (syms == null) {
        syms = sys.newEmptyList();
        image.put(SYMBOLS, syms);
    }
    int thisOffset = sid - firstLocalSid;
    IonValue name = sys.newString(symbolName);
    ((IonList) syms).add(thisOffset, name);
}
Also used : IonValue(com.amazon.ion.IonValue) IonList(com.amazon.ion.IonList) ValueFactory(com.amazon.ion.ValueFactory)

Aggregations

IonList (com.amazon.ion.IonList)1 IonValue (com.amazon.ion.IonValue)1 ValueFactory (com.amazon.ion.ValueFactory)1