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;
}
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);
}
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"));
}
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")));
}
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);
}
Aggregations