1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package ca.uhn.hl7v2.validation.builder;
27
28 import java.util.Collections;
29 import java.util.List;
30
31 import ca.uhn.hl7v2.Version;
32 import ca.uhn.hl7v2.validation.Rule;
33 import ca.uhn.hl7v2.validation.impl.RuleBinding;
34
35
36
37
38
39
40
41 @SuppressWarnings("serial")
42 public class ValidationRuleBuilder extends RuleTypeBuilder<ValidationRuleBuilder, Rule<?>> {
43
44 protected ValidationRuleBuilder() {
45 super();
46 }
47
48 private ValidationRuleBuilder(List<RuleBinding<? extends Rule<?>>> rules, Version... versions) {
49 super(rules, versions);
50 }
51
52 public final List<RuleBinding<? extends Rule<?>>> initialize() {
53 if (getRules().isEmpty()) configure();
54 return Collections.unmodifiableList(getRules());
55 }
56
57
58
59
60 protected void configure() {
61 }
62
63 public final ValidationRuleBuilder forVersion(
64 Version... version) {
65 return new ValidationRuleBuilder(getRules(), version);
66 }
67
68 public final ValidationRuleBuilder forVersion(
69 String... version) {
70 Version[] versions = new Version[version.length];
71 for (int i = 0; i < versions.length; i++) {
72 versions[i] = Version.versionOf(version[i]);
73 }
74 return new ValidationRuleBuilder(getRules(), versions);
75 }
76
77 public final VersionExpressionBuilder forVersion() {
78 return new VersionExpressionBuilder();
79 }
80
81 public final ValidationRuleBuilder forAllVersions() {
82 return forVersion().all();
83 }
84
85
86
87
88 public class VersionExpressionBuilder {
89
90 public ValidationRuleBuilder all() {
91 return new ValidationRuleBuilder(getRules(), Version.values());
92 }
93
94 public ValidationRuleBuilder asOf(String version) {
95 return asOf(Version.versionOf(version));
96 }
97
98 public ValidationRuleBuilder asOf(Version version) {
99 return new ValidationRuleBuilder(getRules(), Version.asOf(version));
100 }
101
102 public ValidationRuleBuilder before(String version) {
103 return before(Version.versionOf(version));
104 }
105
106 public ValidationRuleBuilder before(Version version) {
107 return new ValidationRuleBuilder(getRules(), Version.before(version));
108 }
109
110 public ValidationRuleBuilder except(String... versions) {
111 Versionml#Version">Version[] v = new Version[versions.length];
112 for (int i = 0; i < versions.length; i++) {
113 v[i] = Version.versionOf(versions[i]);
114 }
115 return except(v);
116 }
117
118 public ValidationRuleBuilder except(Version... versions) {
119 return new ValidationRuleBuilder(getRules(), Version.except(versions));
120 }
121
122 }
123
124 }