@@ -45,24 +45,29 @@ public interface Example {
4545 public static void main (String [] args ) {
4646 execute ("Math Service 1" , Examples ::mathService1 );
4747 execute ("Math Service 2" , Examples ::mathService2 );
48+
4849 execute ("JSON Encoder" , Examples ::jsonEncoder );
4950 execute ("Text Encoder" , Examples ::textEncoder );
5051 execute ("CSV Encoder" , Examples ::csvEncoder );
52+
5153 execute ("Template Encoder" , Examples ::templateEncoder );
52- execute ("Adapt Bean" , Examples ::adaptBean );
53- execute ("Coerce Bean" , Examples ::coerceBean );
54- execute ("Interface Proxy" , Examples ::interfaceProxy );
55- execute ("Required Property 1" , Examples ::requiredProperty1 );
56- execute ("Required Property 2" , Examples ::requiredProperty2 );
57- execute ("Element Adapter" , Examples ::elementAdapter );
58- execute ("Collections" , Examples ::collections );
5954 execute ("Variables" , Examples ::variables );
6055 execute ("Repeating Sections" , Examples ::repeatingSections );
6156 execute ("Conditional Sections" , Examples ::conditionalSections );
6257 execute ("Inverted Sections" , Examples ::invertedSections );
6358 execute ("Resources" , Examples ::resources );
6459 execute ("Includes" , Examples ::includes );
6560 execute ("Comments" , Examples ::comments );
61+
62+ execute ("Adapt Bean" , Examples ::adaptBean );
63+ execute ("Coerce Bean" , Examples ::coerceBean );
64+ execute ("Interface Proxy" , Examples ::interfaceProxy );
65+ execute ("Required Property 1" , Examples ::requiredProperty1 );
66+ execute ("Required Property 2" , Examples ::requiredProperty2 );
67+
68+ execute ("Element Adapter" , Examples ::elementAdapter );
69+
70+ execute ("Collections" , Examples ::collections );
6671 }
6772
6873 private static void execute (String label , Example example ) {
@@ -164,6 +169,55 @@ public static void templateEncoder() throws Exception {
164169 templateEncoder .write (map , System .out );
165170 }
166171
172+ public static void variables () throws IOException {
173+ templateExample ("variables" );
174+ }
175+
176+ public static void repeatingSections () throws IOException {
177+ templateExample ("repeating-sections" );
178+ }
179+
180+ public static void conditionalSections () throws IOException {
181+ templateExample ("conditional-sections" );
182+ }
183+
184+ public static void invertedSections () throws IOException {
185+ templateExample ("inverted-sections" );
186+ }
187+
188+ public static void resources () throws IOException {
189+ templateExample ("resources" );
190+ }
191+
192+ public static void includes () throws IOException {
193+ templateExample ("includes" );
194+ }
195+
196+ public static void comments () throws IOException {
197+ templateExample ("comments" );
198+ }
199+
200+ private static void templateExample (String name ) throws IOException {
201+ var jsonDecoder = new JSONDecoder ();
202+
203+ Object dictionary ;
204+ try (var inputStream = Examples .class .getResourceAsStream (String .format ("%s.json" , name ))) {
205+ dictionary = jsonDecoder .read (new InputStreamReader (inputStream ));
206+ }
207+
208+ var templateEncoder = new TemplateEncoder (Examples .class , String .format ("%s.html" , name ));
209+
210+ try {
211+ var resourceBundle = ResourceBundle .getBundle (String .format ("%s.%s" , Examples .class .getPackageName (), name ));
212+
213+ templateEncoder .setResourceBundle (resourceBundle );
214+ } catch (MissingResourceException exception ) {
215+ // No-op
216+ }
217+
218+ templateEncoder .write (dictionary , System .out );
219+ }
220+
167221 public static void adaptBean () {
168222 var course = new Course ();
169223
@@ -282,53 +336,4 @@ public static void collections() {
282336
283337 System .out .println (set .contains ("a" )); // true
284338 }
285-
286- public static void variables () throws IOException {
287- templateExample ("variables" );
288- }
289-
290- public static void repeatingSections () throws IOException {
291- templateExample ("repeating-sections" );
292- }
293-
294- public static void conditionalSections () throws IOException {
295- templateExample ("conditional-sections" );
296- }
297-
298- public static void invertedSections () throws IOException {
299- templateExample ("inverted-sections" );
300- }
301-
302- public static void resources () throws IOException {
303- templateExample ("resources" );
304- }
305-
306- public static void includes () throws IOException {
307- templateExample ("includes" );
308- }
309-
310- public static void comments () throws IOException {
311- templateExample ("comments" );
312- }
313-
314- private static void templateExample (String name ) throws IOException {
315- var jsonDecoder = new JSONDecoder ();
316-
317- Object dictionary ;
318- try (var inputStream = Examples .class .getResourceAsStream (String .format ("%s.json" , name ))) {
319- dictionary = jsonDecoder .read (new InputStreamReader (inputStream ));
320- }
321-
322- var templateEncoder = new TemplateEncoder (Examples .class , String .format ("%s.html" , name ));
323-
324- try {
325- var resourceBundle = ResourceBundle .getBundle (String .format ("%s.%s" , Examples .class .getPackageName (), name ));
326-
327- templateEncoder .setResourceBundle (resourceBundle );
328- } catch (MissingResourceException exception ) {
329- // No-op
330- }
331-
332- templateEncoder .write (dictionary , System .out );
333- }
334339}
0 commit comments