Search in sources :

Example 66 with IonValue

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

the class ReverseBinaryEncoder method writeIonStructContent.

private void writeIonStructContent(IonStruct val) {
    if (val.isNullValue()) {
        writeByte((byte) (TYPE_STRUCT | NULL_LENGTH_MASK));
    } else {
        final int originalOffset = myBuffer.length - myOffset;
        // TODO amzn/ion-java/issues/31 should not preserve the ordering of fields
        ArrayList<IonValue> values = new ArrayList<IonValue>();
        // references of the IonValues
        for (IonValue curr : val) {
            values.add(curr);
        }
        for (int i = values.size(); --i >= 0; ) {
            IonValue v = values.get(i);
            SymbolToken symToken = v.getFieldNameSymbol();
            writeIonValue(v);
            int sid = findSid(symToken);
            writeVarUInt(sid);
        }
        // TODO amzn/ion-java/issues/41 Detect if the struct fields are sorted in ascending
        // order of Sids. If so, 1 should be written into 'length' field.
        // Note that this 'length' field is not the same as the four-bit
        // length L in the type descriptor octet.
        writePrefix(TYPE_STRUCT, myBuffer.length - myOffset - originalOffset);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) ArrayList(java.util.ArrayList)

Example 67 with IonValue

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

the class IonStructLite method retainAll.

public boolean retainAll(String... fieldNames) {
    checkForLock();
    boolean removedAny = false;
    int size = get_child_count();
    for (int ii = size; ii > 0; ) {
        ii--;
        IonValue field = get_child(ii);
        if (!isListedField(field, fieldNames)) {
            field.removeFromContainer();
            removedAny = true;
        }
    }
    return removedAny;
}
Also used : IonValue(com.amazon.ion.IonValue)

Example 68 with IonValue

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

the class IonStructLite method get.

public IonValue get(String fieldName) {
    int field_idx = find_field_helper(fieldName);
    IonValue field;
    if (field_idx < 0) {
        if (hasNullFieldName)
            throw new UnknownSymbolException("Unable to determine whether the field exists because the struct contains field names with unknown text.");
        field = null;
    } else {
        field = get_child(field_idx);
    }
    return field;
}
Also used : IonValue(com.amazon.ion.IonValue) UnknownSymbolException(com.amazon.ion.UnknownSymbolException)

Example 69 with IonValue

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

the class IonSequenceLite method sequenceHashCode.

protected int sequenceHashCode(int seed, SymbolTableProvider symbolTableProvider) {
    final int prime = 8191;
    int result = seed;
    if (!isNullValue()) {
        for (IonValue v : this) {
            IonValueLite vLite = (IonValueLite) v;
            result = prime * result + vLite.hashCode(symbolTableProvider);
            // mixing at each step to make the hash code order-dependent
            result ^= (result << 29) ^ (result >> 3);
        }
    }
    return hashTypeAnnotations(result, symbolTableProvider);
}
Also used : com.amazon.ion.impl._Private_IonValue(com.amazon.ion.impl._Private_IonValue) IonValue(com.amazon.ion.IonValue)

Example 70 with IonValue

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

the class IonDatagramLite method hashCode.

@Override
public int hashCode() {
    int prime = 8191;
    int result = HASH_SIGNATURE;
    if (!isNullValue()) {
        // own symbol table.
        for (IonValue v : this) {
            result = prime * result + v.hashCode();
            // mixing at each step to make the hash code order-dependent
            result ^= (result << 29) ^ (result >> 3);
        }
    }
    return result;
}
Also used : IonValue(com.amazon.ion.IonValue)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4