@Test public void testGetImmutableMapOrNull() { ServiceTalkThreadContextMap map = new ServiceTalkThreadContextMap(); map.clear(); assertNull(map.getImmutableMapOrNull()); map.put("x", "10"); Map<String, String> immutableMap = map.getImmutableMapOrNull(); assertNotNull(immutableMap); assertEquals(immutableMap.size(), 1); try { immutableMap.put("y", "20"); fail(); } catch (UnsupportedOperationException ignored) { } }
@Nullable @Override public Map<String, String> getImmutableMapOrNull() { Map<String, String> storage = getStorage(); if (storage.isEmpty()) { return null; } final Map<String, String> copy = getCopyOrNull(storage, true); return copy == null ? null : unmodifiableMap(copy); }
ServiceTalkThreadContextMap implements ReadOnlyThreadContextMap, CleanableThreadContextMap { @Nullable @Override public Map<String, String> getImmutableMapOrNull() { Map<String, String> storage = getStorage(); if (storage.isEmpty()) { return null; } final Map<String, String> copy = getCopyOrNull(storage, true); return copy == null ? null : unmodifiableMap(copy); } }
ServiceTalkThreadContextMap implements ReadOnlyThreadContextMap, CleanableThreadContextMap { @Nullable @Override public Map<String, String> getImmutableMapOrNull() { Map<String, String> storage = getStorage(); if (storage.isEmpty()) { return null; } final Map<String, String> copy = getCopyOrNull(storage, true); return copy == null ? null : unmodifiableMap(copy); }  }
ServiceTalkThreadContextMap implements ReadOnlyThreadContextMap, CleanableThreadContextMap { @Nullable @Override public Map<String, String> getImmutableMapOrNull() { Map<String, String> storage = getStorage(); if (storage.isEmpty()) { return null; } final Map<String, String> copy = getCopyOrNull(storage, true); return copy == null ? null : unmodifiableMap(copy); }  @Override final void put(String key, String value); @Nullable @Override String get(String key); @Override final void remove(String key); @Override final void clear(); @Override boolean containsKey(String key); @Override Map<String, String> getCopy(); @Nullable @Override Map<String, String> getImmutableMapOrNull(); @Override boolean isEmpty(); @Override final void removeAll(Iterable<String> keys); @Override final void putAll(Map<String, String> map); @Override StringMap getReadOnlyContextData(); }
ServiceTalkThreadContextMap implements ReadOnlyThreadContextMap, CleanableThreadContextMap { @Nullable @Override public Map<String, String> getImmutableMapOrNull() { Map<String, String> storage = getStorage(); if (storage.isEmpty()) { return null; } final Map<String, String> copy = getCopyOrNull(storage, true); return copy == null ? null : unmodifiableMap(copy); }  @Override final void put(String key, String value); @Nullable @Override String get(String key); @Override final void remove(String key); @Override final void clear(); @Override boolean containsKey(String key); @Override Map<String, String> getCopy(); @Nullable @Override Map<String, String> getImmutableMapOrNull(); @Override boolean isEmpty(); @Override final void removeAll(Iterable<String> keys); @Override final void putAll(Map<String, String> map); @Override StringMap getReadOnlyContextData();  }