Search in sources :

Example 11 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class PlatformUtils method unwrapBinary.

/**
     * @param o Object to unwrap.
     * @return Unwrapped object.
     */
private static Object unwrapBinary(Object o) {
    if (o == null)
        return null;
    if (knownArray(o))
        return o;
    if (o instanceof Map.Entry) {
        Map.Entry entry = (Map.Entry) o;
        Object key = entry.getKey();
        Object uKey = unwrapBinary(key);
        Object val = entry.getValue();
        Object uVal = unwrapBinary(val);
        return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
    } else if (BinaryUtils.knownCollection(o))
        return unwrapKnownCollection((Collection<Object>) o);
    else if (BinaryUtils.knownMap(o))
        return unwrapBinariesIfNeeded((Map<Object, Object>) o);
    else if (o instanceof Object[])
        return unwrapBinariesInArray((Object[]) o);
    else if (o instanceof BinaryObject)
        return ((BinaryObject) o).deserialize();
    return o;
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryTreeSelfTest method checkTreeSet.

/**
     * Check {@code TreeSet} data structure.
     *
     * @param useBinary Whether to go through binary mode.
     * @param useComparator Whether comparator should be used.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
private void checkTreeSet(boolean useBinary, boolean useComparator) throws Exception {
    // Populate set.
    TreeSet<TestKey> set;
    if (useComparator) {
        set = new TreeSet<>(new TestKeyComparator());
        for (int i = 0; i < SIZE; i++) set.add(key(false, i));
    } else {
        set = new TreeSet<>();
        for (int i = 0; i < SIZE; i++) set.add(key(true, i));
    }
    // Put and get value from cache.
    cache().put(KEY, set);
    TreeSet<TestKey> resSet;
    if (useBinary) {
        BinaryObject resMapBinary = (BinaryObject) cache().withKeepBinary().get(KEY);
        resSet = resMapBinary.deserialize();
    } else
        resSet = (TreeSet<TestKey>) cache().get(KEY);
    // Ensure content is correct.
    if (useComparator)
        assert resSet.comparator() instanceof TestKeyComparator;
    else
        assertNull(resSet.comparator());
    assertEquals(set, resSet);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) TreeSet(java.util.TreeSet)

Example 13 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testStringField.

/**
     * @throws Exception If failed.
     */
public void testStringField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("stringField", "str");
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals("str", po.<String>field("stringField"));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 14 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testCharArrayField.

/**
     * @throws Exception If failed.
     */
public void testCharArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("charArrayField", new char[] { 1, 2, 3 });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(Arrays.equals(new char[] { 1, 2, 3 }, po.<char[]>field("charArrayField")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 15 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testDoubleField.

/**
     * @throws Exception If failed.
     */
public void testDoubleField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("doubleField", 1.0d);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6