From 32f624e1d5dc067595cbe6685930f9ef0f3db6a8 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 10 Oct 2019 03:49:44 -0600 Subject: [PATCH 1/4] StackFormatter: remove quantityToRSStackSize This is nearly unused, and serves no great purpose as quantityToStackSize can display the same information in a more readable format --- .../plugins/itemstats/ItemStatPlugin.java | 2 +- .../kingdomofmiscellania/KingdomCounter.java | 2 +- .../runelite/client/util/StackFormatter.java | 47 +++---------------- .../client/util/StackFormatterTest.java | 16 ------- 4 files changed, 8 insertions(+), 59 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java index 4f244d844b..b0c218bad7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java @@ -340,7 +340,7 @@ public class ItemStatPlugin extends Plugin createSeparator(invContainer, invContainer.getHeight() - 40); - final String coinText = "You have " + StackFormatter.quantityToRSStackSize(getCurrentGP()) + final String coinText = "You have " + StackFormatter.quantityToStackSize(getCurrentGP()) + (getCurrentGP() == 1 ? " coin." : " coins."); final Widget coinWidget = createText(invContainer, coinText, FontID.PLAIN_12, ORANGE_TEXT, diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java index 8a2871125f..e2e6539d9f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java @@ -48,6 +48,6 @@ public class KingdomCounter extends Counter public String getTooltip() { return "Favor: " + plugin.getFavor() + "/127" + "
" - + "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer()); + + "Coffer: " + StackFormatter.quantityToStackSize(plugin.getCoffer()); } } diff --git a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java index c9282f7f46..a334b54148 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java +++ b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java @@ -33,8 +33,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * A set of utility functions to use when - * formatting numbers for to stack sizes. + * A set of utility functions to use when formatting quantities */ public class StackFormatter { @@ -70,12 +69,12 @@ public class StackFormatter ); /** - * Convert a quantity to a nicely formatted stack size. - * See the StackFormatterTest to see expected output. + * Convert a quantity to a short, comma separated, SI-prefix style string + * + * example: {@code 9,450}, {@code 2.14B}, {@code 100K} * * @param quantity The quantity to convert. - * @return A condensed version, with commas, K, M or B - * as needed to 3 significant figures. + * @return a 6 or less character string, possibly with a decimal point, commas or K/M/B suffix */ public static String quantityToStackSize(long quantity) { @@ -115,41 +114,7 @@ public class StackFormatter } /** - * Convert a quantity to stack size as it would - * appear in RuneScape. - * - * @param quantity The quantity to convert. - * @return The stack size as it would appear in RS, - * with K after 100,000 and M after 10,000,000 - */ - public static String quantityToRSStackSize(int quantity) - { - if (quantity == Integer.MIN_VALUE) - { - // Integer.MIN_VALUE = Integer.MIN_VALUE * -1 so we need to correct for it. - return "-" + quantityToRSStackSize(Integer.MAX_VALUE); - } - else if (quantity < 0) - { - return "-" + quantityToRSStackSize(-quantity); - } - else if (quantity < 100_000) - { - return Integer.toString(quantity); - } - else if (quantity < 10_000_000) - { - return quantity / 1_000 + "K"; - } - else - { - return quantity / 1_000_000 + "M"; - } - } - - /** - * Convert a quantity to stack size as it would - * appear in RuneScape. (with decimals) + * Convert a quantity to a short SI-prefix style string with decimals *

* This differs from quantityToRSStack in that it displays * decimals. Ex: 27100 is 27.1k (not 27k) diff --git a/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java b/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java index 1e297a8513..23c3619a54 100644 --- a/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java +++ b/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java @@ -59,22 +59,6 @@ public class StackFormatterTest assertEquals("2.1B", StackFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE)); } - @Test - public void quantityToRSStackSize() - { - assertEquals("0", StackFormatter.quantityToRSStackSize(0)); - assertEquals("99999", StackFormatter.quantityToRSStackSize(99_999)); - assertEquals("100K", StackFormatter.quantityToRSStackSize(100_000)); - assertEquals("10M", StackFormatter.quantityToRSStackSize(10_000_000)); - assertEquals("2147M", StackFormatter.quantityToRSStackSize(Integer.MAX_VALUE)); - - assertEquals("0", StackFormatter.quantityToRSStackSize(-0)); - assertEquals("-400", StackFormatter.quantityToRSStackSize(-400)); - assertEquals("-400K", StackFormatter.quantityToRSStackSize(-400_000)); - assertEquals("-40M", StackFormatter.quantityToRSStackSize(-40_000_000)); - assertEquals("-2147M", StackFormatter.quantityToRSStackSize(Integer.MIN_VALUE)); - } - @Test public void quantityToStackSize() { From b30243c784876573b9072e46ad7041edf61e66fc Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 10 Oct 2019 04:23:35 -0600 Subject: [PATCH 2/4] StackFormatter: Fix documentation --- .../runelite/client/util/StackFormatter.java | 57 ++++++------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java index a334b54148..8a71754620 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java +++ b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java @@ -47,22 +47,13 @@ public class StackFormatter */ private static final Pattern SUFFIX_PATTERN = Pattern.compile("^-?[0-9,.]+([a-zA-Z]?)$"); - /** - * A number formatter - */ private static final NumberFormat NUMBER_FORMATTER = NumberFormat.getInstance(Locale.ENGLISH); - /** - * A decimal number formatter - */ private static final NumberFormat DECIMAL_FORMATTER = new DecimalFormat( "#,###.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH) ); - /** - * A more precise decimal number formatter, outputting thousandths - */ private static final NumberFormat PRECISE_DECIMAL_FORMATTER = new DecimalFormat( "#,###.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH) @@ -114,15 +105,12 @@ public class StackFormatter } /** - * Convert a quantity to a short SI-prefix style string with decimals - *

- * This differs from quantityToRSStack in that it displays - * decimals. Ex: 27100 is 27.1k (not 27k) - *

- * - * @param quantity The quantity to convert. - * @return The stack size as it would appear in RS, with decimals, + * Convert a quantity to a short SI-prefix style string, possibly with a decimal, * with K after 100,000 and M after 10,000,000 + * + * example: {@code 9,450}, {@code 2.1B}, {@code 100K} + * + * @see #quantityToRSDecimalStack(int, boolean) */ public static String quantityToRSDecimalStack(int quantity) { @@ -130,17 +118,14 @@ public class StackFormatter } /** - * Convert a quantity to stack size as it would - * appear in RuneScape. (with decimals) - *

- * This differs from quantityToRSStack in that it displays - * decimals. Ex: 27100 is 27.1k (not 27k) - *

- * - * @param quantity The quantity to convert. - * @param precise If true, the returned string will have thousandths precision if quantity is larger than 1 million. - * @return The stack size as it would appear in RS, with decimals, + * Convert a quantity to a short SI-prefix style string, possibly with decimals, * with K after 100,000 and M after 10,000,000 + * + * example without {@code precise}: {@code 9,450}, {@code 2.1B}, {@code 8.4M} + * example with {@code precise}: {@code 9,450}, {@code 2.147B}, {@code 8.32M} + * + * @param precise If true, allow thousandths precision if {@code quantity} is larger than 1 million. + * Otherwise have at most a single decimal */ public static String quantityToRSDecimalStack(int quantity, boolean precise) { @@ -175,27 +160,21 @@ public class StackFormatter } /** - * Specialization of format. + * Formats a number to be comma delimited. No suffixes are given * - * @param number the long number to format - * @return the formatted String - * @throws ArithmeticException if rounding is needed with rounding - * mode being set to RoundingMode.UNNECESSARY - * @see java.text.Format#format + * example: {@code 10,123,351}, {@code 5} */ public static String formatNumber(final long number) { return NUMBER_FORMATTER.format(number); } + /** - * Specialization of format. + * Formats a number to be comma delimited. No suffixes are given. Has at + * most 3 decimal places * - * @param number the double number to format - * @return the formatted String - * @throws ArithmeticException if rounding is needed with rounding - * mode being set to RoundingMode.UNNECESSARY - * @see java.text.Format#format + * example: {@code 10,123,351}, {@code 5.612} */ public static String formatNumber(double number) { From ea69b8e57d2aeeebebdb2c3ccb9f3696d52657bc Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 10 Oct 2019 04:25:53 -0600 Subject: [PATCH 3/4] StackFormatter: synchronize access to NumberFormats DecimalFormat likes to copy data into itself when formatting because it is poorly designed, as such it cannot be used by multiple threads at once. --- .../java/net/runelite/client/util/StackFormatter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java index 8a71754620..75d4a9c63f 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java +++ b/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java @@ -67,7 +67,7 @@ public class StackFormatter * @param quantity The quantity to convert. * @return a 6 or less character string, possibly with a decimal point, commas or K/M/B suffix */ - public static String quantityToStackSize(long quantity) + public static synchronized String quantityToStackSize(long quantity) { if (quantity < 0) { @@ -127,7 +127,7 @@ public class StackFormatter * @param precise If true, allow thousandths precision if {@code quantity} is larger than 1 million. * Otherwise have at most a single decimal */ - public static String quantityToRSDecimalStack(int quantity, boolean precise) + public static synchronized String quantityToRSDecimalStack(int quantity, boolean precise) { String quantityStr = String.valueOf(quantity); if (quantityStr.length() <= 4) @@ -152,7 +152,7 @@ public class StackFormatter * @param string The string to convert. * @return A long representation of it. */ - public static long stackSizeToQuantity(String string) throws ParseException + public static synchronized long stackSizeToQuantity(String string) throws ParseException { int multiplier = getMultiplier(string); float parsedValue = NUMBER_FORMATTER.parse(string).floatValue(); @@ -164,7 +164,7 @@ public class StackFormatter * * example: {@code 10,123,351}, {@code 5} */ - public static String formatNumber(final long number) + public static synchronized String formatNumber(final long number) { return NUMBER_FORMATTER.format(number); } @@ -176,7 +176,7 @@ public class StackFormatter * * example: {@code 10,123,351}, {@code 5.612} */ - public static String formatNumber(double number) + public static synchronized String formatNumber(double number) { return NUMBER_FORMATTER.format(number); } From d627171bbe23763b5f6219c69271c8b769ce7df4 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 10 Oct 2019 04:29:30 -0600 Subject: [PATCH 4/4] runelite-client: Rename StackFormatter to QuantityFormatter StackFormatter.formatNumber was incredibly misleading, it makes more sense to remove Stack from the classes name than move it. --- .../client/plugins/ammo/AmmoCounter.java | 4 +- .../client/plugins/bank/BankPlugin.java | 16 +- .../client/plugins/barrows/BarrowsPlugin.java | 4 +- .../BlastFurnaceCofferOverlay.java | 4 +- .../chatcommands/ChatCommandsPlugin.java | 6 +- .../client/plugins/examine/ExaminePlugin.java | 12 +- .../grandexchange/GrandExchangeItemPanel.java | 8 +- .../grandexchange/GrandExchangeOfferSlot.java | 12 +- .../grandexchange/GrandExchangePlugin.java | 10 +- .../grounditems/GroundItemsOverlay.java | 10 +- .../grounditems/GroundItemsPlugin.java | 4 +- .../client/plugins/hiscore/HiscorePanel.java | 50 +++--- .../plugins/itemprices/ItemPricesOverlay.java | 14 +- .../ItemsKeptOnDeathPlugin.java | 4 +- .../plugins/itemstats/ItemStatPlugin.java | 4 +- .../kingdomofmiscellania/KingdomCounter.java | 4 +- .../plugins/loottracker/LootTrackerBox.java | 8 +- .../plugins/loottracker/LootTrackerPanel.java | 4 +- .../nightmarezone/NightmareZoneOverlay.java | 8 +- .../client/plugins/xptracker/XpInfoBox.java | 4 +- .../plugins/xptracker/XpInfoBoxOverlay.java | 6 +- ...kFormatter.java => QuantityFormatter.java} | 4 +- .../client/util/QuantityFormatterTest.java | 143 ++++++++++++++++++ .../client/util/StackFormatterTest.java | 143 ------------------ 24 files changed, 243 insertions(+), 243 deletions(-) rename runelite-client/src/main/java/net/runelite/client/util/{StackFormatter.java => QuantityFormatter.java} (98%) create mode 100644 runelite-client/src/test/java/net/runelite/client/util/QuantityFormatterTest.java delete mode 100644 runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/ammo/AmmoCounter.java b/runelite-client/src/main/java/net/runelite/client/plugins/ammo/AmmoCounter.java index f7f12c497a..4f4639d5f7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/ammo/AmmoCounter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/ammo/AmmoCounter.java @@ -28,7 +28,7 @@ import java.awt.image.BufferedImage; import lombok.Getter; import net.runelite.client.plugins.Plugin; import net.runelite.client.ui.overlay.infobox.Counter; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; class AmmoCounter extends Counter { @@ -46,7 +46,7 @@ class AmmoCounter extends Counter @Override public String getText() { - return StackFormatter.quantityToRSDecimalStack(getCount()); + return QuantityFormatter.quantityToRSDecimalStack(getCount()); } @Override diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/bank/BankPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/bank/BankPlugin.java index 4435471399..dafa61f630 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/bank/BankPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bank/BankPlugin.java @@ -61,7 +61,7 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.banktags.tabs.BankSearch; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; @PluginDescriptor( name = "Bank", @@ -241,11 +241,11 @@ public class BankPlugin extends Plugin if (config.showExact()) { - strCurrentTab += StackFormatter.formatNumber(gePrice) + ")"; + strCurrentTab += QuantityFormatter.formatNumber(gePrice) + ")"; } else { - strCurrentTab += StackFormatter.quantityToStackSize(gePrice) + ")"; + strCurrentTab += QuantityFormatter.quantityToStackSize(gePrice) + ")"; } } @@ -260,11 +260,11 @@ public class BankPlugin extends Plugin if (config.showExact()) { - strCurrentTab += StackFormatter.formatNumber(haPrice) + ")"; + strCurrentTab += QuantityFormatter.formatNumber(haPrice) + ")"; } else { - strCurrentTab += StackFormatter.quantityToStackSize(haPrice) + ")"; + strCurrentTab += QuantityFormatter.quantityToStackSize(haPrice) + ")"; } } @@ -369,7 +369,7 @@ public class BankPlugin extends Plugin long compare; try { - compare = StackFormatter.stackSizeToQuantity(matcher.group("num")); + compare = QuantityFormatter.parseQuantity(matcher.group("num")); } catch (ParseException e) { @@ -398,8 +398,8 @@ public class BankPlugin extends Plugin long compare1, compare2; try { - compare1 = StackFormatter.stackSizeToQuantity(num1); - compare2 = StackFormatter.stackSizeToQuantity(num2); + compare1 = QuantityFormatter.parseQuantity(num1); + compare2 = QuantityFormatter.parseQuantity(num2); } catch (ParseException e) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java index 68b726908b..2d4db73d12 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java @@ -70,7 +70,7 @@ import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxPriority; import net.runelite.client.ui.overlay.infobox.LoopTimer; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; @PluginDescriptor( name = "Barrows Brothers", @@ -288,7 +288,7 @@ public class BarrowsPlugin extends Plugin final ChatMessageBuilder message = new ChatMessageBuilder() .append(ChatColorType.HIGHLIGHT) .append("Your chest is worth around ") - .append(StackFormatter.formatNumber(chestPrice)) + .append(QuantityFormatter.formatNumber(chestPrice)) .append(" coins.") .append(ChatColorType.NORMAL); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceCofferOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceCofferOverlay.java index d88c668939..b549adbeba 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceCofferOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceCofferOverlay.java @@ -38,7 +38,7 @@ import net.runelite.client.ui.overlay.OverlayMenuEntry; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; class BlastFurnaceCofferOverlay extends Overlay { @@ -74,7 +74,7 @@ class BlastFurnaceCofferOverlay extends Overlay panelComponent.getChildren().add(LineComponent.builder() .left("Coffer:") - .right(StackFormatter.quantityToStackSize(client.getVar(BLAST_FURNACE_COFFER)) + " gp") + .right(QuantityFormatter.quantityToStackSize(client.getVar(BLAST_FURNACE_COFFER)) + " gp") .build()); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index ef140b3350..85b19e266c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -62,7 +62,7 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import static net.runelite.client.util.Text.sanitize; import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.Duels; @@ -836,7 +836,7 @@ public class ChatCommandsPlugin extends Plugin .append(ChatColorType.NORMAL) .append(": GE average ") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(itemPrice)); + .append(QuantityFormatter.formatNumber(itemPrice)); ItemComposition itemComposition = itemManager.getItemComposition(itemId); if (itemComposition != null) @@ -846,7 +846,7 @@ public class ChatCommandsPlugin extends Plugin .append(ChatColorType.NORMAL) .append(" HA value ") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(alchPrice)); + .append(QuantityFormatter.formatNumber(alchPrice)); } String response = builder.build(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java index 33cc9deb90..02769cb2a5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java @@ -56,7 +56,7 @@ import net.runelite.client.eventbus.Subscribe; import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; import net.runelite.http.api.examine.ExamineClient; @@ -336,7 +336,7 @@ public class ExaminePlugin extends Plugin if (quantity > 1) { message - .append(StackFormatter.formatNumber(quantity)) + .append(QuantityFormatter.formatNumber(quantity)) .append(" x "); } @@ -351,7 +351,7 @@ public class ExaminePlugin extends Plugin .append(ChatColorType.NORMAL) .append(" GE average ") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(gePrice * quantity)); + .append(QuantityFormatter.formatNumber(gePrice * quantity)); if (quantity > 1) { @@ -359,7 +359,7 @@ public class ExaminePlugin extends Plugin .append(ChatColorType.NORMAL) .append(" (") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(gePrice)) + .append(QuantityFormatter.formatNumber(gePrice)) .append(ChatColorType.NORMAL) .append("ea)"); } @@ -371,7 +371,7 @@ public class ExaminePlugin extends Plugin .append(ChatColorType.NORMAL) .append(" HA value ") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(alchPrice * quantity)); + .append(QuantityFormatter.formatNumber(alchPrice * quantity)); if (quantity > 1) { @@ -379,7 +379,7 @@ public class ExaminePlugin extends Plugin .append(ChatColorType.NORMAL) .append(" (") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(alchPrice)) + .append(QuantityFormatter.formatNumber(alchPrice)) .append(ChatColorType.NORMAL) .append("ea)"); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeItemPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeItemPanel.java index 7f40564e01..453f340754 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeItemPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeItemPanel.java @@ -42,7 +42,7 @@ import javax.swing.border.EmptyBorder; import net.runelite.client.game.AsyncBufferedImage; import net.runelite.client.ui.ColorScheme; import net.runelite.client.util.LinkBrowser; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; /** * This panel displays an individual item result in the @@ -124,7 +124,7 @@ class GrandExchangeItemPanel extends JPanel JLabel gePriceLabel = new JLabel(); if (gePrice > 0) { - gePriceLabel.setText(StackFormatter.formatNumber(gePrice) + " gp"); + gePriceLabel.setText(QuantityFormatter.formatNumber(gePrice) + " gp"); } else { @@ -139,13 +139,13 @@ class GrandExchangeItemPanel extends JPanel // Alch price JLabel haPriceLabel = new JLabel(); - haPriceLabel.setText(StackFormatter.formatNumber(haPrice.intValue()) + " alch"); + haPriceLabel.setText(QuantityFormatter.formatNumber(haPrice.intValue()) + " alch"); haPriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_ALCH); alchAndLimitPanel.add(haPriceLabel, BorderLayout.WEST); // GE Limit JLabel geLimitLabel = new JLabel(); - String limitLabelText = geItemLimit == 0 ? "" : "Limit " + StackFormatter.formatNumber(geItemLimit); + String limitLabelText = geItemLimit == 0 ? "" : "Limit " + QuantityFormatter.formatNumber(geItemLimit); geLimitLabel.setText(limitLabelText); geLimitLabel.setForeground(ColorScheme.GRAND_EXCHANGE_LIMIT); geLimitLabel.setBorder(new CompoundBorder(geLimitLabel.getBorder(), new EmptyBorder(0, 0, 0, 7))); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeOfferSlot.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeOfferSlot.java index 14090170fe..f2a35d47d8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeOfferSlot.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangeOfferSlot.java @@ -52,7 +52,7 @@ import net.runelite.client.ui.FontManager; import net.runelite.client.ui.components.ThinProgressBar; import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; public class GrandExchangeOfferSlot extends JPanel { @@ -211,17 +211,17 @@ public class GrandExchangeOfferSlot extends JPanel || newOffer.getState() == GrandExchangeOfferState.CANCELLED_BUY; String offerState = (buying ? "Bought " : "Sold ") - + StackFormatter.quantityToRSDecimalStack(newOffer.getQuantitySold()) + " / " - + StackFormatter.quantityToRSDecimalStack(newOffer.getTotalQuantity()); + + QuantityFormatter.quantityToRSDecimalStack(newOffer.getQuantitySold()) + " / " + + QuantityFormatter.quantityToRSDecimalStack(newOffer.getTotalQuantity()); offerInfo.setText(offerState); - itemPrice.setText(htmlLabel("Price each: ", StackFormatter.formatNumber(newOffer.getPrice()))); + itemPrice.setText(htmlLabel("Price each: ", QuantityFormatter.formatNumber(newOffer.getPrice()))); String action = buying ? "Spent: " : "Received: "; - offerSpent.setText(htmlLabel(action, StackFormatter.formatNumber(newOffer.getSpent()) + " / " - + StackFormatter.formatNumber(newOffer.getPrice() * newOffer.getTotalQuantity()))); + offerSpent.setText(htmlLabel(action, QuantityFormatter.formatNumber(newOffer.getSpent()) + " / " + + QuantityFormatter.formatNumber(newOffer.getPrice() * newOffer.getTotalQuantity()))); progressBar.setForeground(getProgressColor(newOffer)); progressBar.setMaximumValue(newOffer.getTotalQuantity()); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java index bccc7be58d..b7936c243e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java @@ -77,7 +77,7 @@ import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.ClientToolbar; import net.runelite.client.ui.NavigationButton; import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; import net.runelite.http.api.ge.GrandExchangeClient; import net.runelite.http.api.ge.GrandExchangeTrade; @@ -456,11 +456,11 @@ public class GrandExchangePlugin extends Plugin if (config.showExact()) { - titleBuilder.append(StackFormatter.formatNumber(total)); + titleBuilder.append(QuantityFormatter.formatNumber(total)); } else { - titleBuilder.append(StackFormatter.quantityToStackSize(total)); + titleBuilder.append(QuantityFormatter.quantityToStackSize(total)); } titleBuilder.append(')'); @@ -497,7 +497,7 @@ public class GrandExchangePlugin extends Plugin // If we have item buy limit, append it if (itemLimit != null) { - final String text = geText.getText() + BUY_LIMIT_GE_TEXT + StackFormatter.formatNumber(itemLimit); + final String text = geText.getText() + BUY_LIMIT_GE_TEXT + QuantityFormatter.formatNumber(itemLimit); geText.setText(text); } } @@ -521,7 +521,7 @@ public class GrandExchangePlugin extends Plugin try { final OSBGrandExchangeResult result = CLIENT.lookupItem(itemId); - final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(result.getOverall_average()); + final String text = geText.getText() + OSB_GE_TEXT + QuantityFormatter.formatNumber(result.getOverall_average()); geText.setText(text); } catch (IOException e) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java index 9d909c300b..1e626e776a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java @@ -55,7 +55,7 @@ import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.components.BackgroundComponent; import net.runelite.client.ui.overlay.components.ProgressPieComponent; import net.runelite.client.ui.overlay.components.TextComponent; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import org.apache.commons.lang3.ArrayUtils; public class GroundItemsOverlay extends Overlay @@ -234,7 +234,7 @@ public class GroundItemsOverlay extends Overlay else { itemStringBuilder.append(" (") - .append(StackFormatter.quantityToStackSize(item.getQuantity())) + .append(QuantityFormatter.quantityToStackSize(item.getQuantity())) .append(")"); } } @@ -244,14 +244,14 @@ public class GroundItemsOverlay extends Overlay if (item.getGePrice() > 0) { itemStringBuilder.append(" (EX: ") - .append(StackFormatter.quantityToStackSize(item.getGePrice())) + .append(QuantityFormatter.quantityToStackSize(item.getGePrice())) .append(" gp)"); } if (item.getHaPrice() > 0) { itemStringBuilder.append(" (HA: ") - .append(StackFormatter.quantityToStackSize(item.getHaPrice())) + .append(QuantityFormatter.quantityToStackSize(item.getHaPrice())) .append(" gp)"); } } @@ -265,7 +265,7 @@ public class GroundItemsOverlay extends Overlay { itemStringBuilder .append(" (") - .append(StackFormatter.quantityToStackSize(price)) + .append(QuantityFormatter.quantityToStackSize(price)) .append(" gp)"); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index 22899c3a69..aafd612236 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -90,7 +90,7 @@ import static net.runelite.client.plugins.grounditems.config.MenuHighlightMode.O import net.runelite.client.plugins.grounditems.config.ValueCalculationMode; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.util.ColorUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; @PluginDescriptor( @@ -673,7 +673,7 @@ public class GroundItemsPlugin extends Plugin else { notificationStringBuilder.append(" (") - .append(StackFormatter.quantityToStackSize(item.getQuantity())) + .append(QuantityFormatter.quantityToStackSize(item.getQuantity())) .append(")"); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java index c667fca463..0ddb3372f3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePanel.java @@ -59,7 +59,7 @@ import net.runelite.client.ui.components.IconTextField; import net.runelite.client.ui.components.materialtabs.MaterialTab; import net.runelite.client.ui.components.materialtabs.MaterialTabGroup; import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreResult; @@ -512,8 +512,8 @@ public class HiscorePanel extends PluginPanel + result.getRanged().getExperience() + result.getPrayer().getExperience(); content += "

Skill: Combat

"; - content += "

Exact Combat Level: " + StackFormatter.formatNumber(combatLevel) + "

"; - content += "

Experience: " + StackFormatter.formatNumber(combatExperience) + "

"; + content += "

Exact Combat Level: " + QuantityFormatter.formatNumber(combatLevel) + "

"; + content += "

Experience: " + QuantityFormatter.formatNumber(combatExperience) + "

"; } else { @@ -521,20 +521,20 @@ public class HiscorePanel extends PluginPanel { case CLUE_SCROLL_ALL: { - String allRank = (result.getClueScrollAll().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollAll().getRank()); - String beginnerRank = (result.getClueScrollBeginner().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollBeginner().getRank()); - String easyRank = (result.getClueScrollEasy().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollEasy().getRank()); - String mediumRank = (result.getClueScrollMedium().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollMedium().getRank()); - String hardRank = (result.getClueScrollHard().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollHard().getRank()); - String eliteRank = (result.getClueScrollElite().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollElite().getRank()); - String masterRank = (result.getClueScrollMaster().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getClueScrollMaster().getRank()); - String all = (result.getClueScrollAll().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollAll().getLevel())); - String beginner = (result.getClueScrollBeginner().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollBeginner().getLevel())); - String easy = (result.getClueScrollEasy().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollEasy().getLevel())); - String medium = (result.getClueScrollMedium().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollMedium().getLevel())); - String hard = (result.getClueScrollHard().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollHard().getLevel())); - String elite = (result.getClueScrollElite().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollElite().getLevel())); - String master = (result.getClueScrollMaster().getLevel() == -1 ? "0" : StackFormatter.formatNumber(result.getClueScrollMaster().getLevel())); + String allRank = (result.getClueScrollAll().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollAll().getRank()); + String beginnerRank = (result.getClueScrollBeginner().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollBeginner().getRank()); + String easyRank = (result.getClueScrollEasy().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollEasy().getRank()); + String mediumRank = (result.getClueScrollMedium().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollMedium().getRank()); + String hardRank = (result.getClueScrollHard().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollHard().getRank()); + String eliteRank = (result.getClueScrollElite().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollElite().getRank()); + String masterRank = (result.getClueScrollMaster().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getClueScrollMaster().getRank()); + String all = (result.getClueScrollAll().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollAll().getLevel())); + String beginner = (result.getClueScrollBeginner().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollBeginner().getLevel())); + String easy = (result.getClueScrollEasy().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollEasy().getLevel())); + String medium = (result.getClueScrollMedium().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollMedium().getLevel())); + String hard = (result.getClueScrollHard().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollHard().getLevel())); + String elite = (result.getClueScrollElite().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollElite().getLevel())); + String master = (result.getClueScrollMaster().getLevel() == -1 ? "0" : QuantityFormatter.formatNumber(result.getClueScrollMaster().getLevel())); content += "

All: " + all + " Rank: " + allRank + "

"; content += "

Beginner: " + beginner + " Rank: " + beginnerRank + "

"; content += "

Easy: " + easy + " Rank: " + easyRank + "

"; @@ -546,27 +546,27 @@ public class HiscorePanel extends PluginPanel } case BOUNTY_HUNTER_ROGUE: { - String rank = (result.getBountyHunterRogue().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getBountyHunterRogue().getRank()); + String rank = (result.getBountyHunterRogue().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getBountyHunterRogue().getRank()); content += "

Rank: " + rank + "

"; break; } case BOUNTY_HUNTER_HUNTER: { - String rank = (result.getBountyHunterHunter().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getBountyHunterHunter().getRank()); + String rank = (result.getBountyHunterHunter().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getBountyHunterHunter().getRank()); content += "

Rank: " + rank + "

"; break; } case LAST_MAN_STANDING: { - String rank = (result.getLastManStanding().getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(result.getLastManStanding().getRank()); + String rank = (result.getLastManStanding().getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(result.getLastManStanding().getRank()); content += "

Rank: " + rank + "

"; break; } case OVERALL: { Skill requestedSkill = result.getSkill(skill); - String rank = (requestedSkill.getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(requestedSkill.getRank()); - String exp = (requestedSkill.getExperience() == -1L) ? "Unranked" : StackFormatter.formatNumber(requestedSkill.getExperience()); + String rank = (requestedSkill.getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(requestedSkill.getRank()); + String exp = (requestedSkill.getExperience() == -1L) ? "Unranked" : QuantityFormatter.formatNumber(requestedSkill.getExperience()); content += "

Skill: " + skill.getName() + "

"; content += "

Rank: " + rank + "

"; content += "

Experience: " + exp + "

"; @@ -577,8 +577,8 @@ public class HiscorePanel extends PluginPanel Skill requestedSkill = result.getSkill(skill); final long experience = requestedSkill.getExperience(); - String rank = (requestedSkill.getRank() == -1) ? "Unranked" : StackFormatter.formatNumber(requestedSkill.getRank()); - String exp = (experience == -1L) ? "Unranked" : StackFormatter.formatNumber(experience); + String rank = (requestedSkill.getRank() == -1) ? "Unranked" : QuantityFormatter.formatNumber(requestedSkill.getRank()); + String exp = (experience == -1L) ? "Unranked" : QuantityFormatter.formatNumber(experience); String remainingXp; if (experience == -1L) { @@ -587,7 +587,7 @@ public class HiscorePanel extends PluginPanel else { int currentLevel = Experience.getLevelForXp((int) experience); - remainingXp = (currentLevel + 1 <= Experience.MAX_VIRT_LEVEL) ? StackFormatter.formatNumber(Experience.getXpForLevel(currentLevel + 1) - experience) : "0"; + remainingXp = (currentLevel + 1 <= Experience.MAX_VIRT_LEVEL) ? QuantityFormatter.formatNumber(Experience.getXpForLevel(currentLevel + 1) - experience) : "0"; } content += "

Skill: " + skill.getName() + "

"; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java index d98828d3b0..bcb06fe6f1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java @@ -45,7 +45,7 @@ import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.tooltip.Tooltip; import net.runelite.client.ui.overlay.tooltip.TooltipManager; import net.runelite.client.util.ColorUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; class ItemPricesOverlay extends Overlay { @@ -183,11 +183,11 @@ class ItemPricesOverlay extends Overlay // Special case for coins and platinum tokens if (id == ItemID.COINS_995) { - return StackFormatter.formatNumber(qty) + " gp"; + return QuantityFormatter.formatNumber(qty) + " gp"; } else if (id == ItemID.PLATINUM_TOKEN) { - return StackFormatter.formatNumber(qty * 1000) + " gp"; + return QuantityFormatter.formatNumber(qty * 1000) + " gp"; } ItemComposition itemDef = itemManager.getItemComposition(id); @@ -234,12 +234,12 @@ class ItemPricesOverlay extends Overlay if (gePrice > 0) { itemStringBuilder.append("EX: ") - .append(StackFormatter.quantityToStackSize(gePrice * qty)) + .append(QuantityFormatter.quantityToStackSize(gePrice * qty)) .append(" gp"); if (config.showEA() && qty > 1) { itemStringBuilder.append(" (") - .append(StackFormatter.quantityToStackSize(gePrice)) + .append(QuantityFormatter.quantityToStackSize(gePrice)) .append(" ea)"); } } @@ -251,12 +251,12 @@ class ItemPricesOverlay extends Overlay } itemStringBuilder.append("HA: ") - .append(StackFormatter.quantityToStackSize(haValue * qty)) + .append(QuantityFormatter.quantityToStackSize(haValue * qty)) .append(" gp"); if (config.showEA() && qty > 1) { itemStringBuilder.append(" (") - .append(StackFormatter.quantityToStackSize(haValue)) + .append(QuantityFormatter.quantityToStackSize(haValue)) .append(" ea)"); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemskeptondeath/ItemsKeptOnDeathPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemskeptondeath/ItemsKeptOnDeathPlugin.java index 8a6e1791a7..e8fc4b30d2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemskeptondeath/ItemsKeptOnDeathPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemskeptondeath/ItemsKeptOnDeathPlugin.java @@ -61,7 +61,7 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemMapping; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; @PluginDescriptor( name = "Items Kept on Death", @@ -570,7 +570,7 @@ public class ItemsKeptOnDeathPlugin extends Plugin total += (long) price * w.getItemQuantity(); } final Widget lostValue = client.getWidget(WidgetInfo.ITEMS_LOST_VALUE); - lostValue.setText(StackFormatter.quantityToStackSize(total) + " gp"); + lostValue.setText(QuantityFormatter.quantityToStackSize(total) + " gp"); // Update Max items kept final Widget max = client.getWidget(WidgetInfo.ITEMS_KEPT_MAX); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java index b0c218bad7..da58d97c54 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemstats/ItemStatPlugin.java @@ -62,7 +62,7 @@ import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.JagexColors; import net.runelite.client.ui.overlay.OverlayManager; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.http.api.item.ItemEquipmentStats; import net.runelite.http.api.item.ItemStats; @@ -340,7 +340,7 @@ public class ItemStatPlugin extends Plugin createSeparator(invContainer, invContainer.getHeight() - 40); - final String coinText = "You have " + StackFormatter.quantityToStackSize(getCurrentGP()) + final String coinText = "You have " + QuantityFormatter.quantityToStackSize(getCurrentGP()) + (getCurrentGP() == 1 ? " coin." : " coins."); final Widget coinWidget = createText(invContainer, coinText, FontID.PLAIN_12, ORANGE_TEXT, diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java index e2e6539d9f..aaaf0468b0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kingdomofmiscellania/KingdomCounter.java @@ -26,7 +26,7 @@ package net.runelite.client.plugins.kingdomofmiscellania; import java.awt.image.BufferedImage; import net.runelite.client.ui.overlay.infobox.Counter; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; public class KingdomCounter extends Counter { @@ -48,6 +48,6 @@ public class KingdomCounter extends Counter public String getTooltip() { return "Favor: " + plugin.getFavor() + "/127" + "
" - + "Coffer: " + StackFormatter.quantityToStackSize(plugin.getCoffer()); + + "Coffer: " + QuantityFormatter.quantityToStackSize(plugin.getCoffer()); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java index 372d1bd25a..e3a24ee377 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java @@ -53,7 +53,7 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.FontManager; import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; class LootTrackerBox extends JPanel @@ -181,8 +181,8 @@ class LootTrackerBox extends JPanel { buildItems(); - priceLabel.setText(StackFormatter.quantityToStackSize(totalPrice) + " gp"); - priceLabel.setToolTipText(StackFormatter.formatNumber(totalPrice) + " gp"); + priceLabel.setText(QuantityFormatter.quantityToStackSize(totalPrice) + " gp"); + priceLabel.setToolTipText(QuantityFormatter.formatNumber(totalPrice) + " gp"); final long kills = getTotalKills(); if (kills > 1) @@ -354,6 +354,6 @@ class LootTrackerBox extends JPanel final int quantity = item.getQuantity(); final long price = item.getPrice(); final String ignoredLabel = item.isIgnored() ? " - Ignored" : ""; - return name + " x " + quantity + " (" + StackFormatter.quantityToStackSize(price) + ") " + ignoredLabel; + return name + " x " + quantity + " (" + QuantityFormatter.quantityToStackSize(price) + ") " + ignoredLabel; } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java index e901a6820f..9dc783bab8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java @@ -50,7 +50,7 @@ import net.runelite.client.ui.PluginPanel; import net.runelite.client.ui.components.PluginErrorPanel; import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ImageUtil; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import net.runelite.http.api.loottracker.LootTrackerClient; class LootTrackerPanel extends PluginPanel @@ -629,7 +629,7 @@ class LootTrackerPanel extends PluginPanel private static String htmlLabel(String key, long value) { - final String valueStr = StackFormatter.quantityToStackSize(value); + final String valueStr = QuantityFormatter.quantityToStackSize(value); return String.format(HTML_LABEL_TEMPLATE, ColorUtil.toHexColor(ColorScheme.LIGHT_GRAY_COLOR), key, valueStr); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java index d732d14d3b..231d7f82c2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java @@ -43,7 +43,7 @@ import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; class NightmareZoneOverlay extends Overlay { @@ -108,15 +108,15 @@ class NightmareZoneOverlay extends Overlay panelComponent.getChildren().clear(); panelComponent.getChildren().add(LineComponent.builder() .left("Points: ") - .right(StackFormatter.formatNumber(currentPoints)) + .right(QuantityFormatter.formatNumber(currentPoints)) .build()); panelComponent.getChildren().add(LineComponent.builder() .left("Points/Hour: ") - .right(StackFormatter.formatNumber(plugin.getPointsPerHour())) + .right(QuantityFormatter.formatNumber(plugin.getPointsPerHour())) .build()); panelComponent.getChildren().add(LineComponent.builder() .left("Total: ") - .right(StackFormatter.formatNumber(totalPoints)) + .right(QuantityFormatter.formatNumber(totalPoints)) .build()); return panelComponent.render(graphics); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBox.java b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBox.java index 7d9dbe7723..53bad6208a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBox.java @@ -56,7 +56,7 @@ import net.runelite.client.ui.SkillColor; import net.runelite.client.ui.components.ProgressBar; import net.runelite.client.util.ColorUtil; import net.runelite.client.util.LinkBrowser; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; class XpInfoBox extends JPanel { @@ -310,7 +310,7 @@ class XpInfoBox extends JPanel static String htmlLabel(String key, int value) { - String valueStr = StackFormatter.quantityToRSDecimalStack(value, true); + String valueStr = QuantityFormatter.quantityToRSDecimalStack(value, true); return String.format(HTML_LABEL_TEMPLATE, ColorUtil.toHexColor(ColorScheme.LIGHT_GRAY_COLOR), key, valueStr); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBoxOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBoxOverlay.java index e64f398d07..f78db6f296 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBoxOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpInfoBoxOverlay.java @@ -44,7 +44,7 @@ import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.ProgressBarComponent; import net.runelite.client.ui.overlay.components.SplitComponent; -import net.runelite.client.util.StackFormatter; +import net.runelite.client.util.QuantityFormatter; import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG; import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; @@ -122,7 +122,7 @@ class XpInfoBoxOverlay extends Overlay final LineComponent xpLine = LineComponent.builder() .left(leftStr + ":") - .right(StackFormatter.quantityToRSDecimalStack(rightNum, true)) + .right(QuantityFormatter.quantityToRSDecimalStack(rightNum, true)) .build(); final String bottemLeftStr; @@ -143,7 +143,7 @@ class XpInfoBoxOverlay extends Overlay final LineComponent xpLineBottom = LineComponent.builder() .left(bottemLeftStr + ":") - .right(StackFormatter.quantityToRSDecimalStack(bottomRightNum, true)) + .right(QuantityFormatter.quantityToRSDecimalStack(bottomRightNum, true)) .build(); final SplitComponent xpSplit = SplitComponent.builder() diff --git a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java b/runelite-client/src/main/java/net/runelite/client/util/QuantityFormatter.java similarity index 98% rename from runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java rename to runelite-client/src/main/java/net/runelite/client/util/QuantityFormatter.java index 75d4a9c63f..49823b5cca 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/StackFormatter.java +++ b/runelite-client/src/main/java/net/runelite/client/util/QuantityFormatter.java @@ -35,7 +35,7 @@ import java.util.regex.Pattern; /** * A set of utility functions to use when formatting quantities */ -public class StackFormatter +public class QuantityFormatter { /** * A list of suffixes to use when formatting stack sizes. @@ -152,7 +152,7 @@ public class StackFormatter * @param string The string to convert. * @return A long representation of it. */ - public static synchronized long stackSizeToQuantity(String string) throws ParseException + public static synchronized long parseQuantity(String string) throws ParseException { int multiplier = getMultiplier(string); float parsedValue = NUMBER_FORMATTER.parse(string).floatValue(); diff --git a/runelite-client/src/test/java/net/runelite/client/util/QuantityFormatterTest.java b/runelite-client/src/test/java/net/runelite/client/util/QuantityFormatterTest.java new file mode 100644 index 0000000000..27ee40c41e --- /dev/null +++ b/runelite-client/src/test/java/net/runelite/client/util/QuantityFormatterTest.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018, arlyon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.util; + +import java.text.ParseException; +import java.util.Locale; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Test; + +public class QuantityFormatterTest +{ + @Before + public void setUp() + { + Locale.setDefault(Locale.ENGLISH); + } + + @Test + public void quantityToRSDecimalStackSize() + { + assertEquals("0", QuantityFormatter.quantityToRSDecimalStack(0)); + assertEquals("8500", QuantityFormatter.quantityToRSDecimalStack(8_500)); + assertEquals("10K", QuantityFormatter.quantityToRSDecimalStack(10_000)); + assertEquals("21.7K", QuantityFormatter.quantityToRSDecimalStack(21_700)); + assertEquals("100K", QuantityFormatter.quantityToRSDecimalStack(100_000)); + assertEquals("100.3K", QuantityFormatter.quantityToRSDecimalStack(100_300)); + assertEquals("1M", QuantityFormatter.quantityToRSDecimalStack(1_000_000)); + assertEquals("8.4M", QuantityFormatter.quantityToRSDecimalStack(8_450_000)); + assertEquals("10M", QuantityFormatter.quantityToRSDecimalStack(10_000_000)); + assertEquals("12.8M", QuantityFormatter.quantityToRSDecimalStack(12_800_000)); + assertEquals("100M", QuantityFormatter.quantityToRSDecimalStack(100_000_000)); + assertEquals("250.1M", QuantityFormatter.quantityToRSDecimalStack(250_100_000)); + assertEquals("1B", QuantityFormatter.quantityToRSDecimalStack(1_000_000_000)); + assertEquals("1.5B", QuantityFormatter.quantityToRSDecimalStack(1500_000_000)); + assertEquals("2.1B", QuantityFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE)); + } + + @Test + public void quantityToStackSize() + { + assertEquals("0", QuantityFormatter.quantityToStackSize(0)); + assertEquals("999", QuantityFormatter.quantityToStackSize(999)); + assertEquals("1,000", QuantityFormatter.quantityToStackSize(1000)); + assertEquals("9,450", QuantityFormatter.quantityToStackSize(9450)); + assertEquals("14.5K", QuantityFormatter.quantityToStackSize(14_500)); + assertEquals("99.9K", QuantityFormatter.quantityToStackSize(99_920)); + assertEquals("100K", QuantityFormatter.quantityToStackSize(100_000)); + assertEquals("10M", QuantityFormatter.quantityToStackSize(10_000_000)); + assertEquals("2.14B", QuantityFormatter.quantityToStackSize(Integer.MAX_VALUE)); + assertEquals("100B", QuantityFormatter.quantityToStackSize(100_000_000_000L)); + + assertEquals("0", QuantityFormatter.quantityToStackSize(-0)); + assertEquals("-400", QuantityFormatter.quantityToStackSize(-400)); + assertEquals("-400K", QuantityFormatter.quantityToStackSize(-400_000)); + assertEquals("-40M", QuantityFormatter.quantityToStackSize(-40_000_000)); + assertEquals("-2.14B", QuantityFormatter.quantityToStackSize(Integer.MIN_VALUE)); + assertEquals("-400B", QuantityFormatter.quantityToStackSize(-400_000_000_000L)); + } + + @Test + public void quantityToPreciseStackSize() + { + assertEquals("0", QuantityFormatter.quantityToRSDecimalStack(0)); + assertEquals("8500", QuantityFormatter.quantityToRSDecimalStack(8_500, true)); + assertEquals("10K", QuantityFormatter.quantityToRSDecimalStack(10_000, true)); + assertEquals("21.7K", QuantityFormatter.quantityToRSDecimalStack(21_710, true)); + assertEquals("100K", QuantityFormatter.quantityToRSDecimalStack(100_000, true)); + assertEquals("100.3K", QuantityFormatter.quantityToRSDecimalStack(100_310, true)); + assertEquals("1M", QuantityFormatter.quantityToRSDecimalStack(1_000_000, true)); + assertEquals("8.45M", QuantityFormatter.quantityToRSDecimalStack(8_450_000, true)); + assertEquals("8.451M", QuantityFormatter.quantityToRSDecimalStack(8_451_000, true)); + assertEquals("10M", QuantityFormatter.quantityToRSDecimalStack(10_000_000, true)); + assertEquals("12.8M", QuantityFormatter.quantityToRSDecimalStack(12_800_000, true)); + assertEquals("12.85M", QuantityFormatter.quantityToRSDecimalStack(12_850_000, true)); + assertEquals("12.851M", QuantityFormatter.quantityToRSDecimalStack(12_851_000, true)); + assertEquals("100M", QuantityFormatter.quantityToRSDecimalStack(100_000_000, true)); + assertEquals("250.1M", QuantityFormatter.quantityToRSDecimalStack(250_100_000, true)); + assertEquals("250.151M", QuantityFormatter.quantityToRSDecimalStack(250_151_000, true)); + assertEquals("1B", QuantityFormatter.quantityToRSDecimalStack(1_000_000_000, true)); + assertEquals("1.5B", QuantityFormatter.quantityToRSDecimalStack(1500_000_000, true)); + assertEquals("1.55B", QuantityFormatter.quantityToRSDecimalStack(1550_000_000, true)); + assertEquals("2.147B", QuantityFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE, true)); + } + + @Test + public void stackSizeToQuantity() throws ParseException + { + assertEquals(0, QuantityFormatter.parseQuantity("0")); + assertEquals(907, QuantityFormatter.parseQuantity("907")); + assertEquals(1200, QuantityFormatter.parseQuantity("1200")); + assertEquals(10_500, QuantityFormatter.parseQuantity("10,500")); + assertEquals(10_500, QuantityFormatter.parseQuantity("10.5K")); + assertEquals(33_560_000, QuantityFormatter.parseQuantity("33.56M")); + assertEquals(2_000_000_000, QuantityFormatter.parseQuantity("2B")); + + assertEquals(0, QuantityFormatter.parseQuantity("-0")); + assertEquals(-400, QuantityFormatter.parseQuantity("-400")); + assertEquals(-400_000, QuantityFormatter.parseQuantity("-400k")); + assertEquals(-40_543_000, QuantityFormatter.parseQuantity("-40.543M")); + + try + { + QuantityFormatter.parseQuantity("0L"); + fail("Should have thrown an exception for invalid suffix."); + } + catch (ParseException ignore) + { + } + + try + { + QuantityFormatter.parseQuantity("badstack"); + fail("Should have thrown an exception for improperly formatted stack."); + } + catch (ParseException ignore) + { + } + } +} diff --git a/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java b/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java deleted file mode 100644 index 23c3619a54..0000000000 --- a/runelite-client/src/test/java/net/runelite/client/util/StackFormatterTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2018, arlyon - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.util; - -import java.text.ParseException; -import java.util.Locale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import org.junit.Before; -import org.junit.Test; - -public class StackFormatterTest -{ - @Before - public void setUp() - { - Locale.setDefault(Locale.ENGLISH); - } - - @Test - public void quantityToRSDecimalStackSize() - { - assertEquals("0", StackFormatter.quantityToRSDecimalStack(0)); - assertEquals("8500", StackFormatter.quantityToRSDecimalStack(8_500)); - assertEquals("10K", StackFormatter.quantityToRSDecimalStack(10_000)); - assertEquals("21.7K", StackFormatter.quantityToRSDecimalStack(21_700)); - assertEquals("100K", StackFormatter.quantityToRSDecimalStack(100_000)); - assertEquals("100.3K", StackFormatter.quantityToRSDecimalStack(100_300)); - assertEquals("1M", StackFormatter.quantityToRSDecimalStack(1_000_000)); - assertEquals("8.4M", StackFormatter.quantityToRSDecimalStack(8_450_000)); - assertEquals("10M", StackFormatter.quantityToRSDecimalStack(10_000_000)); - assertEquals("12.8M", StackFormatter.quantityToRSDecimalStack(12_800_000)); - assertEquals("100M", StackFormatter.quantityToRSDecimalStack(100_000_000)); - assertEquals("250.1M", StackFormatter.quantityToRSDecimalStack(250_100_000)); - assertEquals("1B", StackFormatter.quantityToRSDecimalStack(1_000_000_000)); - assertEquals("1.5B", StackFormatter.quantityToRSDecimalStack(1500_000_000)); - assertEquals("2.1B", StackFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE)); - } - - @Test - public void quantityToStackSize() - { - assertEquals("0", StackFormatter.quantityToStackSize(0)); - assertEquals("999", StackFormatter.quantityToStackSize(999)); - assertEquals("1,000", StackFormatter.quantityToStackSize(1000)); - assertEquals("9,450", StackFormatter.quantityToStackSize(9450)); - assertEquals("14.5K", StackFormatter.quantityToStackSize(14_500)); - assertEquals("99.9K", StackFormatter.quantityToStackSize(99_920)); - assertEquals("100K", StackFormatter.quantityToStackSize(100_000)); - assertEquals("10M", StackFormatter.quantityToStackSize(10_000_000)); - assertEquals("2.14B", StackFormatter.quantityToStackSize(Integer.MAX_VALUE)); - assertEquals("100B", StackFormatter.quantityToStackSize(100_000_000_000L)); - - assertEquals("0", StackFormatter.quantityToStackSize(-0)); - assertEquals("-400", StackFormatter.quantityToStackSize(-400)); - assertEquals("-400K", StackFormatter.quantityToStackSize(-400_000)); - assertEquals("-40M", StackFormatter.quantityToStackSize(-40_000_000)); - assertEquals("-2.14B", StackFormatter.quantityToStackSize(Integer.MIN_VALUE)); - assertEquals("-400B", StackFormatter.quantityToStackSize(-400_000_000_000L)); - } - - @Test - public void quantityToPreciseStackSize() - { - assertEquals("0", StackFormatter.quantityToRSDecimalStack(0)); - assertEquals("8500", StackFormatter.quantityToRSDecimalStack(8_500, true)); - assertEquals("10K", StackFormatter.quantityToRSDecimalStack(10_000, true)); - assertEquals("21.7K", StackFormatter.quantityToRSDecimalStack(21_710, true)); - assertEquals("100K", StackFormatter.quantityToRSDecimalStack(100_000, true)); - assertEquals("100.3K", StackFormatter.quantityToRSDecimalStack(100_310, true)); - assertEquals("1M", StackFormatter.quantityToRSDecimalStack(1_000_000, true)); - assertEquals("8.45M", StackFormatter.quantityToRSDecimalStack(8_450_000, true)); - assertEquals("8.451M", StackFormatter.quantityToRSDecimalStack(8_451_000, true)); - assertEquals("10M", StackFormatter.quantityToRSDecimalStack(10_000_000, true)); - assertEquals("12.8M", StackFormatter.quantityToRSDecimalStack(12_800_000, true)); - assertEquals("12.85M", StackFormatter.quantityToRSDecimalStack(12_850_000, true)); - assertEquals("12.851M", StackFormatter.quantityToRSDecimalStack(12_851_000, true)); - assertEquals("100M", StackFormatter.quantityToRSDecimalStack(100_000_000, true)); - assertEquals("250.1M", StackFormatter.quantityToRSDecimalStack(250_100_000, true)); - assertEquals("250.151M", StackFormatter.quantityToRSDecimalStack(250_151_000, true)); - assertEquals("1B", StackFormatter.quantityToRSDecimalStack(1_000_000_000, true)); - assertEquals("1.5B", StackFormatter.quantityToRSDecimalStack(1500_000_000, true)); - assertEquals("1.55B", StackFormatter.quantityToRSDecimalStack(1550_000_000, true)); - assertEquals("2.147B", StackFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE, true)); - } - - @Test - public void stackSizeToQuantity() throws ParseException - { - assertEquals(0, StackFormatter.stackSizeToQuantity("0")); - assertEquals(907, StackFormatter.stackSizeToQuantity("907")); - assertEquals(1200, StackFormatter.stackSizeToQuantity("1200")); - assertEquals(10_500, StackFormatter.stackSizeToQuantity("10,500")); - assertEquals(10_500, StackFormatter.stackSizeToQuantity("10.5K")); - assertEquals(33_560_000, StackFormatter.stackSizeToQuantity("33.56M")); - assertEquals(2_000_000_000, StackFormatter.stackSizeToQuantity("2B")); - - assertEquals(0, StackFormatter.stackSizeToQuantity("-0")); - assertEquals(-400, StackFormatter.stackSizeToQuantity("-400")); - assertEquals(-400_000, StackFormatter.stackSizeToQuantity("-400k")); - assertEquals(-40_543_000, StackFormatter.stackSizeToQuantity("-40.543M")); - - try - { - StackFormatter.stackSizeToQuantity("0L"); - fail("Should have thrown an exception for invalid suffix."); - } - catch (ParseException ignore) - { - } - - try - { - StackFormatter.stackSizeToQuantity("badstack"); - fail("Should have thrown an exception for improperly formatted stack."); - } - catch (ParseException ignore) - { - } - } -}