Search in sources :

Example 1 with IcedHashMapGeneric

use of water.util.IcedHashMapGeneric in project h2o-3 by h2oai.

the class IcedHasMapGenericTest method testSerialization.

@Test
public void testSerialization() {
    IcedHashMapGeneric m = new IcedHashMapGeneric();
    // String -> String pair
    m.put("haha", "gaga");
    // String -> String pair
    m.put("str->freezable", new IcedDouble(3.14));
    // String -> String pair
    m.put("str->freezable[]", new Freezable[] { new IcedDouble(3.14) });
    // String -> String pair
    m.put("str->Integer", 314);
    // Freezable -> String pair
    m.put(new BufferedString("haha2"), "gaga");
    // String -> String pair
    m.put(new BufferedString("str->freezable2"), new IcedDouble(3.14));
    // String -> String pair
    m.put(new BufferedString("str->freezable[]2"), new Freezable[] { new IcedDouble(3.14) });
    // String -> String pair
    m.put(new BufferedString("str->Integer2"), 314);
    // String -> String pair
    m.put(new IcedLong(1234), 1234);
    byte[] buf = new AutoBuffer().put(m).buf();
    IcedHashMapGeneric m2 = new AutoBuffer(buf).get();
    assertEquals(m.size(), m2.size());
    Set<Map.Entry> entries = m.entrySet();
    for (Map.Entry e : entries) {
        if (e.getValue() instanceof Freezable[])
            assert Arrays.deepEquals((Freezable[]) e.getValue(), (Freezable[]) m2.get(e.getKey()));
        else
            assertEquals(e.getValue(), m2.get(e.getKey()));
    }
}
Also used : IcedHashMapGeneric(water.util.IcedHashMapGeneric) IcedDouble(water.util.IcedDouble) IcedLong(water.util.IcedLong) BufferedString(water.parser.BufferedString) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)1 Test (org.junit.Test)1 BufferedString (water.parser.BufferedString)1 IcedDouble (water.util.IcedDouble)1 IcedHashMapGeneric (water.util.IcedHashMapGeneric)1 IcedLong (water.util.IcedLong)1