Search in sources :

Example 1 with IonSexp

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

the class IonReaderTextSystemX method getIonValue.

public IonValue getIonValue(IonSystem sys) {
    if (isNullValue()) {
        switch(_value_type) {
            case NULL:
                return sys.newNull();
            case BOOL:
                return sys.newNullBool();
            case INT:
                return sys.newNullInt();
            case FLOAT:
                return sys.newNullFloat();
            case DECIMAL:
                return sys.newNullDecimal();
            case TIMESTAMP:
                return sys.newNullTimestamp();
            case SYMBOL:
                return sys.newNullSymbol();
            case STRING:
                return sys.newNullString();
            case CLOB:
                return sys.newNullClob();
            case BLOB:
                return sys.newNullBlob();
            case LIST:
                return sys.newNullList();
            case SEXP:
                return sys.newNullSexp();
            case STRUCT:
                return sys.newNullString();
            default:
                throw new IonException("unrecognized type encountered");
        }
    }
    switch(_value_type) {
        case NULL:
            return sys.newNull();
        case BOOL:
            return sys.newBool(booleanValue());
        case INT:
            return sys.newInt(longValue());
        case FLOAT:
            return sys.newFloat(doubleValue());
        case DECIMAL:
            return sys.newDecimal(decimalValue());
        case TIMESTAMP:
            IonTimestamp t = sys.newNullTimestamp();
            Timestamp ti = timestampValue();
            t.setValue(ti);
            return t;
        case SYMBOL:
            return sys.newSymbol(stringValue());
        case STRING:
            return sys.newString(stringValue());
        case CLOB:
            IonClob clob = sys.newNullClob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            clob.setBytes(newBytes());
            return clob;
        case BLOB:
            IonBlob blob = sys.newNullBlob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            blob.setBytes(newBytes());
            return blob;
        case LIST:
            IonList list = sys.newNullList();
            fillContainerList(sys, list);
            return list;
        case SEXP:
            IonSexp sexp = sys.newNullSexp();
            fillContainerList(sys, sexp);
            return sexp;
        case STRUCT:
            IonStruct struct = sys.newNullStruct();
            fillContainerStruct(sys, struct);
            return struct;
        default:
            throw new IonException("unrecognized type encountered");
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonException(com.amazon.ion.IonException) IonTimestamp(com.amazon.ion.IonTimestamp) IonList(com.amazon.ion.IonList) IonClob(com.amazon.ion.IonClob) IonBlob(com.amazon.ion.IonBlob) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp)

Example 2 with IonSexp

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

the class _Private_CurriedValueFactory method newSexp.

public IonSexp newSexp(int[] values) {
    IonSexp v = myFactory.newSexp(values);
    handle(v);
    return v;
}
Also used : IonSexp(com.amazon.ion.IonSexp)

Example 3 with IonSexp

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

the class _Private_CurriedValueFactory method newSexp.

@Deprecated
public IonSexp newSexp(Collection<? extends IonValue> values) throws ContainedValueException, NullPointerException {
    IonSexp v = myFactory.newSexp(values);
    handle(v);
    return v;
}
Also used : IonSexp(com.amazon.ion.IonSexp)

Example 4 with IonSexp

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

the class PrinterTest method testPrintingAnnotations.

// =========================================================================
// Test cases
@Test
public void testPrintingAnnotations() throws Exception {
    IonNull value = (IonNull) oneValue("an::$0::null");
    checkRendering("an::$0::null", value);
    value.addTypeAnnotation("+");
    value.addTypeAnnotation("\u0000");
    value.addTypeAnnotation("$0");
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintSymbolAsString(true);
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintStringAsJson(true);
    checkRendering("an::$0::'+'::'\\0'::'$0'::null", value);
    myPrinter.setPrintSymbolAsString(false);
    myPrinter.setPrintStringAsJson(false);
    myPrinter.setSkipAnnotations(true);
    checkRendering("null", value);
    myPrinter.setSkipAnnotations(false);
    IonSexp s = system().newEmptySexp();
    s.add(value);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    myPrinter.setPrintSymbolAsString(true);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    myPrinter.setPrintStringAsJson(true);
    checkRendering("(an::$0::'+'::'\\0'::'$0'::null)", s);
    value.setTypeAnnotations("boo", "boo");
    checkRendering("boo::boo::null", value);
}
Also used : IonSexp(com.amazon.ion.IonSexp) IonNull(com.amazon.ion.IonNull) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 5 with IonSexp

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

the class _Private_CurriedValueFactory method newSexp.

public IonSexp newSexp(IonSequence firstChild) throws ContainedValueException, NullPointerException {
    IonSexp v = myFactory.newSexp(firstChild);
    handle(v);
    return v;
}
Also used : IonSexp(com.amazon.ion.IonSexp)

Aggregations

IonSexp (com.amazon.ion.IonSexp)13 Test (org.junit.Test)4 IonList (com.amazon.ion.IonList)3 IonStruct (com.amazon.ion.IonStruct)3 BlobTest (com.amazon.ion.BlobTest)2 ClobTest (com.amazon.ion.ClobTest)2 IntTest (com.amazon.ion.IntTest)2 IonBlob (com.amazon.ion.IonBlob)2 IonClob (com.amazon.ion.IonClob)2 IonNull (com.amazon.ion.IonNull)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 IonBool (com.amazon.ion.IonBool)1 IonDatagram (com.amazon.ion.IonDatagram)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1 IonFloat (com.amazon.ion.IonFloat)1 IonInt (com.amazon.ion.IonInt)1 IonString (com.amazon.ion.IonString)1 IonSymbol (com.amazon.ion.IonSymbol)1 Timestamp (com.amazon.ion.Timestamp)1