Example usage for org.apache.wicket.util.collections MiniMap size

List of usage examples for org.apache.wicket.util.collections MiniMap size

Introduction

In this page you can find the example usage for org.apache.wicket.util.collections MiniMap size.

Prototype

int size

To view the source code for org.apache.wicket.util.collections MiniMap size.

Click Source Link

Document

The number of valid entries

Usage

From source file:de.javakaffee.kryoserializers.wicket.MiniMapSerializer.java

License:Apache License

@Override
public void write(final Kryo kryo, final Output output, final MiniMap<Object, Object> map) {
    output.writeInt(getMaxEntries(map), true);
    output.writeInt(map.size(), true);

    for (final Entry<?, ?> entry : map.entrySet()) {
        kryo.writeClassAndObject(output, entry.getKey());
        kryo.writeClassAndObject(output, entry.getValue());
    }/*from  w ww  . ja v a2s  . c om*/

    if (TRACE)
        trace("kryo", "Wrote map: " + map);
}

From source file:de.javakaffee.kryoserializers.wicket.MiniMapSerializerTest.java

License:Apache License

@Test(enabled = true)
public void testMiniMapEmpty() {
    final MiniMap<?, ?> obj = new MiniMap<Object, Object>(0);
    final byte[] serialized = serialize(_kryo, obj);
    final MiniMap<?, ?> deserialized = deserialize(_kryo, serialized, MiniMap.class);
    Assert.assertEquals(deserialized.size(), obj.size());
}

From source file:de.javakaffee.kryoserializers.wicket.MiniMapSerializerTest.java

License:Apache License

@Test(enabled = true)
public void testMiniMapExactNumberOfEntries() {
    final MiniMap<String, String> obj = new MiniMap<String, String>(1);
    obj.put("foo", "bar");
    final byte[] serialized = serialize(_kryo, obj);
    final MiniMap<?, ?> deserialized = deserialize(_kryo, serialized, MiniMap.class);
    Assert.assertEquals(deserialized.size(), obj.size());
    final Entry<?, ?> deserializedNext = deserialized.entrySet().iterator().next();
    final Entry<?, ?> origNext = obj.entrySet().iterator().next();
    Assert.assertEquals(deserializedNext.getKey(), origNext.getKey());
    Assert.assertEquals(deserializedNext.getValue(), origNext.getValue());
}

From source file:de.javakaffee.kryoserializers.wicket.MiniMapSerializerTest.java

License:Apache License

@Test(enabled = true)
public void testMiniMapLessThanMaxEntries() {
    final MiniMap<String, String> obj = new MiniMap<String, String>(2);
    obj.put("foo", "bar");
    final byte[] serialized = serialize(_kryo, obj);
    final MiniMap<?, ?> deserialized = deserialize(_kryo, serialized, MiniMap.class);
    Assert.assertEquals(deserialized.size(), obj.size());
}

From source file:de.javakaffee.kryoserializers.wicket.MiniMapSerializerTest.java

License:Apache License

@SuppressWarnings("unchecked")
@Test(enabled = true)//  ww w.  ja v a 2 s.  c  om
public void testMiniMapAddEntriesAfterDeserialization() {
    final MiniMap<String, String> obj = new MiniMap<String, String>(2);
    obj.put("foo", "bar");
    final byte[] serialized = serialize(_kryo, obj);
    final MiniMap<String, String> deserialized = deserialize(_kryo, serialized, MiniMap.class);
    Assert.assertEquals(deserialized.size(), obj.size());

    deserialized.put("bar", "baz");
    try {
        deserialized.put("this should", "fail");
        Assert.fail("We told the orig MiniMap to accept 2 entries at max,"
                + " therefore we should not be allowed to put more.");
    } catch (final RuntimeException e) {
        // this is expected - didn't use @Test.expectedExceptions
        // as this would tie us to the exactly thrown exception
    }
}