1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.dependency;
19
20 import java.io.Serializable;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27 import org.owasp.dependencycheck.data.cwe.CweDB;
28
29
30
31
32
33
34 public class CweSet implements Serializable {
35
36
37
38
39 private static final long serialVersionUID = 7884812602736995362L;
40
41
42
43
44 private final Set<String> cwes = new HashSet<>();
45
46
47
48
49
50
51 public Set<String> getEntries() {
52 return cwes;
53 }
54
55
56
57
58
59
60 public void addCwe(String cwe) {
61 if (cwe != null) {
62 this.cwes.add(cwe);
63 }
64 }
65
66 @Override
67 public String toString() {
68 if (cwes.isEmpty()) {
69 return "";
70 }
71 return cwes.stream().map(CweDB::getFullName).collect(Collectors.joining(", "));
72 }
73
74
75
76
77
78
79 public Stream<String> stream() {
80 return cwes.stream();
81 }
82
83
84
85
86
87
88 public Map<String, String> getFullCwes() {
89 final Map<String, String> map = new HashMap<>();
90 cwes.forEach((cwe) -> map.put(cwe, CweDB.getName(cwe)));
91 return map;
92 }
93
94
95
96
97
98
99
100
101 public boolean isEmpty() {
102 return cwes.isEmpty();
103 }
104 }