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