Skip to content
Snippets Groups Projects
Commit dbf6a329 authored by felmer's avatar felmer
Browse files

LMS-1485 add getPlaceholderNames()

SVN: 15478
parent 2e0b6eae
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import java.util.ArrayList; ...@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* A little template engine. Usage example: * A little template engine. Usage example:
...@@ -280,6 +281,14 @@ public class Template ...@@ -280,6 +281,14 @@ public class Template
} }
return new Template(map, list); 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. * Binds the specified value to the specified placeholder name.
......
...@@ -19,6 +19,8 @@ package ch.systemsx.cisd.common.utilities; ...@@ -19,6 +19,8 @@ package ch.systemsx.cisd.common.utilities;
import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail; import static org.testng.AssertJUnit.fail;
import java.util.Set;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
...@@ -53,6 +55,7 @@ public class TemplateTest ...@@ -53,6 +55,7 @@ public class TemplateTest
{ {
Template template = new Template("hello ${name}${name}"); Template template = new Template("hello ${name}${name}");
template.bind("name", "world"); template.bind("name", "world");
assertEquals(1, template.getPlaceholderNames().size());
assertEquals("hello worldworld", template.createText()); assertEquals("hello worldworld", template.createText());
} }
...@@ -62,6 +65,10 @@ public class TemplateTest ...@@ -62,6 +65,10 @@ public class TemplateTest
Template template = new Template("hello ${name}, do you know ${name2}?"); Template template = new Template("hello ${name}, do you know ${name2}?");
template.bind("name", "world"); template.bind("name", "world");
template.bind("name2", "Albert Einstein"); 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()); assertEquals("hello world, do you know Albert Einstein?", template.createText());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment