-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidationResult.java
More file actions
56 lines (46 loc) · 1.52 KB
/
ValidationResult.java
File metadata and controls
56 lines (46 loc) · 1.52 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pl.commit.craft.template;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Set;
@AllArgsConstructor
class ValidationResult {
@Getter
private final boolean valid;
private final Set<String> missingInPattern;
private final Set<String> extraInPattern;
/**
* Creates a successful validation result
*/
public static ValidationResult valid() {
return new ValidationResult(true, Set.of(), Set.of());
}
/**
* Creates a validation result with errors
*/
public static ValidationResult invalid(Set<String> missingInPattern, Set<String> extraInPattern) {
return new ValidationResult(false, missingInPattern, extraInPattern);
}
/**
* Generates a detailed error message for invalid templates
*/
public String getErrorMessage() {
if (valid) {
return "Template is valid";
}
StringBuilder message = new StringBuilder("Invalid template format: ");
if (!missingInPattern.isEmpty()) {
message.append("Keys missing in pattern: [")
.append(String.join(", ", missingInPattern))
.append("]");
if (!extraInPattern.isEmpty()) {
message.append("; ");
}
}
if (!extraInPattern.isEmpty()) {
message.append("Missing keys in model: [")
.append(String.join(", ", extraInPattern))
.append("]");
}
return message.toString();
}
}