Commit a328210afeffd77e6801a1dc16514d9249acfa2b

Authored by Nathanael Jourdane
1 parent 168ebf31
Exists in master

Improve StringJoiner()

src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/StringJoiner.java
... ... @@ -16,71 +16,68 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.votable.utils;
18 18  
19   -import java.util.logging.Logger;
  19 +import java.util.List;
20 20  
21 21 /**
  22 + * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7
  23 + * compatibility.
  24 + *
22 25 * @author N. Jourdane
23 26 */
24   -public class Strings {
25   -
26   - /** The logger for the class Utils. */
27   - private static final Logger logger = Logger.getLogger(Strings.class.getName());
  27 +public class StringJoiner {
28 28  
  29 + /** The string joiner separator to put between each word, ie. ';'. */
  30 + private String separator;
29 31  
30   - /** Private constructor to hide the implicit public one. */
31   - private Strings() {
32   - }
  32 + /** The resulting string, ie. "foo;bar". */
  33 + private String string;
33 34  
34 35  
35 36 /**
36   - * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7
37   - * compatibility.
  37 + * Method constructor for the String joiner.
38 38 *
39   - * @author N. Jourdane
  39 + * @param separator The string joiner separator to put between each word, ie. ';'.
40 40 */
41   - public static class StringJoiner {
42   -
43   - /** The string joiner separator to put between each word, ie. ';'. */
44   - private String separator;
45   -
46   - /** The resulting string, ie. "foo;bar". */
47   - private String string;
  41 + public StringJoiner(String separator) {
  42 + this.separator = separator;
  43 + string = new String();
  44 + }
48 45  
  46 + public StringJoiner(String separator, List<String> list) {
  47 + this.separator = separator;
  48 + string = new String();
  49 + add(list);
  50 + }
49 51  
50   - /**
51   - * Method constructor for the String joiner.
52   - *
53   - * @param separator The string joiner separator to put between each word, ie. ';'.
54   - */
55   - public StringJoiner(String separator) {
56   - this.separator = separator;
57   - string = new String();
  52 + public void add(List<String> list) {
  53 + for (Object e : list) {
  54 + add(e.toString());
58 55 }
  56 + }
59 57  
60   - /**
61   - * Add a new word to the joiner.
62   - *
63   - * @param text The word to add.
64   - */
65   - public void add(String text) {
66   - if (string.isEmpty()) {
67   - string = text;
68   - } else {
69   - string += separator + text;
70   - }
  58 + /**
  59 + * Add a new word to the joiner.
  60 + *
  61 + * @param text The word to add.
  62 + */
  63 + public void add(String text) {
  64 + if (string.isEmpty()) {
  65 + string = text;
  66 + } else {
  67 + string += separator + text;
71 68 }
  69 + }
72 70  
73   - /**
74   - * @return true if the string joiner content is empty.
75   - */
76   - public boolean isEmpty() {
77   - return string.isEmpty();
78   - }
  71 + /**
  72 + * @return true if the string joiner content is empty.
  73 + */
  74 + public boolean isEmpty() {
  75 + return string.isEmpty();
  76 + }
79 77  
80   - @Override
81   - public String toString() {
82   - return string;
83   - }
  78 + @Override
  79 + public String toString() {
  80 + return string;
84 81 }
85 82  
86 83 }
... ...