diff options
Diffstat (limited to 'src/esieequest/controller/Utils.java')
-rw-r--r-- | src/esieequest/controller/Utils.java | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/esieequest/controller/Utils.java b/src/esieequest/controller/Utils.java index 139798c..d45f58c 100644 --- a/src/esieequest/controller/Utils.java +++ b/src/esieequest/controller/Utils.java | |||
@@ -1,40 +1,43 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.List; |
4 | 4 | ||
5 | import com.google.common.base.Joiner; | ||
6 | |||
7 | import esieequest.model.Text; | ||
8 | |||
9 | /** | ||
10 | * A set of custom utility methods. | ||
11 | * | ||
12 | * @author Pacien TRAN-GIRARD | ||
13 | */ | ||
5 | public class Utils { | 14 | public class Utils { |
6 | 15 | ||
7 | /** | 16 | /** |
17 | * Converts a List<String> into a String with a given prefix, suffix and | ||
18 | * placeholder used if the List is empty. | ||
8 | * | 19 | * |
9 | * @param elements | 20 | * @param list |
10 | * the elements | 21 | * the List to convert |
11 | * @param prefix | 22 | * @param prefix |
12 | * the prefix of the list | 23 | * the prefix |
13 | * @param emptyText | 24 | * @param empty |
14 | * the text that will be returned if the Set is empty | 25 | * the placeholder |
15 | * @return the list | 26 | * @param suffix |
27 | * the suffix | ||
28 | * @return the converted String | ||
16 | */ | 29 | */ |
17 | public static String list(final Set<String> elements, final String prefix, final String emptyText) { | 30 | public static String listToString(final List<String> list, final String prefix, final String empty, final String suffix) { |
18 | if (!elements.isEmpty()) { | 31 | final StringBuilder str = new StringBuilder(prefix); |
19 | return prefix + Utils.buildListString(elements) + "."; | ||
20 | } | ||
21 | return emptyText; | ||
22 | } | ||
23 | 32 | ||
24 | /** | 33 | if (list.isEmpty()) { |
25 | * Builds a list in the form of a String from a given Set. | 34 | str.append(empty); |
26 | * | 35 | } else { |
27 | * @param elements | 36 | str.append(Joiner.on(Text.LIST_SEPARATOR.getText()).join(list)); |
28 | * the Set of Strings | ||
29 | * | ||
30 | * @return the list | ||
31 | */ | ||
32 | private static String buildListString(final Set<String> elements) { | ||
33 | final StringBuilder list = new StringBuilder(); | ||
34 | for (final String string : elements) { | ||
35 | list.append(" ").append(string); | ||
36 | } | 37 | } |
37 | return list.toString(); | 38 | str.append(suffix); |
39 | |||
40 | return str.toString(); | ||
38 | } | 41 | } |
39 | 42 | ||
40 | } | 43 | } |