Merge pull request #10027 from abextm/quantity-formatter

Fix documentation/naming/safety of StackFormatter
This commit is contained in:
Adam
2019-10-16 12:39:34 -04:00
committed by GitHub
24 changed files with 270 additions and 342 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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);

View File

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

View File

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

View File

@@ -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)");
}

View File

@@ -42,7 +42,7 @@ import javax.swing.border.EmptyBorder;
import net.runelite.client.util.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)));

View File

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

View File

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

View File

@@ -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)");
}
}

View File

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

View File

@@ -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 += "<p><span style = 'color:white'>Skill:</span> Combat</p>";
content += "<p><span style = 'color:white'>Exact Combat Level:</span> " + StackFormatter.formatNumber(combatLevel) + "</p>";
content += "<p><span style = 'color:white'>Experience:</span> " + StackFormatter.formatNumber(combatExperience) + "</p>";
content += "<p><span style = 'color:white'>Exact Combat Level:</span> " + QuantityFormatter.formatNumber(combatLevel) + "</p>";
content += "<p><span style = 'color:white'>Experience:</span> " + QuantityFormatter.formatNumber(combatExperience) + "</p>";
}
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 += "<p><span style = 'color:white'>All:</span> " + all + " <span style = 'color:white'>Rank:</span> " + allRank + "</p>";
content += "<p><span style = 'color:white'>Beginner:</span> " + beginner + " <span style = 'color:white'>Rank:</span> " + beginnerRank + "</p>";
content += "<p><span style = 'color:white'>Easy:</span> " + easy + " <span style = 'color:white'>Rank:</span> " + easyRank + "</p>";
@@ -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 += "<p><span style = 'color:white'>Rank:</span> " + rank + "</p>";
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 += "<p><span style = 'color:white'>Rank:</span> " + rank + "</p>";
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 += "<p><span style = 'color:white'>Rank:</span> " + rank + "</p>";
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 += "<p><span style = 'color:white'>Skill:</span> " + skill.getName() + "</p>";
content += "<p><span style = 'color:white'>Rank:</span> " + rank + "</p>";
content += "<p><span style = 'color:white'>Experience:</span> " + exp + "</p>";
@@ -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 += "<p><span style = 'color:white'>Skill:</span> " + skill.getName() + "</p>";

View File

@@ -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)");
}
}

View File

@@ -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);

View File

@@ -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.quantityToRSStackSize(getCurrentGP())
final String coinText = "You have " + QuantityFormatter.quantityToStackSize(getCurrentGP())
+ (getCurrentGP() == 1 ? " coin." : " coins.");
final Widget coinWidget = createText(invContainer, coinText, FontID.PLAIN_12, ORANGE_TEXT,

View File

@@ -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" + "</br>"
+ "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer());
+ "Coffer: " + QuantityFormatter.quantityToStackSize(plugin.getCoffer());
}
}

View File

@@ -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;
}
}

View File

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

View File

@@ -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);

View File

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

View File

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

View File

@@ -33,10 +33,9 @@ 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
public class QuantityFormatter
{
/**
* A list of suffixes to use when formatting stack sizes.
@@ -48,36 +47,27 @@ 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)
);
/**
* 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)
public static synchronized String quantityToStackSize(long quantity)
{
if (quantity < 0)
{
@@ -115,49 +105,12 @@ 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)
* <p>
* This differs from quantityToRSStack in that it displays
* decimals. Ex: 27100 is 27.1k (not 27k)
* <p>
*
* @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)
{
@@ -165,19 +118,16 @@ public class StackFormatter
}
/**
* Convert a quantity to stack size as it would
* appear in RuneScape. (with decimals)
* <p>
* This differs from quantityToRSStack in that it displays
* decimals. Ex: 27100 is 27.1k (not 27k)
* <p>
*
* @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)
public static synchronized String quantityToRSDecimalStack(int quantity, boolean precise)
{
String quantityStr = String.valueOf(quantity);
if (quantityStr.length() <= 4)
@@ -202,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 parseQuantity(String string) throws ParseException
{
int multiplier = getMultiplier(string);
float parsedValue = NUMBER_FORMATTER.parse(string).floatValue();
@@ -210,29 +160,23 @@ 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)
public static synchronized 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)
public static synchronized String formatNumber(double number)
{
return NUMBER_FORMATTER.format(number);
}