Get rid of Guava

This commit is contained in:
MM20
2025-02-10 20:41:40 +01:00
parent bbb50e6e5e
commit 8d1800b95b
5 changed files with 21 additions and 12 deletions
+1 -1
View File
@@ -35,8 +35,8 @@ android {
}
dependencies {
implementation(libs.bundles.kotlin)
implementation(libs.jackson.core)
implementation(libs.jackson.dataformat.yaml)
implementation(libs.guava)
implementation(libs.mustache.compiler)
}
@@ -0,0 +1,11 @@
package org.woheller69.AndroidAddressFormatter
/**
* Make Kotlin functions accessible from Java.
*/
internal object Kt {
@JvmStatic
inline fun toIntOrNull(string: String): Int? {
return string.toIntOrNull()
}
}
@@ -8,7 +8,6 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.mustachejava.*;
import com.google.common.primitives.Ints;
import java.io.IOException;
import java.io.StringWriter;
import java.io.StringReader;
@@ -21,7 +20,6 @@ import java.util.HashMap;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Function;
import com.google.common.base.CaseFormat;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
@@ -100,7 +98,7 @@ public class OsmAddressFormatter {
for (Map.Entry<String, Object> entry : components.entrySet()) {
String field = entry.getKey();
Object value = entry.getValue();
String newField = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field);
String newField = lowerCamelToUnderscore(field);
if (!normalizedComponents.containsKey(newField)) {
normalizedComponents.put(newField, value);
}
@@ -108,6 +106,13 @@ public class OsmAddressFormatter {
return normalizedComponents;
}
private String lowerCamelToUnderscore(String input) {
Pattern pattern = Pattern.compile("([a-z])([A-Z])");
Matcher matcher = pattern.matcher(input);
String result = matcher.replaceAll("$1_$2");
return result.toLowerCase();
}
Map<String, Object> determineCountryCode(Map<String, Object> components,
String fallbackCountryCode) {
String countryCode;
@@ -194,7 +199,7 @@ public class OsmAddressFormatter {
Object country = components.get("country");
Object state = components.get("state");
if (country != null && state != null && Ints.tryParse((String) country) != null) {
if (country != null && state != null && Kt.toIntOrNull((String) country) != null) {
components.put("country", state);
components.remove("state");
}