MCPcopy
hub / github.com/zaproxy/zaproxy / AlertSet

Class AlertSet

zap/src/main/java/org/zaproxy/zap/extension/alert/AlertSet.java:36–200  ·  view source on GitHub ↗

A collection of Alerts with unique alertIds. @since 2.17.0

Source from the content-addressed store, hash-verified

34 * @since 2.17.0
35 */
36public class AlertSet {
37
38 private Map<Integer, Alert> map = new ConcurrentHashMap<>();
39 private Alert highestRisk;
40
41 public AlertSet() {}
42
43 /**
44 * Add the specified alert to the set.
45 *
46 * @param alert the alert
47 * @return true if the alert was not already in the set.
48 */
49 public synchronized boolean add(Alert alert) {
50 boolean added = map.put(alert.getAlertId(), alert) == null;
51 highestRisk = getHighestRisk(highestRisk, alert);
52 return added;
53 }
54
55 /**
56 * Adds all of the specified alerts to the set.
57 *
58 * @param alerts the alerts
59 * @return true if one or more of the alerts were not already in the set.
60 */
61 public boolean addAll(List<Alert> alerts) {
62 AtomicBoolean changed = new AtomicBoolean(false);
63 alerts.forEach(
64 a -> {
65 if (add(a)) {
66 changed.set(true);
67 }
68 });
69 return changed.get();
70 }
71
72 /**
73 * Removes the specified alert using the alertId.
74 *
75 * @param alert the alert to remove
76 * @return true if the alert was removed
77 */
78 public synchronized boolean remove(Alert alert) {
79 Alert a = map.remove(alert.getAlertId());
80 if (a != null) {
81 if (highestRisk != null && a.getAlertId() == highestRisk.getAlertId()) {
82 calculateHighestRisk();
83 }
84 return true;
85 }
86 return false;
87 }
88
89 /**
90 * Removes all of the specified alerts.
91 *
92 * @param alerts the alerts to remove
93 * @return true if one or more of the alerts were removed.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected