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