Skip to content

Commit 6b1a07e

Browse files
authored
chore: replace use of string.join for android 21 (#111)
* chore: replace ust of string.join for java6 back-compat * move eppo value test class and fix delimiter * patch bump
1 parent 48c4d3d commit 6b1a07e

File tree

4 files changed

+89
-16
lines changed

4 files changed

+89
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'cloud.eppo'
9-
version = '3.10.1-SNAPSHOT'
9+
version = '3.10.1'
1010
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1111

1212
java {

src/main/java/cloud/eppo/api/EppoValue.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloud.eppo.api;
22

33
import cloud.eppo.ufc.dto.EppoValueType;
4+
import java.util.Iterator;
45
import java.util.List;
56
import java.util.Objects;
67

@@ -101,7 +102,8 @@ public String toString() {
101102
case STRING:
102103
return this.stringValue;
103104
case ARRAY_OF_STRING:
104-
return String.join(" ,", this.stringArrayValue);
105+
// Android21 back-compatability
106+
return joinStringArray(this.stringArrayValue);
105107
case NULL:
106108
return "";
107109
default:
@@ -130,4 +132,21 @@ public boolean equals(Object otherObject) {
130132
public int hashCode() {
131133
return Objects.hash(type, boolValue, doubleValue, stringValue, stringArrayValue);
132134
}
135+
136+
/** This method is to allow for Android 21 support; String.join was introduced in API 26 */
137+
private static String joinStringArray(List<String> stringArray) {
138+
if (stringArray == null || stringArray.isEmpty()) {
139+
return "";
140+
}
141+
String delimiter = ", ";
142+
StringBuilder stringBuilder = new StringBuilder();
143+
Iterator<String> iterator = stringArray.iterator();
144+
while (iterator.hasNext()) {
145+
stringBuilder.append(iterator.next());
146+
if (iterator.hasNext()) {
147+
stringBuilder.append(delimiter);
148+
}
149+
}
150+
return stringBuilder.toString();
151+
}
133152
}

src/test/java/cloud/eppo/EppoValueTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cloud.eppo.api;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.ArrayList;
6+
import java.util.Arrays;
7+
import java.util.List;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class EppoValueTest {
11+
@Test
12+
public void testDoubleValue() {
13+
EppoValue eppoValue = EppoValue.valueOf(123.4567);
14+
assertEquals(123.4567, eppoValue.doubleValue(), 0.0);
15+
}
16+
17+
@Test
18+
public void testToStringWithStringArray() {
19+
// Test with multiple values
20+
List<String> values = Arrays.asList("one", "two", "three");
21+
EppoValue value = EppoValue.valueOf(values);
22+
assertEquals("one, two, three", value.toString());
23+
24+
// Test with single value
25+
List<String> singleValue = Arrays.asList("solo");
26+
EppoValue singleValueObj = EppoValue.valueOf(singleValue);
27+
assertEquals("solo", singleValueObj.toString());
28+
29+
// Test with empty list
30+
List<String> emptyList = new ArrayList<>();
31+
EppoValue emptyValue = EppoValue.valueOf(emptyList);
32+
assertEquals("", emptyValue.toString());
33+
}
34+
35+
@Test
36+
public void testStringArrayJoining() {
37+
// Test joining behavior with various arrays
38+
List<String> values = Arrays.asList("a", "b", "c");
39+
EppoValue value = EppoValue.valueOf(values);
40+
assertEquals("a, b, c", value.toString());
41+
42+
// Test with values containing the delimiter
43+
List<String> commaValues = Arrays.asList("first,item", "second ,item");
44+
EppoValue commaValue = EppoValue.valueOf(commaValues);
45+
assertEquals("first,item, second ,item", commaValue.toString());
46+
}
47+
48+
@Test
49+
public void testToStringConsistencyAcrossTypes() {
50+
// Verify string representation is consistent across types
51+
EppoValue boolValue = EppoValue.valueOf(true);
52+
assertEquals("true", boolValue.toString());
53+
54+
EppoValue numValue = EppoValue.valueOf(42.5);
55+
assertEquals("42.5", numValue.toString());
56+
57+
EppoValue strValue = EppoValue.valueOf("test");
58+
assertEquals("test", strValue.toString());
59+
60+
EppoValue nullValue = EppoValue.nullValue();
61+
assertEquals("", nullValue.toString());
62+
63+
// String array should now use our custom joiner
64+
List<String> array = Arrays.asList("test1", "test2");
65+
EppoValue arrayValue = EppoValue.valueOf(array);
66+
assertEquals("test1, test2", arrayValue.toString());
67+
}
68+
}

0 commit comments

Comments
 (0)