From 7fc9167a33d773b0859774f94a1fd999175d5fc7 Mon Sep 17 00:00:00 2001 From: DanMB Date: Tue, 5 Jul 2022 11:25:02 -0400 Subject: [PATCH] Update manifold --- build.gradle | 4 +- .../extensions/java/lang/String/XString.java | 40 +++++++++++++++++++ .../arcane/amulet/test/unit/SugarTests.java | 10 +++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 891481a..b7de6f4 100644 --- a/build.gradle +++ b/build.gradle @@ -54,8 +54,8 @@ dependencies { implementation 'systems.manifold:manifold-rt:2022.1.18' implementation 'com.google.dagger:dagger:2.40.1' implementation 'org.reflections:reflections:0.10.2' - api 'systems.manifold:manifold-rt:2022.1.14' - api 'systems.manifold:manifold-ext-rt:2022.1.14' + api 'systems.manifold:manifold-rt:2022.1.18' + api 'systems.manifold:manifold-ext-rt:2022.1.18' api 'it.unimi.dsi:fastutil:8.5.8' api 'com.google.guava:guava:31.1-jre' api 'org.apache.commons:commons-lang3:3.12.0' diff --git a/src/main/java/Amulet/extensions/java/lang/String/XString.java b/src/main/java/Amulet/extensions/java/lang/String/XString.java index f55d0d2..07c3d44 100644 --- a/src/main/java/Amulet/extensions/java/lang/String/XString.java +++ b/src/main/java/Amulet/extensions/java/lang/String/XString.java @@ -74,6 +74,46 @@ public static String lower(@This String s) { return s.toLowerCase(Locale.ROOT); } + public static double toDouble(@This String s) { + return Double.parseDouble(s); + } + public static double toDouble(@This String s, double or) { + try{ + return toDouble(s); + } + + catch(NumberFormatException e){ + return or; + } + } + + public static int toInt(@This String s) { + return Integer.parseInt(s); + } + public static int toInt(@This String s, int or) { + try{ + return toInt(s); + } + + catch(NumberFormatException e){ + return or; + } + } + + public static long toLong(@This String s) { + return Long.parseLong(s); + } + public static long toLong(@This String s, long or) { + try{ + return toLong(s); + } + + catch(NumberFormatException e){ + return or; + } + } + + public static String replaceAbs(@This String s, String find, String replace) { return s.replaceAll("\\Q" + find + "\\E", replace); } diff --git a/src/test/java/art/arcane/amulet/test/unit/SugarTests.java b/src/test/java/art/arcane/amulet/test/unit/SugarTests.java index a0f4892..1669ea3 100644 --- a/src/test/java/art/arcane/amulet/test/unit/SugarTests.java +++ b/src/test/java/art/arcane/amulet/test/unit/SugarTests.java @@ -20,6 +20,9 @@ import art.arcane.amulet.MagicalSugar; import art.arcane.amulet.geometry.Vec; +import art.arcane.amulet.io.nbt.nbt.tag.CompoundTag; +import art.arcane.amulet.io.nbt.objects.NBTObjectSerializer; +import art.arcane.amulet.io.nbt.objects.UnserializableClassException; import art.arcane.amulet.range.IntegerRange; import manifold.ext.rt.RuntimeMethods; import org.junit.jupiter.api.Assertions; @@ -40,6 +43,13 @@ public void testTime() { assertEquals(TimeUnit.SECONDS.toMillis(30) + TimeUnit.MINUTES.toMillis(25), 30seconds + (25minutes)); } + @Test + public void testParsing() { + assertEquals(5.774, "5.774".toDouble()); + assertEquals(-1, "xxx".toInt(-1)); + assertEquals(7L, "7".toLong()); + } + @SuppressWarnings("ConstantConditions") @Test public void testNullSafe() {