Get rid of Guava

This commit is contained in:
MM20 2025-02-10 20:41:40 +01:00
parent bbb50e6e5e
commit 8d1800b95b
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 21 additions and 12 deletions

View File

@ -84,11 +84,6 @@ android {
} }
} }
} }
configurations.all {
//Fixes Error: Duplicate class: com.google.common.util.concurrent.ListenableFuture
exclude(group = "com.google.guava", module = "listenablefuture")
exclude(group = "org.apache.httpcomponents", module = "httpclient")
}
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8

View File

@ -1,6 +1,5 @@
[versions] [versions]
mustache = "0.9.7" mustache = "0.9.7"
guava = "33.1.0-android"
jacksonCore = "2.12.7" jacksonCore = "2.12.7"
jacksonDataformatYaml = "2.12.7" jacksonDataformatYaml = "2.12.7"
minSdk = "26" minSdk = "26"
@ -49,7 +48,6 @@ osmOpeningHours = "0.1.0"
mustache-compiler = { module = "com.github.spullara.mustache.java:compiler", version.ref = "mustache" } mustache-compiler = { module = "com.github.spullara.mustache.java:compiler", version.ref = "mustache" }
gradle = { group = "com.android.tools.build", name = "gradle", version.ref = "android-gradle-plugin" } gradle = { group = "com.android.tools.build", name = "gradle", version.ref = "android-gradle-plugin" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jacksonCore" } jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jacksonCore" }
jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jacksonDataformatYaml" } jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jacksonDataformatYaml" }
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" } kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }

View File

@ -35,8 +35,8 @@ android {
} }
dependencies { dependencies {
implementation(libs.bundles.kotlin)
implementation(libs.jackson.core) implementation(libs.jackson.core)
implementation(libs.jackson.dataformat.yaml) implementation(libs.jackson.dataformat.yaml)
implementation(libs.guava)
implementation(libs.mustache.compiler) implementation(libs.mustache.compiler)
} }

View File

@ -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()
}
}

View File

@ -8,7 +8,6 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.type.MapType; import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.mustachejava.*; import com.github.mustachejava.*;
import com.google.common.primitives.Ints;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.StringReader; import java.io.StringReader;
@ -21,7 +20,6 @@ import java.util.HashMap;
import java.util.Spliterator; import java.util.Spliterator;
import java.util.Spliterators; import java.util.Spliterators;
import java.util.function.Function; import java.util.function.Function;
import com.google.common.base.CaseFormat;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -100,7 +98,7 @@ public class OsmAddressFormatter {
for (Map.Entry<String, Object> entry : components.entrySet()) { for (Map.Entry<String, Object> entry : components.entrySet()) {
String field = entry.getKey(); String field = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
String newField = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field); String newField = lowerCamelToUnderscore(field);
if (!normalizedComponents.containsKey(newField)) { if (!normalizedComponents.containsKey(newField)) {
normalizedComponents.put(newField, value); normalizedComponents.put(newField, value);
} }
@ -108,6 +106,13 @@ public class OsmAddressFormatter {
return normalizedComponents; 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, Map<String, Object> determineCountryCode(Map<String, Object> components,
String fallbackCountryCode) { String fallbackCountryCode) {
String countryCode; String countryCode;
@ -194,7 +199,7 @@ public class OsmAddressFormatter {
Object country = components.get("country"); Object country = components.get("country");
Object state = components.get("state"); 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.put("country", state);
components.remove("state"); components.remove("state");
} }