From f46fc1e9d85d555cd557eefa10e1211f9ad1ceb1 Mon Sep 17 00:00:00 2001 From: xander Date: Thu, 1 Sep 2022 20:23:00 +0100 Subject: CI stuff rename binding functions and format numbers with commas --- src/main/java/dev/isxander/yacl/api/Binding.java | 4 +-- src/main/java/dev/isxander/yacl/api/Option.java | 4 +-- .../controllers/slider/DoubleSliderController.java | 2 +- .../controllers/slider/FloatSliderController.java | 2 +- .../slider/IntegerSliderController.java | 3 +- .../controllers/slider/LongSliderController.java | 3 +- .../yacl/impl/utils/NumberFormatHelper.java | 38 ---------------------- 7 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/dev/isxander/yacl/impl/utils/NumberFormatHelper.java (limited to 'src') 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 { * @param getter should return the current value of the option * @param setter should set the option to the supplied value */ - static Binding of(T def, Supplier getter, Consumer setter) { + static Binding generic(T def, Supplier getter, Consumer 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 { /** * Creates a {@link Binding} for Minecraft's {@link SimpleOption} */ - static Binding of(SimpleOption minecraftOption) { + static Binding minecraft(SimpleOption 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 { /** * 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 { 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 { /** * Formats doubles to two decimal places */ - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%.2f", value)); + public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value)); private final Option 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 { /** * Formats floats to one decimal place */ - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%.1f", value)); + public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value)); private final Option 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 { - public static final Function DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value)); + public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value)); private final Option 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 { - public static final Function DEFAULT_FORMATTER = value -> Text.of(NumberFormatHelper.formatSmaller(value)); + public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value)); private final Option 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 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 assylias - */ - 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 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; - } -} -- cgit