mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-06-26 01:00:25 +00:00
Refactor Project to Gradle (#3720)
Gradle is better than Maven, don't @ me. okay but actually it's [faster](https://www.youtube.com/watch?v=atuFSv2bLa8&feature=youtu.be&t=77), compiles and tests in parallel more efficiently, and more epic stuff).
This commit is contained in:
parent
82b466db0b
commit
9a23f806fe
516 changed files with 1297 additions and 1445 deletions
|
@ -1,118 +0,0 @@
|
|||
package com.earth2me.essentials.utils;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public final class NumberUtil {
|
||||
|
||||
private static final DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
|
||||
private static final DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
// This field is likely to be modified in com.earth2me.essentials.Settings when loading currency format.
|
||||
// This ensures that we can supply a constant formatting.
|
||||
private static NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||
|
||||
static {
|
||||
twoDPlaces.setRoundingMode(RoundingMode.HALF_UP);
|
||||
currencyFormat.setRoundingMode(RoundingMode.FLOOR);
|
||||
|
||||
PRETTY_FORMAT.setRoundingMode(RoundingMode.FLOOR);
|
||||
PRETTY_FORMAT.setGroupingUsed(true);
|
||||
PRETTY_FORMAT.setMinimumFractionDigits(2);
|
||||
PRETTY_FORMAT.setMaximumFractionDigits(2);
|
||||
}
|
||||
|
||||
private NumberUtil() {
|
||||
}
|
||||
|
||||
// this method should only be called by Essentials
|
||||
public static void internalSetPrettyFormat(final NumberFormat prettyFormat) {
|
||||
PRETTY_FORMAT = prettyFormat;
|
||||
}
|
||||
|
||||
public static String shortCurrency(final BigDecimal value, final IEssentials ess) {
|
||||
if (ess.getSettings().isCurrencySymbolSuffixed()) {
|
||||
return formatAsCurrency(value) + ess.getSettings().getCurrencySymbol();
|
||||
}
|
||||
return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value);
|
||||
}
|
||||
|
||||
public static String formatDouble(final double value) {
|
||||
return twoDPlaces.format(value);
|
||||
}
|
||||
|
||||
public static String formatAsCurrency(final BigDecimal value) {
|
||||
String str = currencyFormat.format(value);
|
||||
if (str.endsWith(".00")) {
|
||||
str = str.substring(0, str.length() - 3);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String formatAsPrettyCurrency(final BigDecimal value) {
|
||||
String str = PRETTY_FORMAT.format(value);
|
||||
if (str.endsWith(".00")) {
|
||||
str = str.substring(0, str.length() - 3);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String displayCurrency(final BigDecimal value, final IEssentials ess) {
|
||||
String currency = formatAsPrettyCurrency(value);
|
||||
String sign = "";
|
||||
if (value.signum() < 0) {
|
||||
currency = currency.substring(1);
|
||||
sign = "-";
|
||||
}
|
||||
if (ess.getSettings().isCurrencySymbolSuffixed()) {
|
||||
return sign + tl("currency", currency, ess.getSettings().getCurrencySymbol());
|
||||
}
|
||||
return sign + tl("currency", ess.getSettings().getCurrencySymbol(), currency);
|
||||
}
|
||||
|
||||
public static String displayCurrencyExactly(final BigDecimal value, final IEssentials ess) {
|
||||
String currency = value.toPlainString();
|
||||
String sign = "";
|
||||
if (value.signum() < 0) {
|
||||
currency = currency.substring(1);
|
||||
sign = "-";
|
||||
}
|
||||
if (ess.getSettings().isCurrencySymbolSuffixed()) {
|
||||
return sign + tl("currency", currency, ess.getSettings().getCurrencySymbol());
|
||||
}
|
||||
return sign + tl("currency", ess.getSettings().getCurrencySymbol(), currency);
|
||||
}
|
||||
|
||||
public static String sanitizeCurrencyString(final String input, final IEssentials ess) {
|
||||
final String symbol = ess.getSettings().getCurrencySymbol();
|
||||
final boolean suffix = ess.getSettings().isCurrencySymbolSuffixed();
|
||||
if (input.contains(symbol)) {
|
||||
return suffix ? input.substring(0, input.indexOf(symbol)) : input.substring(symbol.length());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static boolean isInt(final String sInt) {
|
||||
try {
|
||||
Integer.parseInt(sInt);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isPositiveInt(final String sInt) {
|
||||
if (!isInt(sInt)) {
|
||||
return false;
|
||||
}
|
||||
return Integer.parseInt(sInt) > 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue