1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package gov.nist.secauto.oscal.lib.model.control.profile;
28
29 import gov.nist.secauto.oscal.lib.model.Matching;
30 import gov.nist.secauto.oscal.lib.model.ProfileSelectControlById;
31
32 import java.util.Collection;
33 import java.util.LinkedList;
34 import java.util.List;
35 import java.util.regex.Pattern;
36 import java.util.stream.Collectors;
37
38 import edu.umd.cs.findbugs.annotations.NonNull;
39
40 public abstract class AbstractProfileSelectControlById implements IProfileSelectControlById {
41
42
43 @NonNull
44 public static Builder builder() {
45 return new Builder();
46 }
47
48 public static class Builder {
49 private boolean withChildControls;
50 private final List<String> withIds = new LinkedList<>();
51 private final List<Pattern> matching = new LinkedList<>();
52
53 @NonNull
54 public Builder withChildControls(boolean value) {
55 this.withChildControls = value;
56 return this;
57 }
58
59 @NonNull
60 public Builder withId(@NonNull String id) {
61 withIds.add(id);
62 return this;
63 }
64
65 @NonNull
66 public Builder withIds(@NonNull Collection<String> ids) {
67 withIds.addAll(ids);
68 return this;
69 }
70
71 @NonNull
72 public Builder matching(@NonNull Pattern pattern) {
73 matching.add(pattern);
74 return this;
75 }
76
77 @NonNull
78 public ProfileSelectControlById build() {
79 ProfileSelectControlById retval = new ProfileSelectControlById();
80 retval.setWithChildControls(withChildControls ? "yes" : "no");
81 retval.setWithIds(withIds);
82 retval.setMatching(matching.stream()
83 .map(pattern -> {
84 Matching matching = new Matching();
85 matching.setPattern(pattern.pattern());
86 return matching;
87 })
88 .collect(Collectors.toList()));
89 return retval;
90 }
91 }
92 }