comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/ValidationException.java @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 package ${package}.utils;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6
7 public class ValidationException extends RuntimeException {
8 private final List<ValidationException> children;
9 private String bullet = "";
10 private String currentMessage;
11
12 public ValidationException(final String message) {
13 this(message, (List<ValidationException>) null);
14 }
15
16 public ValidationException(final String message, final ValidationException child) {
17 this(message, Arrays.asList(child));
18 }
19
20 public ValidationException(final String message, final List<ValidationException> children_) {
21 super(message);
22 this.currentMessage = message;
23 final List<ValidationException> children = new ArrayList<ValidationException>();
24 if (children_ != null) {
25 for (final ValidationException child : children_) {
26 children.addAll(child.simplify());
27 }
28 }
29 this.children = children;
30 }
31
32 public ValidationException withBullet(final String bullet) {
33 this.bullet = bullet;
34 return this;
35 }
36
37 public List<ValidationException> simplify() {
38 if (getMessage().length() > 0) {
39 return Arrays.asList(this);
40 } else {
41 return this.children;
42 }
43 }
44
45 public String summary(final int level, final boolean withBullet) {
46 final int indentPerLevel = 2;
47 final String spaces = new String(new char[level * indentPerLevel]).replace("\0", " ");
48 final String bullet;
49 if (this.bullet.length() > 0 && withBullet) {
50 bullet = this.bullet;
51 } else {
52 bullet = "";
53 }
54 return spaces + bullet + this.currentMessage;
55 }
56
57 public String prettyStr(final Integer level_) {
58 Integer level = level_;
59 if (level == null) {
60 level = 0;
61 }
62 final List<String> parts = new ArrayList<String>();
63 int nextLevel;
64 if (this.currentMessage != null && this.currentMessage.length() > 0) {
65 parts.add(this.summary(level, true));
66 nextLevel = level + 1;
67 } else {
68 nextLevel = level;
69 }
70 for (final ValidationException child : this.children) {
71 parts.add(child.prettyStr(nextLevel));
72 }
73 final String ret = String.join("\n", parts);
74 return ret;
75 }
76
77 public String getMessage() {
78 return this.prettyStr(null);
79 }
80 }