aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxander <xander@isxander.dev>2022-09-01 20:23:00 +0100
committerxander <xander@isxander.dev>2022-09-01 20:23:00 +0100
commitf46fc1e9d85d555cd557eefa10e1211f9ad1ceb1 (patch)
tree123fa86dcf4f27a63f0398ca4726e5876f5d04a2 /src
parent627c45bd6cfa7cce9e048d7681029c812a45f1cc (diff)
downloadYetAnotherConfigLib-f46fc1e9d85d555cd557eefa10e1211f9ad1ceb1.tar.gz
YetAnotherConfigLib-f46fc1e9d85d555cd557eefa10e1211f9ad1ceb1.tar.bz2
YetAnotherConfigLib-f46fc1e9d85d555cd557eefa10e1211f9ad1ceb1.zip
CI stuff
rename binding functions and format numbers with commas
Diffstat (limited to 'src')
-rw-r--r--src/main/java/dev/isxander/yacl/api/Binding.java4
-rw-r--r--src/main/java/dev/isxander/yacl/api/Option.java4
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java2
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java2
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java3
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java3
-rw-r--r--src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java38
7 files changed, 8 insertions, 48 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/Binding.java b/src/main/java/dev/isxander/yacl/api/Binding.java
index d870d8c..37514ca 100644
--- a/src/main/java/dev/isxander/yacl/api/Binding.java
+++ b/src/main/java/dev/isxander/yacl/api/Binding.java
@@ -26,7 +26,7 @@ public interface Binding<T> {
* @param getter should return the current value of the option
* @param setter should set the option to the supplied value
*/
- static <T> Binding<T> of(T def, Supplier<T> getter, Consumer<T> setter) {
+ static <T> Binding<T> generic(T def, Supplier<T> getter, Consumer<T> setter) {
Validate.notNull(def, "`def` must not be null");
Validate.notNull(getter, "`getter` must not be null");
Validate.notNull(setter, "`setter` must not be null");
@@ -37,7 +37,7 @@ public interface Binding<T> {
/**
* Creates a {@link Binding} for Minecraft's {@link SimpleOption}
*/
- static <T> Binding<T> of(SimpleOption<T> minecraftOption) {
+ static <T> Binding<T> minecraft(SimpleOption<T> minecraftOption) {
Validate.notNull(minecraftOption, "`minecraftOption` must not be null");
return new GenericBindingImpl<>(
diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java
index 6598b80..65eae23 100644
--- a/src/main/java/dev/isxander/yacl/api/Option.java
+++ b/src/main/java/dev/isxander/yacl/api/Option.java
@@ -147,7 +147,7 @@ public interface Option<T> {
/**
* Sets the binding for the option.
- * Shorthand of {@link Binding#of(Object, Supplier, Consumer)}
+ * Shorthand of {@link Binding#generic(Object, Supplier, Consumer)}
*
* @param def default value of the option, used to reset
* @param getter should return the current value of the option
@@ -159,7 +159,7 @@ public interface Option<T> {
Validate.notNull(getter, "`getter` must not be null");
Validate.notNull(setter, "`setter` must not be null");
- this.binding = Binding.of(def, getter, setter);
+ this.binding = Binding.generic(def, getter, setter);
return this;
}
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
index 8d74ceb..ed78abd 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
@@ -13,7 +13,7 @@ public class DoubleSliderController implements ISliderController<Double> {
/**
* Formats doubles to two decimal places
*/
- public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%.2f", value));
+ public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value));
private final Option<Double> option;
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
index 6f4192b..4297271 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
@@ -13,7 +13,7 @@ public class FloatSliderController implements ISliderController<Float> {
/**
* Formats floats to one decimal place
*/
- public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%.1f", value));
+ public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value));
private final Option<Float> option;
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
index 0d0d7b9..38efed5 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
@@ -1,7 +1,6 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.impl.utils.NumberFormatHelper;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;
@@ -11,7 +10,7 @@ import java.util.function.Function;
* {@link ISliderController} for integers.
*/
public class IntegerSliderController implements ISliderController<Integer> {
- public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value));
+ public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value));
private final Option<Integer> option;
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
index d4c71d1..67b6a0e 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
@@ -1,7 +1,6 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.impl.utils.NumberFormatHelper;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;
@@ -11,7 +10,7 @@ import java.util.function.Function;
* {@link ISliderController} for longs.
*/
public class LongSliderController implements ISliderController<Long> {
- public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value));
+ public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value));
private final Option<Long> option;
diff --git a/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java b/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java
deleted file mode 100644
index bbf44a1..0000000
--- a/src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package dev.isxander.yacl.impl.utils;
-
-import org.jetbrains.annotations.ApiStatus;
-
-import java.util.Map;
-import java.util.NavigableMap;
-import java.util.TreeMap;
-
-@ApiStatus.Internal
-public class NumberFormatHelper {
- private static final NavigableMap<Long, String> suffixes = new TreeMap<>();
- static {
- suffixes.put(1_000L, "K");
- suffixes.put(1_000_000L, "M");
- suffixes.put(1_000_000_000L, "B");
- suffixes.put(1_000_000_000_000L, "T");
- suffixes.put(1_000_000_000_000_000L, "P");
- suffixes.put(1_000_000_000_000_000_000L, "E");
- }
-
- /**
- * @author <a href="https://stackoverflow.com/a/30661479">assylias</a>
- */
- public static String formatSmaller(long value) {
- // Long.MIN_VALUE == -Long.MIN_VALUE, so we need an adjustment here
- if (value == Long.MIN_VALUE) return formatSmaller(Long.MIN_VALUE + 1);
- if (value < 0) return "-" + formatSmaller(-value);
- if (value < 1000) return Long.toString(value); //deal with easy case
-
- Map.Entry<Long, String> e = suffixes.floorEntry(value);
- Long divideBy = e.getKey();
- String suffix = e.getValue();
-
- long truncated = value / (divideBy / 10); //the number part of the output times 10
- boolean hasDecimal = truncated < 100 && (truncated / 10d) != (truncated / 10);
- return hasDecimal ? (truncated / 10d) + suffix : (truncated / 10) + suffix;
- }
-}