|
@@ -9,20 +9,17 @@ |
9 |
9 |
|
* template system that supports substitutions within any specific template by |
10 |
10 |
|
* "named" values. |
11 |
11 |
|
*/ |
12 |
|
- |
public class E13nData |
13 |
|
- |
{ |
|
12 |
+ |
public class E13nData { |
14 |
13 |
|
|
15 |
14 |
|
/** |
16 |
15 |
|
* Substitution Value w/ a flag indicating if it is User Data, or another |
17 |
16 |
|
* Template Id Code to be used as a Sub-Template. |
18 |
17 |
|
*/ |
19 |
|
- |
public static class SubstitutionValue |
20 |
|
- |
{ |
|
18 |
+ |
public static class SubstitutionValue { |
21 |
19 |
|
private final boolean userData; |
22 |
20 |
|
private final String value; |
23 |
21 |
|
|
24 |
|
- |
public SubstitutionValue( boolean userData, String value ) |
25 |
|
- |
{ |
|
22 |
+ |
public SubstitutionValue( boolean userData, String value ) { |
26 |
23 |
|
this.userData = userData; |
27 |
24 |
|
this.value = value; |
28 |
25 |
|
} |
|
@@ -31,22 +28,19 @@ |
31 |
28 |
|
* Flag indicating if the "value" is User Data, or another Template Id |
32 |
29 |
|
* Code to be used as a Sub-Template. |
33 |
30 |
|
*/ |
34 |
|
- |
public boolean isUserData() |
35 |
|
- |
{ |
|
31 |
+ |
public boolean isUserData() { |
36 |
32 |
|
return userData; |
37 |
33 |
|
} |
38 |
34 |
|
|
39 |
35 |
|
/** |
40 |
36 |
|
* User Data, or another Template Id Code to be used as a Sub-Template. |
41 |
37 |
|
*/ |
42 |
|
- |
public String getValue() |
43 |
|
- |
{ |
|
38 |
+ |
public String getValue() { |
44 |
39 |
|
return value; |
45 |
40 |
|
} |
46 |
41 |
|
|
47 |
42 |
|
@Override |
48 |
|
- |
public String toString() |
49 |
|
- |
{ |
|
43 |
+ |
public String toString() { |
50 |
44 |
|
return userData ? value : "{" + value + "}"; |
51 |
45 |
|
} |
52 |
46 |
|
} |
|
@@ -60,16 +54,13 @@ |
60 |
54 |
|
* |
61 |
55 |
|
* @param templateIdCode Template Identifying Code |
62 |
56 |
|
*/ |
63 |
|
- |
public E13nData( Object templateIdCode ) |
64 |
|
- |
{ |
|
57 |
+ |
public E13nData( Object templateIdCode ) { |
65 |
58 |
|
this.templateIdCode = Assert.noEmptyToString( "templateIdCode", templateIdCode ); |
66 |
59 |
|
} |
67 |
60 |
|
|
68 |
|
- |
private synchronized E13nData addPair( boolean userData, String name, String value ) |
69 |
|
- |
{ |
|
61 |
+ |
private synchronized E13nData addPair( boolean userData, String name, String value ) { |
70 |
62 |
|
name = Assert.noEmpty( "name", name ); |
71 |
|
- |
if ( templateSubstitutionNamedValues == null ) |
72 |
|
- |
{ |
|
63 |
+ |
if ( templateSubstitutionNamedValues == null ) { |
73 |
64 |
|
templateSubstitutionNamedValues = new HashMap<String, SubstitutionValue>(); |
74 |
65 |
|
} |
75 |
66 |
|
templateSubstitutionNamedValues.put( name, new SubstitutionValue( userData, value ) ); |
|
@@ -82,8 +73,7 @@ |
82 |
73 |
|
* @param name Not allowed to be empty |
83 |
74 |
|
* @param userData null converted to "" |
84 |
75 |
|
*/ |
85 |
|
- |
public E13nData addSubstitutionNamedUserData( String name, String userData ) |
86 |
|
- |
{ |
|
76 |
+ |
public E13nData addSubstitutionNamedUserData( String name, String userData ) { |
87 |
77 |
|
return addPair( true, name, StringUtils.deNull( userData ) ); |
88 |
78 |
|
} |
89 |
79 |
|
|
|
@@ -93,34 +83,29 @@ |
93 |
83 |
|
* @param name Not allowed to be empty |
94 |
84 |
|
* @param subTemplateIdCode Not allowed to be empty |
95 |
85 |
|
*/ |
96 |
|
- |
public E13nData addSubstitutionNamedSubTemplateIdCode( String name, String subTemplateIdCode ) |
97 |
|
- |
{ |
|
86 |
+ |
public E13nData addSubstitutionNamedSubTemplateIdCode( String name, String subTemplateIdCode ) { |
98 |
87 |
|
return addPair( false, name, Assert.noEmpty( "subTemplateIdCode", subTemplateIdCode ) ); |
99 |
88 |
|
} |
100 |
89 |
|
|
101 |
90 |
|
/** |
102 |
91 |
|
* @return Not Empty TemplateIdCode |
103 |
92 |
|
*/ |
104 |
|
- |
public String getTemplateIdCode() |
105 |
|
- |
{ |
|
93 |
+ |
public String getTemplateIdCode() { |
106 |
94 |
|
return templateIdCode; |
107 |
95 |
|
} |
108 |
96 |
|
|
109 |
97 |
|
/** |
110 |
98 |
|
* @return Not null map of Template Substitution Named Values |
111 |
99 |
|
*/ |
112 |
|
- |
public synchronized Map<String, SubstitutionValue> getTemplateSubstitutionNamedValues() |
113 |
|
- |
{ |
114 |
|
- |
if ( templateSubstitutionNamedValues == null ) |
115 |
|
- |
{ |
|
100 |
+ |
public synchronized Map<String, SubstitutionValue> getTemplateSubstitutionNamedValues() { |
|
101 |
+ |
if ( templateSubstitutionNamedValues == null ) { |
116 |
102 |
|
return Collections.emptyMap(); |
117 |
103 |
|
} |
118 |
104 |
|
return new HashMap<String, SubstitutionValue>( templateSubstitutionNamedValues ); // defensive copy for Thread Safety |
119 |
105 |
|
} |
120 |
106 |
|
|
121 |
107 |
|
@Override |
122 |
|
- |
public String toString() |
123 |
|
- |
{ |
|
108 |
+ |
public String toString() { |
124 |
109 |
|
return getTemplateIdCode() + getTemplateSubstitutionNamedValues(); |
125 |
110 |
|
} |
126 |
111 |
|
} |