-
Notifications
You must be signed in to change notification settings - Fork 5
/
ExceptionUtils.java
42 lines (38 loc) · 1.18 KB
/
ExceptionUtils.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* © 2023. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.utils;
import edu.ie3.datamodel.models.UniqueEntity;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class ExceptionUtils {
private ExceptionUtils() {
throw new IllegalStateException("Utility classes cannot be instantiated");
}
/**
* Creates a string containing multiple exception messages.
*
* @param exceptions list of exceptions
* @return str containing the messages
*/
public static String getMessages(List<? extends Exception> exceptions) {
return exceptions.stream()
.map(Throwable::getMessage)
.reduce("", (a, b) -> a + "\n " + b)
.replaceFirst("\n ", "");
}
/**
* Combines multiple {@link UniqueEntity} into a string.
*
* @param entities to be combined
* @return a string
*/
public static String combine(Collection<? extends UniqueEntity> entities) {
return "{"
+ entities.stream().map(UniqueEntity::toString).collect(Collectors.joining(", "))
+ "}";
}
}