author | jgish |
Tue, 02 Apr 2013 18:41:04 -0400 | |
changeset 17181 | e3d13a15c5c0 |
child 17333 | 3cfbb50b9fb7 |
permissions | -rw-r--r-- |
17181
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
1 |
/* |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
2 |
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
4 |
* |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
8 |
* |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
13 |
* accompanied this code). |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
14 |
* |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
18 |
* |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
21 |
* questions. |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
22 |
*/ |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
23 |
/** |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
24 |
* @test |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
25 |
* @bug 5015163 7172553 |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
26 |
* @summary tests StringJoinerTest |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
27 |
* @run testng StringJoinerTest |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
28 |
* @author Jim Gish |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
29 |
*/ |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
30 |
import java.util.StringJoiner; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
31 |
import org.testng.annotations.Test; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
32 |
import static org.testng.Assert.assertEquals; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
33 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
34 |
@Test(groups = {"unit","string","util","libs"}) |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
35 |
public class StringJoinerTest { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
36 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
37 |
private static final String EMPTY = "EMPTY"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
38 |
private static final String ONE = "One"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
39 |
private static final int ONE_LEN = ONE.length(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
40 |
private static final String TWO = "Two"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
41 |
private static final int TWO_LEN = TWO.length(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
42 |
private static final String THREE = "Three"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
43 |
private static final String FOUR = "Four"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
44 |
private static final String FIVE = "Five"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
45 |
private static final String DASH = "-"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
46 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
47 |
/* Uncomment when we have streams |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
48 |
public void addAddAll() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
49 |
StringJoiner sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
50 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
51 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
52 |
ArrayList<String> nextOne = new ArrayList<>(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
53 |
nextOne.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
54 |
nextOne.add(THREE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
55 |
nextOne.stream().forEach(sj::add); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
56 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
57 |
String expected = "{"+ONE+DASH+TWO+DASH+THREE+"}"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
58 |
assertEquals(sj.toString(), expected); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
59 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
60 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
61 |
void addAlladd() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
62 |
StringJoiner sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
63 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
64 |
ArrayList<String> firstOne = new ArrayList<>(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
65 |
firstOne.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
66 |
firstOne.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
67 |
firstOne.stream().forEach(sj::add); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
68 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
69 |
sj.add(THREE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
70 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
71 |
String expected = "{"+ONE+DASH+TWO+DASH+THREE+"}"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
72 |
assertEquals(sj.toString(), expected); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
73 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
74 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
75 |
// The following tests do two successive adds of different types |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
76 |
public void addAlladdAll() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
77 |
StringJoiner sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
78 |
ArrayList<String> firstOne = new ArrayList<>(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
79 |
firstOne.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
80 |
firstOne.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
81 |
firstOne.add(THREE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
82 |
firstOne.stream().forEach(sj::add); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
83 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
84 |
ArrayList<String> nextOne = new ArrayList<>(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
85 |
nextOne.add(FOUR); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
86 |
nextOne.add(FIVE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
87 |
nextOne.stream().forEach(sj::add); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
88 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
89 |
String expected = "{"+ONE+DASH+TWO+DASH+THREE+DASH+FOUR+DASH+FIVE+"}"; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
90 |
assertEquals(sj.toString(), expected); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
91 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
92 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
93 |
public void testInto() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
94 |
ArrayList<String> list = new ArrayList<>(); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
95 |
list.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
96 |
list.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
97 |
list.add(THREE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
98 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
99 |
StringJoiner target = new StringJoiner(",", "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
100 |
assertEquals(target.toString(), "{" + ONE + "," + TWO + "," + THREE + |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
101 |
"}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
102 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
103 |
*/ |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
104 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
105 |
public void addCharSequence() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
106 |
StringJoiner sj = new StringJoiner(","); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
107 |
CharSequence cs_one = ONE; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
108 |
CharSequence cs_two = TWO; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
109 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
110 |
sj.add(cs_one); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
111 |
sj.add(cs_two); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
112 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
113 |
assertEquals(sj.toString(), ONE + "," + TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
114 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
115 |
sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
116 |
sj.add(cs_one); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
117 |
sj.add(cs_two); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
118 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
119 |
assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
120 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
121 |
StringBuilder builder = new StringBuilder(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
122 |
StringBuffer buffer = new StringBuffer(THREE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
123 |
sj = new StringJoiner(", ", "{ ", " }"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
124 |
sj.add(builder).add(buffer); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
125 |
builder.append(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
126 |
buffer.append(FOUR); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
127 |
assertEquals(sj.toString(), "{ " + ONE + ", " + THREE + " }", |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
128 |
"CharSequence is copied when add"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
129 |
sj.add(builder); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
130 |
assertEquals(sj.toString(), "{ " + ONE + ", " + THREE + ", " + ONE + |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
131 |
TWO + " }"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
132 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
133 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
134 |
public void addCharSequenceWithEmptyValue() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
135 |
StringJoiner sj = new StringJoiner(",").setEmptyValue(EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
136 |
CharSequence cs_one = ONE; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
137 |
CharSequence cs_two = TWO; |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
138 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
139 |
sj.add(cs_one); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
140 |
sj.add(cs_two); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
141 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
142 |
assertEquals(sj.toString(), ONE + "," + TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
143 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
144 |
sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
145 |
sj.add(cs_one); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
146 |
sj.add(cs_two); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
147 |
assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
148 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
149 |
sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
150 |
assertEquals(sj.toString(), "{}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
151 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
152 |
sj = new StringJoiner("=", "{", "}").setEmptyValue(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
153 |
assertEquals(sj.toString(), ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
154 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
155 |
sj = new StringJoiner(DASH, "{", "}").setEmptyValue(EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
156 |
assertEquals(sj.toString(), EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
157 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
158 |
sj.add(cs_one); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
159 |
sj.add(cs_two); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
160 |
assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
161 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
162 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
163 |
public void addString() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
164 |
StringJoiner sj = new StringJoiner(DASH); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
165 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
166 |
assertEquals(sj.toString(), ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
167 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
168 |
sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
169 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
170 |
assertEquals(sj.toString(), "{" + ONE + "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
171 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
172 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
173 |
assertEquals(sj.toString(), "{" + ONE + DASH + TWO + "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
174 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
175 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
176 |
public void lengthWithCustomEmptyValue() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
177 |
StringJoiner sj = new StringJoiner(DASH, "<", ">").setEmptyValue(EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
178 |
assertEquals(sj.length(), EMPTY.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
179 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
180 |
assertEquals(sj.length(), "<>".length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
181 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
182 |
assertEquals(sj.length(), "<->".length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
183 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
184 |
assertEquals(sj.length(), 4 + ONE_LEN); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
185 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
186 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
187 |
assertEquals(sj.length(), 5 + ONE_LEN + TWO_LEN); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
188 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
189 |
sj = new StringJoiner("||", "<", "-->"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
190 |
assertEquals(sj.length(), 4); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
191 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
192 |
sj.add("abcdef"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
193 |
assertEquals(sj.length(), 10); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
194 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
195 |
sj.add("xyz"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
196 |
assertEquals(sj.length(), 15); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
197 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
198 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
199 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
200 |
public void noAddAndEmptyValue() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
201 |
StringJoiner sj = new StringJoiner(DASH, "", "").setEmptyValue(EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
202 |
assertEquals(sj.toString(), EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
203 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
204 |
sj = new StringJoiner(DASH, "<..", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
205 |
assertEquals(sj.toString(), "<.."); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
206 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
207 |
sj = new StringJoiner(DASH, "<..", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
208 |
assertEquals(sj.toString(), "<.."); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
209 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
210 |
sj = new StringJoiner(DASH, "", "==>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
211 |
assertEquals(sj.toString(), "==>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
212 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
213 |
sj = new StringJoiner(DASH, "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
214 |
assertEquals(sj.toString(), "{}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
215 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
216 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
217 |
@Test(expectedExceptions = {NullPointerException.class}) |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
218 |
public void setEmptyValueNull() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
219 |
new StringJoiner(DASH, "{", "}").setEmptyValue(null); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
220 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
221 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
222 |
@Test(expectedExceptions = {NullPointerException.class}) |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
223 |
public void setDelimiterNull() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
224 |
new StringJoiner(null); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
225 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
226 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
227 |
@Test(expectedExceptions = {NullPointerException.class}) |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
228 |
public void setPrefixNull() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
229 |
new StringJoiner(DASH, null, "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
230 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
231 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
232 |
@Test(expectedExceptions = {NullPointerException.class}) |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
233 |
public void setSuffixNull() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
234 |
new StringJoiner(DASH, "{", null); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
235 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
236 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
237 |
public void stringFromtoString() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
238 |
StringJoiner sj = new StringJoiner(", "); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
239 |
assertEquals(sj.toString(), ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
240 |
sj = new StringJoiner(",", "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
241 |
assertEquals(sj.toString(), "{}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
242 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
243 |
sj = new StringJoiner(","); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
244 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
245 |
assertEquals(sj.toString(), ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
246 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
247 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
248 |
assertEquals(sj.toString(), ONE + "," + TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
249 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
250 |
sj = new StringJoiner(",", "{--", "--}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
251 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
252 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
253 |
assertEquals(sj.toString(), "{--" + ONE + "," + TWO + "--}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
254 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
255 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
256 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
257 |
public void stringFromtoStringWithEmptyValue() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
258 |
StringJoiner sj = new StringJoiner(" ", "", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
259 |
assertEquals(sj.toString(), ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
260 |
sj = new StringJoiner(", "); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
261 |
assertEquals(sj.toString(), ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
262 |
sj = new StringJoiner(",", "{", "}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
263 |
assertEquals(sj.toString(), "{}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
264 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
265 |
sj = new StringJoiner(",", "{", "}").setEmptyValue(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
266 |
assertEquals(sj.toString(), ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
267 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
268 |
sj = new StringJoiner(","); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
269 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
270 |
assertEquals(sj.toString(), ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
271 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
272 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
273 |
assertEquals(sj.toString(), ONE + "," + TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
274 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
275 |
sj = new StringJoiner(",", "{--", "--}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
276 |
sj.add(ONE); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
277 |
assertEquals(sj.toString(), "{--" + ONE + "--}" ); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
278 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
279 |
sj.add(TWO); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
280 |
assertEquals(sj.toString(), "{--" + ONE + "," + TWO + "--}"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
281 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
282 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
283 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
284 |
public void toStringWithCustomEmptyValue() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
285 |
StringJoiner sj = new StringJoiner(DASH, "<", ">").setEmptyValue(EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
286 |
assertEquals(sj.toString(), EMPTY); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
287 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
288 |
assertEquals(sj.toString(), "<>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
289 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
290 |
assertEquals(sj.toString(), "<->"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
291 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
292 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
293 |
private void testCombos(String infix, String prefix, String suffix) { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
294 |
StringJoiner sj = new StringJoiner(infix, prefix, suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
295 |
assertEquals(sj.toString(), prefix + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
296 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
297 |
// EmptyValue |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
298 |
sj = new StringJoiner(infix, prefix, suffix).setEmptyValue("<NONE>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
299 |
assertEquals(sj.toString(), "<NONE>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
300 |
assertEquals(sj.toString().length(), sj.length()); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
301 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
302 |
// empty in front |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
303 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
304 |
assertEquals(sj.toString(), prefix + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
305 |
// empty in middle |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
306 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
307 |
assertEquals(sj.toString(), prefix + infix + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
308 |
sj.add("1"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
309 |
assertEquals(sj.toString(), prefix + infix + infix + "1" + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
310 |
// empty at end |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
311 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
312 |
assertEquals(sj.toString(), prefix + infix + infix + "1" + infix + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
313 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
314 |
sj = new StringJoiner(infix, prefix, suffix).setEmptyValue("<NONE>"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
315 |
sj.add("1"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
316 |
assertEquals(sj.toString(), prefix + "1" + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
317 |
sj.add("2"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
318 |
assertEquals(sj.toString(), prefix + "1" + infix + "2" + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
319 |
sj.add(""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
320 |
assertEquals(sj.toString(), prefix + "1" + infix + "2" +infix + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
321 |
sj.add("3"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
322 |
assertEquals(sj.toString(), prefix + "1" + infix + "2" +infix + infix + "3" + suffix); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
323 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
324 |
|
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
325 |
public void testDelimiterCombinations() { |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
326 |
testCombos("", "", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
327 |
testCombos("", "<", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
328 |
testCombos("", "", ">"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
329 |
testCombos("", "<", ">"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
330 |
testCombos(",", "", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
331 |
testCombos(",", "<", ""); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
332 |
testCombos(",", "", ">"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
333 |
testCombos(",", "<", ">"); |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
334 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
335 |
} |
e3d13a15c5c0
5015163: (str) String merge/join that is the inverse of String.split()
jgish
parents:
diff
changeset
|
336 |