use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonWriterTestCase method testWritingAnnotations.
@Test
public void testWritingAnnotations() throws Exception {
iw = makeWriter();
IonDatagram expected = system().newDatagram();
iw.addTypeAnnotation("a");
iw.writeNull();
IonValue v = expected.add().newNull();
v.addTypeAnnotation("a");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("c");
iw.writeNull();
v = expected.add().newNull();
v.addTypeAnnotation("b");
v.addTypeAnnotation("c");
iw.addTypeAnnotation("b");
iw.addTypeAnnotation("b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.setTypeAnnotations("b", "b");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("b", "b");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations("c", "d");
iw.writeNull();
v = expected.add().newNull();
v.setTypeAnnotations("c", "d");
iw.addTypeAnnotation("b");
iw.setTypeAnnotations(new String[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations((String[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotations();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols(new SymbolToken[0]);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols((SymbolToken[]) null);
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
iw.addTypeAnnotation("b");
iw.setTypeAnnotationSymbols();
iw.writeNull();
v = expected.add().newNull();
v.clearTypeAnnotations();
assertEquals(expected, reload());
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTableTest method testInternUnknownText.
@Test
public void testInternUnknownText() {
SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC, ST_FRED_V2, ST_GINGER_V1);
String D = "d";
checkUnknownSymbol(D, st);
SymbolToken tok = st.intern(D);
assertSame(D, tok.getText());
assertEquals(st.getImportedMaxId() + 4, tok.getSid());
// Force a new instance
tok = st.intern(new String(D));
assertSame(D, tok.getText());
assertEquals(st.getImportedMaxId() + 4, tok.getSid());
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTableTest method testFindSymbolToken.
// -------------------------------------------------------------------------
// find()
public void testFindSymbolToken(SymbolTable st) {
// Existing symbol from imports
String fredSym = ST_FRED_V2.findKnownSymbol(3);
SymbolToken tok = st.find(new String(fredSym));
assertSame(fredSym, tok.getText());
assertSame(st.getSystemSymbolTable().getMaxId() + 3, tok.getSid());
String gingerSym = ST_GINGER_V1.findKnownSymbol(1);
tok = st.find(new String(gingerSym));
assertSame(gingerSym, tok.getText());
assertSame(st.getSystemSymbolTable().getMaxId() + ST_FRED_V2.getMaxId() + 1, tok.getSid());
// Existing local symbol
tok = st.find(OTHER_A);
assertSame(A, tok.getText());
assertEquals(st.getImportedMaxId() + 1, tok.getSid());
// Non-existing symbol
assertEquals(null, st.find("not there"));
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTableTest method internKnownText.
// -------------------------------------------------------------------------
// intern()
public void internKnownText(SymbolTable st) {
// Existing symbol from imports
String fredSym = ST_FRED_V2.findKnownSymbol(3);
SymbolToken tok = st.intern(new String(fredSym));
assertSame(fredSym, tok.getText());
assertSame(st.getSystemSymbolTable().getMaxId() + 3, tok.getSid());
String gingerSym = ST_GINGER_V1.findKnownSymbol(1);
tok = st.intern(new String(gingerSym));
assertSame(gingerSym, tok.getText());
assertSame(st.getSystemSymbolTable().getMaxId() + ST_FRED_V2.getMaxId() + 1, tok.getSid());
// Existing local symbol
tok = st.intern(OTHER_A);
assertSame(A, tok.getText());
assertEquals(st.getImportedMaxId() + 1, tok.getSid());
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonSystemLite method load_value_helper.
private IonValueLite load_value_helper(IonReader reader, boolean isTopLevel) {
boolean symbol_is_present = false;
IonType t = reader.getType();
if (t == null) {
return null;
}
IonValueLite v;
if (reader.isNullValue()) {
v = newNull(t);
} else {
switch(t) {
case BOOL:
v = newBool(reader.booleanValue());
break;
case INT:
// TODO amzn/ion-java/issues/9 Inefficient since we can't determine the size
// of the integer in order to avoid making BigIntegers.
v = newInt(reader.bigIntegerValue());
break;
case FLOAT:
v = newFloat(reader.doubleValue());
break;
case DECIMAL:
v = newDecimal(reader.decimalValue());
break;
case TIMESTAMP:
v = newTimestamp(reader.timestampValue());
break;
case SYMBOL:
v = newSymbol(reader.symbolValue());
symbol_is_present = true;
break;
case STRING:
v = newString(reader.stringValue());
break;
case CLOB:
v = newClob(reader.newBytes());
break;
case BLOB:
v = newBlob(reader.newBytes());
break;
case LIST:
v = newEmptyList();
break;
case SEXP:
v = newEmptySexp();
break;
case STRUCT:
v = newEmptyStruct();
break;
default:
throw new IonException("unexpected type encountered reading value: " + t.toString());
}
}
// Forget any incoming SIDs on field names.
if (!isTopLevel && reader.isInStruct()) {
SymbolToken token = reader.getFieldNameSymbol();
String text = token.getText();
if (text != null && token.getSid() != UNKNOWN_SYMBOL_ID) {
token = newSymbolToken(text, UNKNOWN_SYMBOL_ID);
}
v.setFieldNameSymbol(token);
symbol_is_present = true;
}
// Forget any incoming SIDs on annotations.
// This is a fresh array so we can modify it:
SymbolToken[] annotations = reader.getTypeAnnotationSymbols();
if (annotations.length != 0) {
for (int i = 0; i < annotations.length; i++) {
SymbolToken token = annotations[i];
String text = token.getText();
if (text != null && token.getSid() != UNKNOWN_SYMBOL_ID) {
annotations[i] = newSymbolToken(text, UNKNOWN_SYMBOL_ID);
}
}
v.setTypeAnnotationSymbols(annotations);
symbol_is_present = true;
}
if (!reader.isNullValue()) {
switch(t) {
case BOOL:
case INT:
case FLOAT:
case DECIMAL:
case TIMESTAMP:
case SYMBOL:
case STRING:
case CLOB:
case BLOB:
break;
case LIST:
case SEXP:
case STRUCT:
// fieldname and annotations off of the parent container
if (load_children((IonContainerLite) v, reader)) {
symbol_is_present = true;
}
break;
default:
throw new IonException("unexpected type encountered reading value: " + t.toString());
}
}
if (symbol_is_present) {
v._isSymbolPresent(true);
}
return v;
}
Aggregations