From 8b89176a88ae8c834204d699fd9e61b867e6105d Mon Sep 17 00:00:00 2001 From: fitrh Date: Tue, 23 Nov 2021 23:39:36 +0800 Subject: [PATCH] feat(collection): add assignmen 6.1 placeholder file Assignment description: 1. Template Parser at #147 --- .../ip/syssrc/collection/TemplateParse.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/ip/syssrc/collection/TemplateParse.java diff --git a/src/main/java/ip/syssrc/collection/TemplateParse.java b/src/main/java/ip/syssrc/collection/TemplateParse.java new file mode 100644 index 00000000..70a89a64 --- /dev/null +++ b/src/main/java/ip/syssrc/collection/TemplateParse.java @@ -0,0 +1,50 @@ +package ip.syssrc.collection; + +/** + * TemplateParse + * + * Assignment 6.1 + * + * @author H071171512 - Fitrah Muhammad + * + */ +public class TemplateParse { + + public static void main(String[] args) { + String template = new String("The {alpha} {do} over the {animal}\n") + .concat("and feels as if {who} where in {where}\n") + .concat("of typography together with {with}.\n"); + + Map data = new HashMap<>(); + data.put("with", "Hermann Zapf"); + data.put("do", "jumps"); + data.put("alpha", "quick brown fox"); + data.put("animal", "lazy dog"); + data.put("where", "the seventh heaven"); + data.put("who", "he"); + + render(parse(template, data)); + } + + /** + * Replace all the placeholders in the template with the coreesponding values in + * the data + * + * @param template the string with placeholder, placeholder is a word inside + * curly braces e.g. {name}, a placeholder with "name" as key + * @param data the map of key-value, value is the data that will replace the + * placeholder in the template, key is a placeholder without + * curly braces. + * @return list of strings with parsed placeholder + */ + public static List parse(String template, Map data) { + return new ArrayList<>(); + } + + /** + * Print each element of template with new line + * + * @param template the list to be printed + **/ + public static void render(List template) {} +}