From dbf6a329a65d88f14c171da34a887299abfb4ccb Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 15 Apr 2010 10:15:03 +0000 Subject: [PATCH] LMS-1485 add getPlaceholderNames() SVN: 15478 --- .../java/ch/systemsx/cisd/common/utilities/Template.java | 9 +++++++++ .../ch/systemsx/cisd/common/utilities/TemplateTest.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/Template.java b/common/source/java/ch/systemsx/cisd/common/utilities/Template.java index 022316d8f55..f4643284399 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/Template.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/Template.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * A little template engine. Usage example: @@ -280,6 +281,14 @@ public class Template } return new Template(map, list); } + + /** + * Returns all placeholder names. + */ + public Set<String> getPlaceholderNames() + { + return variableTokens.keySet(); + } /** * Binds the specified value to the specified placeholder name. diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java index a7ff8c04a8c..087d19c2bc2 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java @@ -19,6 +19,8 @@ package ch.systemsx.cisd.common.utilities; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.fail; +import java.util.Set; + import org.testng.annotations.Test; /** @@ -53,6 +55,7 @@ public class TemplateTest { Template template = new Template("hello ${name}${name}"); template.bind("name", "world"); + assertEquals(1, template.getPlaceholderNames().size()); assertEquals("hello worldworld", template.createText()); } @@ -62,6 +65,10 @@ public class TemplateTest Template template = new Template("hello ${name}, do you know ${name2}?"); template.bind("name", "world"); template.bind("name2", "Albert Einstein"); + Set<String> placeholderNames = template.getPlaceholderNames(); + assertEquals(true, placeholderNames.contains("name")); + assertEquals(true, placeholderNames.contains("name2")); + assertEquals(2, placeholderNames.size()); assertEquals("hello world, do you know Albert Einstein?", template.createText()); } -- GitLab