Hints { public Hints mergeWith(final Hints other) { final EnumSet<Allow> allows = this.allows.isEmpty() ? noneOf(Allow.class) : copyOf(this.allows); allows.addAll(other.getAllows()); final Set<String> representations = new LinkedHashSet<String>(this.representations); representations.addAll(other.getRepresentations()); final Set<String> acceptPut = new LinkedHashSet<String>(this.acceptPut); acceptPut.addAll(other.getAcceptPut()); final Set<String> acceptPost = new LinkedHashSet<String>(this.acceptPost); acceptPost.addAll(other.getAcceptPost()); final Set<String> acceptPatch = new LinkedHashSet<String>(this.acceptPatch); acceptPatch.addAll(other.getAcceptPatch()); final Set<String> acceptRanges = new LinkedHashSet<String>(this.acceptRanges); acceptRanges.addAll(other.getAcceptRanges()); final Set<String> preferences = new LinkedHashSet<String>(this.preferences); preferences.addAll(other.getPreferences()); final Set<Precondition> preconditionReq = new LinkedHashSet<Precondition>(this.preconditionReq); preconditionReq.addAll(other.getPreconditionReq()); final List<Authentication> mergedAuth = mergeAuthReq(other.getAuthReq()); return hints( allows, new ArrayList<String>(representations), new ArrayList<String>(acceptPut), new ArrayList<String>(acceptPost), new ArrayList<String>(acceptPatch), new ArrayList<String>(acceptRanges), new ArrayList<String>(preferences), new ArrayList<Precondition>(preconditionReq), mergedAuth, status.mergeWith(other.getStatus()), docs.mergeWith(other.getDocs()) ); } private  Hints(final Set<Allow> allows,
                  final List<String> representations,
                  final List<String> acceptPut,
                  final List<String> acceptPost,
                  final List<String> acceptPatch,
                  final List<String> acceptRanges,
                  final List<String> preferences,
                  final List<Precondition> preconditionReq,
                  final List<Authentication> authReq,
                  final Status status,
                  final Documentation docs); static Hints emptyHints(); static Hints hints(final Set<Allow> allows,
                              final List<String> representations); static Hints hints(final Set<Allow> allows,
                              final List<String> representations,
                              final List<String> acceptPut,
                              final List<String> acceptPost,
                              final List<String> acceptPatch,
                              final List<String> acceptRanges,
                              final List<String> preferences,
                              final List<Precondition> preconditionReq,
                              final List<Authentication> authReq,
                              final Status status,
                              final Documentation docs); Set<Allow> getAllows(); List<String> getRepresentations(); List<String> getAcceptPut(); List<String> getAcceptPost(); List<String> getAcceptPatch(); List<String> getAcceptRanges(); List<String> getPreferences(); List<Precondition> getPreconditionReq(); List<Authentication> getAuthReq(); Status getStatus(); Documentation getDocs(); Hints mergeWith(final Hints other); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final Hints EMPTY_HINTS; }
@Test public void testMergeWith() { final Hints firstHints = hintsBuilder() .allowing(of(GET, PUT)) .representedAs("text/html", "text/plain") .acceptingForPut("bar/foo") .build(); final Hints secondHints = hintsBuilder() .allowing(of(GET, POST, DELETE, PATCH)) .representedAs("text/html", "application/json") .acceptingForPost("foo/bar") .build(); final Hints merged = firstHints.mergeWith(secondHints); assertEquals(merged.getAllows(), of(GET, PUT, POST, DELETE, PATCH)); assertEquals(merged.getRepresentations(), asList("text/html", "text/plain", "application/json")); assertEquals(merged.getAcceptPut(), asList("bar/foo")); assertEquals(merged.getAcceptPost(), asList("foo/bar")); }