1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.sanity;
15
16 import ch.qos.logback.core.model.Model;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22
23
24
25
26 public interface SanityChecker {
27
28 public void check(Model model);
29
30 default void deepFindAllModelsOfType(Class<? extends Model> modelClass, List<Model> modelList, Model model) {
31 if (modelClass.isInstance(model)) {
32 modelList.add(model);
33 }
34
35 for (Model m : model.getSubModels()) {
36 deepFindAllModelsOfType(modelClass, modelList, m);
37 }
38 }
39
40 default List<Pair<Model, Model>> deepFindNestedSubModelsOfType(Class<? extends Model> modelClass, List<? extends Model> parentList) {
41
42 List<Pair<Model, Model>> nestingPairs = new ArrayList<>();
43
44 for (Model parent : parentList) {
45 List<Model> nestedElements = new ArrayList<>();
46 parent.getSubModels().stream().forEach(m -> deepFindAllModelsOfType(modelClass, nestedElements, m));
47 nestedElements.forEach(n -> nestingPairs.add(new Pair(parent, n)));
48 }
49 return nestingPairs;
50 }
51 }