BaggageImpl { public BaggageImpl split() { Handlers.preSplit(this); Map<ByteString, SetMultimap<ByteString, ByteString>> copiedData = Maps.newHashMapWithExpectedSize(contents.size()); for (ByteString namespace : contents.keySet()) { copiedData.put(namespace, HashMultimap.create(contents.get(namespace))); } BaggageImpl newImpl = new BaggageImpl(copiedData); Handlers.postSplit(this, newImpl); return newImpl; } 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 testSplit() { 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.add(myname, mybytes, mybytes); b.add(myname, mybytes, mybytes2); b.add(myname2, mybytes2, mybytes); BaggageImpl b2 = b.split(); assertTrue(b.get(myname, mybytes).contains(mybytes)); assertTrue(b.get(myname, mybytes).contains(mybytes2)); assertTrue(b.get(myname2, mybytes2).contains(mybytes)); assertTrue(b2.get(myname, mybytes).contains(mybytes)); assertTrue(b2.get(myname, mybytes).contains(mybytes2)); assertTrue(b2.get(myname2, mybytes2).contains(mybytes)); assertEquals(b.get(myname, mybytes).size(), b2.get(myname, mybytes).size()); assertEquals(b.get(myname2, mybytes2).size(), b2.get(myname2, mybytes2).size()); }