- for (String data : new String[] { "test",
- "let's test some words", "" }) {
- int total = 0;
- for (String word : data.split((" "))) {
- total += word.replace("-", "").replace(" ", "")
- .length();
- }
- List<String> result = StringUtils.justifyText(data, 5,
- StringUtils.Alignment.LEFT);
-
- System.out.println("["+data+"] -> [");
-
- int totalResult = 0;
- for (String resultLine : result) {
- System.out.println(resultLine);
- for (String word : resultLine.split((" "))) {
- totalResult += word.replace("-", "")
- .replace(" ", "").length();
- }
- }
- System.out.println("]");
+ Map<String, Map<Integer, Entry<Alignment, List<String>>>> source = new HashMap<String, Map<Integer, Entry<Alignment, List<String>>>>();
+ addValue(source, Alignment.LEFT, "testy", -1, "testy");
+ addValue(source, Alignment.RIGHT, "testy", -1, "testy");
+ addValue(source, Alignment.CENTER, "testy", -1, "testy");
+ addValue(source, Alignment.JUSTIFY, "testy", -1, "testy");
+ addValue(source, Alignment.LEFT, "testy", 5, "testy");
+ addValue(source, Alignment.LEFT, "testy", 3, "te-", "sty");
+ addValue(source, Alignment.LEFT,
+ "Un petit texte qui se mettra sur plusieurs lignes",
+ 10, "Un petit", "texte qui", "se mettra", "sur",
+ "plusieurs", "lignes");
+ addValue(source, Alignment.LEFT,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ "Un", "petit", "texte", "qui se", "mettra", "sur",
+ "plusie-", "urs", "lignes");
+ addValue(source, Alignment.RIGHT,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ " Un", " petit", " texte", " qui se", " mettra",
+ " sur", "plusie-", " urs", " lignes");
+ addValue(source, Alignment.CENTER,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ " Un ", " petit ", " texte ", "qui se ", "mettra ",
+ " sur ", "plusie-", " urs ", "lignes ");
+ addValue(source, Alignment.JUSTIFY,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ "Un pet-", "it tex-", "te qui", "se met-", "tra sur",
+ "plusie-", "urs li-", "gnes");
+ addValue(source, Alignment.JUSTIFY,
+ "Un petit texte qui se mettra sur plusieurs lignes",
+ 14, "Un petit", "texte qui se",
+ "mettra sur", "plusieurs lig-", "nes");
+ addValue(source, Alignment.JUSTIFY, "le dash-test", 9,
+ "le dash-", "test");
+
+ for (String data : source.keySet()) {
+ for (int size : source.get(data).keySet()) {
+ Alignment align = source.get(data).get(size).getKey();
+ List<String> values = source.get(data).get(size)
+ .getValue();
+
+ List<String> result = StringUtils.justifyText(data,
+ size, align);