Search in sources :

Example 66 with SymbolToken

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

the class BinaryWriterTest method testInternUnlockedSymtab.

@Test
public void testInternUnlockedSymtab() throws Exception {
    iw = makeWriter();
    iw.writeSymbol("force a local symtab");
    SymbolTable symtab = iw.getSymbolTable();
    assertTrue(!symtab.isReadOnly());
    assertTrue(symtab.isLocalTable());
    symtab.intern("d");
    iw.stepIn(IonType.STRUCT);
    {
        // this causes e to be interned
        iw.setFieldName("e");
        iw.writeInt(1);
        // d was already interned
        iw.setFieldName("d");
        iw.writeInt(2);
    }
    iw.stepOut();
    symtab.makeReadOnly();
    assertTrue(symtab.isReadOnly());
    SymbolToken d = symtab.find("d");
    SymbolToken e = symtab.find("e");
    assertEquals("d", d.assumeText());
    assertEquals("e", e.assumeText());
    // verify that manually interning d first worked
    assertTrue(d.getSid() < e.getSid());
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 67 with SymbolToken

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

the class IonAssert method checkSymbol.

/**
 * @param expectedText null means absent
 */
public static void checkSymbol(IonReader in, String expectedText, int expectedSid) {
    assertSame(IonType.SYMBOL, in.getType());
    assertFalse(in.isNullValue());
    if (expectedText == null) {
        try {
            in.stringValue();
            fail("Expected " + UnknownSymbolException.class);
        } catch (UnknownSymbolException e) {
            assertEquals(expectedSid, e.getSid());
        }
    } else {
        assertEquals("IonReader.stringValue()", expectedText, in.stringValue());
    }
    SymbolToken sym = in.symbolValue();
    IonTestCase.checkSymbol(expectedText, expectedSid, sym);
}
Also used : UnknownSymbolException(com.amazon.ion.UnknownSymbolException) SymbolToken(com.amazon.ion.SymbolToken)

Example 68 with SymbolToken

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

the class IonAssert method sortFields.

/**
 * Problematic with unknown field names.
 * See {@link Equivalence} for another use of this idiom.
 */
private static HashMap<SymbolToken, List<IonValue>> sortFields(IonStruct s) {
    HashMap<SymbolToken, List<IonValue>> sorted = new HashMap<SymbolToken, List<IonValue>>();
    for (IonValue v : s) {
        SymbolToken tok = v.getFieldNameSymbol();
        if (!sorted.containsKey(tok)) {
            sorted.put(tok, new ArrayList<IonValue>());
        }
        sorted.get(tok).add(v);
    }
    return sorted;
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SymbolToken (com.amazon.ion.SymbolToken)68 SymbolTable (com.amazon.ion.SymbolTable)14 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)13 IonType (com.amazon.ion.IonType)10 IonValue (com.amazon.ion.IonValue)10 IonException (com.amazon.ion.IonException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 IonStruct (com.amazon.ion.IonStruct)4 IOException (java.io.IOException)4 Event (com.amazon.tools.events.Event)3 EventType (com.amazon.tools.events.EventType)3 FakeSymbolToken (com.amazon.ion.FakeSymbolToken)2 IonDatagram (com.amazon.ion.IonDatagram)2 IonSequence (com.amazon.ion.IonSequence)2 IonString (com.amazon.ion.IonString)2 UnknownSymbolException (com.amazon.ion.UnknownSymbolException)2 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)2 ImportDescriptor (com.amazon.tools.events.ImportDescriptor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2