@Test public void union() { annotations = builder().set("foo", "1").set("bar", "2").remove("buz").build(); assertEquals("incorrect keys", of("foo", "bar", "buz"), annotations.keys()); SparseAnnotations updates = builder().remove("foo").set("bar", "3").set("goo", "4").remove("fuzz").build(); SparseAnnotations result = DefaultAnnotations.union(annotations, updates); assertTrue("remove instruction in original remains", result.isRemoved("buz")); assertTrue("remove instruction in update remains", result.isRemoved("fuzz")); assertEquals("incorrect keys", of("buz", "goo", "bar", "fuzz"), result.keys()); assertNull("incorrect value", result.value("foo")); assertEquals("incorrect value", "3", result.value("bar")); assertEquals("incorrect value", "4", result.value("goo")); }
public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations) { if (sparseAnnotations == null || sparseAnnotations.keys().isEmpty()) { return annotations; } final HashMap<String, String> newMap; if (annotations instanceof DefaultAnnotations) { newMap = copy(((DefaultAnnotations) annotations).map); } else { newMap = new HashMap<>(annotations.keys().size() + sparseAnnotations.keys().size()); putAllSparseAnnotations(newMap, annotations); } putAllSparseAnnotations(newMap, sparseAnnotations); return new DefaultAnnotations(newMap); }
DefaultAnnotations implements SparseAnnotations { public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations) { if (sparseAnnotations == null || sparseAnnotations.keys().isEmpty()) { return annotations; } final HashMap<String, String> newMap; if (annotations instanceof DefaultAnnotations) { newMap = copy(((DefaultAnnotations) annotations).map); } else { newMap = new HashMap<>(annotations.keys().size() + sparseAnnotations.keys().size()); putAllSparseAnnotations(newMap, annotations); } putAllSparseAnnotations(newMap, sparseAnnotations); return new DefaultAnnotations(newMap); } }
DefaultAnnotations implements SparseAnnotations { public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations) { if (sparseAnnotations == null || sparseAnnotations.keys().isEmpty()) { return annotations; } final HashMap<String, String> newMap; if (annotations instanceof DefaultAnnotations) { newMap = copy(((DefaultAnnotations) annotations).map); } else { newMap = new HashMap<>(annotations.keys().size() + sparseAnnotations.keys().size()); putAllSparseAnnotations(newMap, annotations); } putAllSparseAnnotations(newMap, sparseAnnotations); return new DefaultAnnotations(newMap); } private  DefaultAnnotations(); private  DefaultAnnotations(Map<String, String> map); }
DefaultAnnotations implements SparseAnnotations { public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations) { if (sparseAnnotations == null || sparseAnnotations.keys().isEmpty()) { return annotations; } final HashMap<String, String> newMap; if (annotations instanceof DefaultAnnotations) { newMap = copy(((DefaultAnnotations) annotations).map); } else { newMap = new HashMap<>(annotations.keys().size() + sparseAnnotations.keys().size()); putAllSparseAnnotations(newMap, annotations); } putAllSparseAnnotations(newMap, sparseAnnotations); return new DefaultAnnotations(newMap); } private  DefaultAnnotations(); private  DefaultAnnotations(Map<String, String> map); @Override boolean equals(Object o); @Override int hashCode(); HashMap<String, String> asMap(); static Builder builder(); static DefaultAnnotations merge(DefaultAnnotations annotations,
                                           SparseAnnotations sparseAnnotations); static SparseAnnotations union(SparseAnnotations annotations,
                                          SparseAnnotations sparseAnnotations); @Override Set<String> keys(); @Override String value(String key); @Override boolean isRemoved(String key); @Override String toString(); }
DefaultAnnotations implements SparseAnnotations { public static SparseAnnotations union(SparseAnnotations annotations, SparseAnnotations sparseAnnotations) { if (sparseAnnotations == null || sparseAnnotations.keys().isEmpty()) { return annotations; } final HashMap<String, String> newMap; if (annotations instanceof DefaultAnnotations) { newMap = copy(((DefaultAnnotations) annotations).map); } else { newMap = new HashMap<>(annotations.keys().size() + sparseAnnotations.keys().size()); putAllSparseAnnotations(newMap, annotations); } putAllSparseAnnotations(newMap, sparseAnnotations); return new DefaultAnnotations(newMap); } private  DefaultAnnotations(); private  DefaultAnnotations(Map<String, String> map); @Override boolean equals(Object o); @Override int hashCode(); HashMap<String, String> asMap(); static Builder builder(); static DefaultAnnotations merge(DefaultAnnotations annotations,
                                           SparseAnnotations sparseAnnotations); static SparseAnnotations union(SparseAnnotations annotations,
                                          SparseAnnotations sparseAnnotations); @Override Set<String> keys(); @Override String value(String key); @Override boolean isRemoved(String key); @Override String toString(); static final SparseAnnotations EMPTY; }