Skip to content

Commit b97a018

Browse files
authored
chore: Remove dependency on Gson (#7)
* chore: Remove dependency on Gson * bump major version * minor cleanup * move more android tests * spotless
1 parent 800f0fb commit b97a018

22 files changed

+1691
-439
lines changed

build.gradle

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

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

1212
dependencies {
13-
// TODO: Consolidate these into a single JSON parsing dependency
14-
// For RAC DTOs
1513
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
16-
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.1'
17-
implementation 'com.fasterxml.jackson.module:jackson-module-parameter-names:2.17.1'
1814
// For UFC DTOs
1915
implementation 'commons-codec:commons-codec:1.17.0'
20-
implementation "com.google.code.gson:gson:2.9.1"
2116
implementation 'org.slf4j:slf4j-api:2.0.13'
2217
testImplementation platform('org.junit:junit-bom:5.10.2')
2318
testImplementation 'org.junit.jupiter:junit-jupiter'

src/main/java/cloud/eppo/Utils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cloud.eppo;
22

3-
import com.google.gson.JsonElement;
3+
import com.fasterxml.jackson.databind.JsonNode;
44
import java.math.BigInteger;
55
import java.security.MessageDigest;
66
import java.security.NoSuchAlgorithmException;
@@ -13,7 +13,7 @@
1313
import org.slf4j.LoggerFactory;
1414

1515
public final class Utils {
16-
private static final SimpleDateFormat isoUtcDateFormat = buildUtcIsoDateFormat();
16+
private static final SimpleDateFormat UTC_ISO_DATE_FORMAT = buildUtcIsoDateFormat();
1717
private static final Logger log = LoggerFactory.getLogger(Utils.class);
1818

1919
public static String getMD5Hex(String input) {
@@ -33,14 +33,14 @@ public static String getMD5Hex(String input) {
3333
return hashText.toString();
3434
}
3535

36-
public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
37-
if (isoDateStringElement == null || isoDateStringElement.isJsonNull()) {
36+
public static Date parseUtcISODateElement(JsonNode isoDateStringElement) {
37+
if (isoDateStringElement == null || isoDateStringElement.isNull()) {
3838
return null;
3939
}
40-
String isoDateString = isoDateStringElement.getAsString();
40+
String isoDateString = isoDateStringElement.asText();
4141
Date result = null;
4242
try {
43-
result = isoUtcDateFormat.parse(isoDateString);
43+
result = UTC_ISO_DATE_FORMAT.parse(isoDateString);
4444
} catch (ParseException e) {
4545
// We expect to fail parsing if the date is base 64 encoded
4646
// Thus we'll leave the result null for now and try again with the decoded value
@@ -50,7 +50,7 @@ public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
5050
// Date may be encoded
5151
String decodedIsoDateString = base64Decode(isoDateString);
5252
try {
53-
result = isoUtcDateFormat.parse(decodedIsoDateString);
53+
result = UTC_ISO_DATE_FORMAT.parse(decodedIsoDateString);
5454
} catch (ParseException e) {
5555
log.warn("Date \"{}\" not in ISO date format", isoDateString);
5656
}
@@ -60,7 +60,7 @@ public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
6060
}
6161

6262
public static String getISODate(Date date) {
63-
return isoUtcDateFormat.format(date);
63+
return UTC_ISO_DATE_FORMAT.format(date);
6464
}
6565

6666
public static String base64Decode(String input) {

src/main/java/cloud/eppo/ufc/dto/FlagConfig.java

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,49 @@
44
import java.util.Map;
55

66
public class FlagConfig {
7-
private String key;
8-
9-
private boolean enabled;
10-
11-
private int totalShards;
12-
13-
private VariationType variationType;
14-
15-
private Map<String, Variation> variations;
16-
17-
private List<Allocation> allocations;
7+
private final String key;
8+
private final boolean enabled;
9+
private final int totalShards;
10+
private final VariationType variationType;
11+
private final Map<String, Variation> variations;
12+
private final List<Allocation> allocations;
13+
14+
public FlagConfig(
15+
String key,
16+
boolean enabled,
17+
int totalShards,
18+
VariationType variationType,
19+
Map<String, Variation> variations,
20+
List<Allocation> allocations) {
21+
this.key = key;
22+
this.enabled = enabled;
23+
this.totalShards = totalShards;
24+
this.variationType = variationType;
25+
this.variations = variations;
26+
this.allocations = allocations;
27+
}
1828

1929
public String getKey() {
2030
return this.key;
2131
}
2232

23-
public void setKey(String key) {
24-
this.key = key;
25-
}
26-
2733
public int getTotalShards() {
2834
return totalShards;
2935
}
3036

31-
public void setTotalShards(int totalShards) {
32-
this.totalShards = totalShards;
33-
}
34-
3537
public boolean isEnabled() {
3638
return enabled;
3739
}
3840

39-
public void setEnabled(boolean enabled) {
40-
this.enabled = enabled;
41-
}
42-
4341
public VariationType getVariationType() {
4442
return variationType;
4543
}
4644

47-
public void setVariationType(VariationType variationType) {
48-
this.variationType = variationType;
49-
}
50-
5145
public Map<String, Variation> getVariations() {
5246
return variations;
5347
}
5448

55-
public void setVariations(Map<String, Variation> variations) {
56-
this.variations = variations;
57-
}
58-
5949
public List<Allocation> getAllocations() {
6050
return allocations;
6151
}
62-
63-
public void setAllocations(List<Allocation> allocations) {
64-
this.allocations = allocations;
65-
}
6652
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package cloud.eppo.ufc.dto;
22

33
import java.util.Map;
4+
import java.util.concurrent.ConcurrentHashMap;
45

56
public class FlagConfigResponse {
6-
private Map<String, FlagConfig> flags;
7+
private final Map<String, FlagConfig> flags;
78

8-
public Map<String, FlagConfig> getFlags() {
9-
return this.flags;
9+
public FlagConfigResponse(Map<String, FlagConfig> flags) {
10+
this.flags = flags;
1011
}
1112

12-
public void setFlags(Map<String, FlagConfig> flags) {
13-
this.flags = flags;
13+
public FlagConfigResponse() {
14+
this(new ConcurrentHashMap<>());
15+
}
16+
17+
public Map<String, FlagConfig> getFlags() {
18+
return this.flags;
1419
}
1520
}

src/main/java/cloud/eppo/ufc/dto/Shard.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
import java.util.Set;
55

66
public class Shard {
7-
private String salt;
8-
private Set<ShardRange> ranges;
7+
private final String salt;
8+
private final Set<ShardRange> ranges;
99

10-
public String getSalt() {
11-
return salt;
10+
public Shard(String salt, Set<ShardRange> ranges) {
11+
this.salt = salt;
12+
this.ranges = ranges;
1213
}
1314

14-
public void setSalt(String salt) {
15-
this.salt = salt;
15+
public String getSalt() {
16+
return salt;
1617
}
1718

1819
public Set<ShardRange> getRanges() {
1920
return ranges;
2021
}
21-
22-
public void setRanges(Set<ShardRange> ranges) {
23-
this.ranges = ranges;
24-
}
2522
}

src/main/java/cloud/eppo/ufc/dto/Split.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,25 @@
44
import java.util.Set;
55

66
public class Split {
7+
private final String variationKey;
8+
private final Set<Shard> shards;
9+
private final Map<String, String> extraLogging;
710

8-
private String variationKey;
9-
10-
private Set<Shard> shards;
11-
12-
private Map<String, String> extraLogging;
11+
public Split(String variationKey, Set<Shard> shards, Map<String, String> extraLogging) {
12+
this.variationKey = variationKey;
13+
this.shards = shards;
14+
this.extraLogging = extraLogging;
15+
}
1316

1417
public String getVariationKey() {
1518
return variationKey;
1619
}
1720

18-
public void setVariationKey(String variationKey) {
19-
this.variationKey = variationKey;
20-
}
21-
2221
public Set<Shard> getShards() {
2322
return shards;
2423
}
2524

26-
public void setShards(Set<Shard> shards) {
27-
this.shards = shards;
28-
}
29-
3025
public Map<String, String> getExtraLogging() {
3126
return extraLogging;
3227
}
33-
34-
public void setExtraLogging(Map<String, String> extraLogging) {
35-
this.extraLogging = extraLogging;
36-
}
3728
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
package cloud.eppo.ufc.dto;
22

33
public class TargetingCondition {
4-
private OperatorType operator;
4+
private final OperatorType operator;
5+
private final String attribute;
6+
private final EppoValue value;
57

6-
private String attribute;
7-
8-
private EppoValue value;
8+
public TargetingCondition(OperatorType operator, String attribute, EppoValue value) {
9+
this.operator = operator;
10+
this.attribute = attribute;
11+
this.value = value;
12+
}
913

1014
public OperatorType getOperator() {
1115
return operator;
1216
}
1317

14-
public void setOperator(OperatorType operatorType) {
15-
this.operator = operatorType;
16-
}
17-
1818
public String getAttribute() {
1919
return attribute;
2020
}
2121

22-
public void setAttribute(String attribute) {
23-
this.attribute = attribute;
24-
}
25-
2622
public EppoValue getValue() {
2723
return value;
2824
}
29-
30-
public void setValue(EppoValue value) {
31-
this.value = value;
32-
}
3325
}

src/main/java/cloud/eppo/ufc/dto/TargetingRule.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import java.util.Set;
44

55
public class TargetingRule {
6+
private final Set<TargetingCondition> conditions;
67

7-
private Set<TargetingCondition> conditions;
8+
public TargetingRule(Set<TargetingCondition> conditions) {
9+
this.conditions = conditions;
10+
}
811

912
public Set<TargetingCondition> getConditions() {
1013
return conditions;
1114
}
12-
13-
public void setConditions(Set<TargetingCondition> conditions) {
14-
this.conditions = conditions;
15-
}
1615
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
package cloud.eppo.ufc.dto;
22

33
public class Variation {
4+
private final String key;
5+
private final EppoValue value;
46

5-
private String key;
6-
7-
private EppoValue value;
7+
public Variation(String key, EppoValue value) {
8+
this.key = key;
9+
this.value = value;
10+
}
811

912
public String getKey() {
1013
return this.key;
1114
}
1215

13-
public void setKey(String key) {
14-
this.key = key;
15-
}
16-
1716
public EppoValue getValue() {
1817
return value;
1918
}
20-
21-
public void setValue(EppoValue value) {
22-
this.value = value;
23-
}
2419
}

src/main/java/cloud/eppo/ufc/dto/adapters/DateAdapter.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)