/** * Returns an implementation of the {@code StringMap} used to back this thread context map, pre-populated * with the contents of the specified context data. * <p> * Subclasses may override. * </p> * @param original the key-value pairs to initialize the returned context data with * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap(final ReadOnlyStringMap original) { return new SortedArrayStringMap(original); }
/** * Constructs a new instance based on an existing {@link Map}. * @param map The Map. */ public MapMessage(final Map<String, V> map) { this.data = new SortedArrayStringMap(map); }
/** * Returns an implementation of the {@code StringMap} used to back this thread context map. * <p> * Subclasses may override. * </p> * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap() { return new SortedArrayStringMap(initialCapacity); }
/** * Returns an implementation of the {@code StringMap} used to back this thread context map. * <p> * Subclasses may override. * </p> * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap() { return new SortedArrayStringMap(initialCapacity); }
/** * Constructs a new instance. */ public MapMessage() { this.data = new SortedArrayStringMap(); }
/** * Returns an implementation of the {@code StringMap} used to back this thread context map, pre-populated * with the contents of the specified context data. * <p> * Subclasses may override. * </p> * @param original the key-value pairs to initialize the returned context data with * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap(final ReadOnlyStringMap original) { return new SortedArrayStringMap(original); }
private static StringMap createContextData() { final StringMap result = new SortedArrayStringMap(); result.putValue("a", "1"); result.putValue("b", "2"); return result; }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModificationTriConsumerPut() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "aaa"); original.forEach(new TriConsumer<String, Object, Object>() { @Override public void accept(final String s, final Object o, final Object o2) { original.putValue("c", "other"); } }, null); }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModificationTriConsumerClear() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "aaa"); original.forEach(new TriConsumer<String, Object, Object>() { @Override public void accept(final String s, final Object o, final Object o2) { original.clear(); } }, null); }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModificationTriConsumerPutValue() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "aaa"); original.forEach(new TriConsumer<String, Object, Object>() { @Override public void accept(final String s, final Object o, final Object o2) { original.putValue("c", "other"); } }, null); }
@Test(expected = UnsupportedOperationException.class) public void testFreezeProhibitsPutValue() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.freeze(); original.putValue("a", "aaa"); }
@Test public void testFreezeAllowsClearIfEmpty() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.freeze(); original.clear(); }
@Test public void testFreezeAllowsRemoveIfEmpty() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.freeze(); original.remove("a"); // no exception }
@Test public void testConstructorIgnoresNull() throws Exception { assertEquals(0, new SortedArrayStringMap((SortedArrayStringMap) null).size()); }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModificationBiConsumerClear() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "aaa"); original.forEach(new BiConsumer<String, Object>() { @Override public void accept(final String s, final Object o) { original.clear(); } }); }
@Test(expected = UnsupportedOperationException.class) public void testFreezeProhibitsRemove() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("b", "bbb"); original.freeze(); original.remove("b"); // existing key: modifies the collection }
@Test public void testToString() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "avalue"); original.putValue("B", "Bvalue"); original.putValue("3", "3value"); assertEquals("{3=3value, B=Bvalue, a=avalue}", original.toString()); }
@Test public void testIsFrozenAfterCallingFreeze() { final SortedArrayStringMap original = new SortedArrayStringMap(); assertFalse("before freeze", original.isFrozen()); original.freeze(); assertTrue("after freeze", original.isFrozen()); }
@Test public void testSerialization() throws Exception { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "avalue"); original.putValue("B", "Bvalue"); original.putValue("3", "3value"); final byte[] binary = serialize(original); final SortedArrayStringMap copy = deserialize(binary); assertEquals(original, copy); }
@Test public void testRemove() { final SortedArrayStringMap original = new SortedArrayStringMap(); original.putValue("a", "avalue"); assertEquals(1, original.size()); assertEquals("avalue", original.getValue("a")); original.remove("a"); assertEquals(0, original.size()); assertNull("no a val", original.getValue("a")); original.remove("B"); assertEquals(0, original.size()); assertNull("no B val", original.getValue("B")); }