BaggageImpl { public void replace(ByteString namespace, ByteString key, ByteString value) { if (namespace != null && key != null) { if (value == null) { remove(namespace, key); } else { modifyKey(namespace, key).put(key, value); } } } BaggageImpl();   BaggageImpl(Map<ByteString, SetMultimap<ByteString, ByteString>> contents); byte[] toByteArray(); ByteString toByteString(); static BaggageImpl deserialize(byte[] byteRepr); static BaggageImpl deserialize(ByteString byteRepr); boolean contains(ByteString namespace, ByteString key); boolean hasNamespace(ByteString namespace); Set<ByteString> get(ByteString namespace, ByteString key); void remove(ByteString namespace, ByteString key); void removeAll(ByteString namespace); void replace(ByteString namespace, ByteString key, ByteString value); void replace(ByteString namespace, ByteString key, Iterable<? extends ByteString> values); void add(ByteString namespace, ByteString key, ByteString value); Set<ByteString> namespaces(); Set<ByteString> keys(ByteString namespace); void moveEntries(ByteString fromNamespace, ByteString toNamespace); void merge(BaggageImpl other); boolean isEmpty(); BaggageImpl split();  }
@Test public void testReplace() { BaggageImpl b = new BaggageImpl(); ByteString myname = ByteString.copyFrom("namespace".getBytes()); ByteString myname2 = ByteString.copyFrom("namespace2".getBytes()); ByteString mybytes = ByteString.copyFrom("k1".getBytes()); ByteString mybytes2 = ByteString.copyFrom("k2".getBytes()); b.replace(myname, mybytes, mybytes); assertTrue(b.get(myname, mybytes).contains(mybytes)); b.replace(myname, mybytes, mybytes2); assertFalse(b.get(myname, mybytes).contains(mybytes)); assertTrue(b.get(myname, mybytes).contains(mybytes2)); b.replace(myname, mybytes, new ArrayList<ByteString>()); assertTrue(b.get(myname, mybytes).isEmpty()); ArrayList<ByteString> l = new ArrayList<ByteString>(); l.add(mybytes); l.add(mybytes2); l.add(mybytes); b.replace(myname, mybytes, l); assertTrue(b.get(myname, mybytes).contains(mybytes)); assertTrue(b.get(myname, mybytes).contains(mybytes2)); assertEquals(2, b.get(myname, mybytes).size()); assertTrue(b.hasNamespace(myname)); b.replace(myname, null, l); assertFalse(b.contains(myname, null)); b.replace(myname, null, mybytes); assertFalse(b.contains(myname, null)); b.replace(myname2, mybytes, (ByteString) null); assertFalse(b.contains(myname2, mybytes)); assertFalse(b.hasNamespace(myname2)); }