1
2
3
4
5
6 package gov.nist.secauto.oscal.lib.model.metadata;
7
8 import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
9 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
10 import gov.nist.secauto.oscal.lib.model.Link;
11
12 import java.net.URI;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.stream.Collectors;
16 import java.util.stream.Stream;
17
18 import edu.umd.cs.findbugs.annotations.NonNull;
19
20 public abstract class AbstractLink implements ILink {
21
22 public static List<Link> merge(@NonNull List<Link> original, @NonNull List<Link> additional) {
23 return Stream.concat(original.stream(), additional.stream())
24 .collect(Collectors.toCollection(LinkedList::new));
25 }
26
27 @NonNull
28 public static Builder builder(@NonNull URI href) {
29 return new Builder(href);
30 }
31
32 public static class Builder {
33 @NonNull
34 private final URI href;
35 private String rel;
36 private String mediaType;
37 private MarkupLine text;
38
39 public Builder(@NonNull URI href) {
40 this.href = ObjectUtils.requireNonNull(href, "href");
41 }
42
43 @NonNull
44 public Builder relation(@NonNull String relation) {
45 this.rel = ObjectUtils.requireNonNull(relation, "rel");
46 return this;
47 }
48
49 @NonNull
50 public Builder value(@NonNull String mediaType) {
51 this.mediaType = ObjectUtils.requireNonNull(mediaType, "mediaType");
52 return this;
53 }
54
55 @NonNull
56 public Builder clazz(@NonNull MarkupLine text) {
57 this.text = ObjectUtils.requireNonNull(text, "text");
58 return this;
59 }
60
61 @NonNull
62 public Link build() {
63 Link retval = new Link();
64 retval.setHref(href);
65 if (rel != null) {
66 retval.setRel(rel);
67 }
68 if (mediaType != null) {
69 retval.setMediaType(mediaType);
70 }
71 if (text != null) {
72 retval.setText(text);
73 }
74
75 return retval;
76 }
77 }
78 }