1 package org.nuiton.validator.bean.simple;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import org.nuiton.validator.NuitonValidatorScope;
25
26 import java.util.EnumMap;
27 import java.util.EnumSet;
28 import java.util.List;
29
30
31
32
33
34
35
36 public class SimpleBeanValidators {
37
38 protected SimpleBeanValidators() {
39
40 }
41
42 public static EnumSet<NuitonValidatorScope> getScopes(
43 List<SimpleBeanValidatorMessage<?>> messages) {
44 EnumSet<NuitonValidatorScope> result =
45 EnumSet.noneOf(NuitonValidatorScope.class);
46 for (SimpleBeanValidatorMessage<?> m : messages) {
47 result.add(m.getScope());
48 }
49 return result;
50 }
51
52 public static EnumMap<NuitonValidatorScope, Integer> getScopesCount(
53 List<SimpleBeanValidatorMessage<?>> messages) {
54 EnumMap<NuitonValidatorScope, Integer> result =
55 new EnumMap<NuitonValidatorScope, Integer>(NuitonValidatorScope.class);
56 for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
57 result.put(s, 0);
58 }
59 for (SimpleBeanValidatorMessage<?> m : messages) {
60
61 NuitonValidatorScope scope = m.getScope();
62
63 result.put(scope, result.get(scope) + 1);
64 }
65
66 for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
67 if (result.get(s) == 0) {
68 result.remove(s);
69 }
70 }
71 return result;
72 }
73 }