1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.pure.preprocess;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.Nullable;
21 import javax.annotation.concurrent.NotThreadSafe;
22
23 import com.helger.commons.ValueEnforcer;
24 import com.helger.commons.annotation.ReturnsMutableCopy;
25 import com.helger.commons.collection.impl.CommonsHashMap;
26 import com.helger.commons.collection.impl.CommonsTreeSet;
27 import com.helger.commons.collection.impl.ICommonsMap;
28 import com.helger.commons.collection.impl.ICommonsSortedSet;
29 import com.helger.commons.string.ToStringGenerator;
30 import com.helger.schematron.pure.model.PSPattern;
31 import com.helger.schematron.pure.model.PSRule;
32 import com.helger.schematron.pure.model.PSSchema;
33
34
35
36
37
38
39
40
41 @NotThreadSafe
42 final class PreprocessorLookup
43 {
44 private final ICommonsMap <String, PSPattern> m_aPatterns = new CommonsHashMap <> ();
45 private final ICommonsMap <String, PSRule> m_aRules = new CommonsHashMap <> ();
46
47 public PreprocessorLookup (@Nonnull final PSSchema aSchema)
48 {
49 ValueEnforcer.notNull (aSchema, "Schema");
50
51 for (final PSPattern aPattern : aSchema.getAllPatterns ())
52 {
53
54 if (aPattern.isAbstract ())
55 m_aPatterns.put (aPattern.getID (), aPattern);
56
57 for (final PSRule aRule : aPattern.getAllRules ())
58 {
59
60 if (aRule.isAbstract ())
61 m_aRules.put (aRule.getID (), aRule);
62 }
63 }
64 }
65
66
67
68
69
70
71
72
73 @Nullable
74 public PSPattern getAbstractPatternOfID (@Nullable final String sID)
75 {
76 return m_aPatterns.get (sID);
77 }
78
79
80
81
82
83
84
85
86 @Nullable
87 public PSRule getAbstractRuleOfID (@Nullable final String sID)
88 {
89 return m_aRules.get (sID);
90 }
91
92
93
94
95 @Nonnull
96 @ReturnsMutableCopy
97 public ICommonsSortedSet <String> getAllAbstractRuleIDs ()
98 {
99 return new CommonsTreeSet <> (m_aRules.keySet ());
100 }
101
102 @Override
103 public String toString ()
104 {
105 return new ToStringGenerator (this).append ("patterns", m_aPatterns).append ("rules", m_aRules).getToString ();
106 }
107 }