Add null checks to print payacct/offer/trade utils

This commit is contained in:
ghubstan 2022-06-29 18:05:37 -03:00
parent c9443d1472
commit 897401ba0e
No known key found for this signature in database
GPG Key ID: E35592D6800A861E

View File

@ -42,6 +42,7 @@ import static java.lang.String.format;
import static java.lang.System.*; import static java.lang.System.*;
import static java.math.BigDecimal.ZERO; import static java.math.BigDecimal.ZERO;
import static java.math.RoundingMode.HALF_UP; import static java.math.RoundingMode.HALF_UP;
import static java.util.Objects.requireNonNull;
/** /**
* Convenience methods and functions not depending on a bot's state nor the need to send requests to the API daemon. * Convenience methods and functions not depending on a bot's state nor the need to send requests to the API daemon.
@ -407,6 +408,7 @@ public class BotUtils {
* @param offer printed offer * @param offer printed offer
*/ */
public static void printOfferSummary(OfferInfo offer) { public static void printOfferSummary(OfferInfo offer) {
requireNonNull(offer, "OfferInfo offer param cannot be null.");
new TableBuilder(OFFER_TBL, offer).build().print(out); new TableBuilder(OFFER_TBL, offer).build().print(out);
} }
@ -416,8 +418,13 @@ public class BotUtils {
* @param offers printed offer list * @param offers printed offer list
*/ */
public static void printOffersSummary(List<OfferInfo> offers) { public static void printOffersSummary(List<OfferInfo> offers) {
requireNonNull(offers, "List<OfferInfo> offers param cannot be null.");
if (offers.isEmpty()) {
log.info("No offers to print.");
} else {
new TableBuilder(OFFER_TBL, offers).build().print(out); new TableBuilder(OFFER_TBL, offers).build().print(out);
} }
}
/** /**
* Print trade summary to stdout. * Print trade summary to stdout.
@ -425,6 +432,7 @@ public class BotUtils {
* @param trade printed trade * @param trade printed trade
*/ */
public static void printTradeSummary(TradeInfo trade) { public static void printTradeSummary(TradeInfo trade) {
requireNonNull(trade, "TradeInfo trade param cannot be null.");
new TableBuilder(TRADE_DETAIL_TBL, trade).build().print(out); new TableBuilder(TRADE_DETAIL_TBL, trade).build().print(out);
} }
@ -435,12 +443,17 @@ public class BotUtils {
* @param trades list of trades * @param trades list of trades
*/ */
public static void printTradesSummary(GetTradesRequest.Category category, List<TradeInfo> trades) { public static void printTradesSummary(GetTradesRequest.Category category, List<TradeInfo> trades) {
requireNonNull(trades, "List<TradeInfo> trades param cannot be null.");
if (trades.isEmpty()) {
log.info("No trades to print.");
} else {
switch (category) { switch (category) {
case CLOSED -> new TableBuilder(CLOSED_TRADES_TBL, trades).build().print(out); case CLOSED -> new TableBuilder(CLOSED_TRADES_TBL, trades).build().print(out);
case FAILED -> new TableBuilder(FAILED_TRADES_TBL, trades).build().print(out); case FAILED -> new TableBuilder(FAILED_TRADES_TBL, trades).build().print(out);
default -> new TableBuilder(OPEN_TRADES_TBL, trades).build().print(out); default -> new TableBuilder(OPEN_TRADES_TBL, trades).build().print(out);
} }
} }
}
/** /**
* Prints PaymentAccount summary to stdout. * Prints PaymentAccount summary to stdout.
@ -448,6 +461,7 @@ public class BotUtils {
* @param paymentAccount the printed PaymentAccount * @param paymentAccount the printed PaymentAccount
*/ */
public static void printPaymentAccountSummary(PaymentAccount paymentAccount) { public static void printPaymentAccountSummary(PaymentAccount paymentAccount) {
requireNonNull(paymentAccount, "PaymentAccount paymentAccount param cannot be null.");
new TableBuilder(PAYMENT_ACCOUNT_TBL, paymentAccount).build().print(out); new TableBuilder(PAYMENT_ACCOUNT_TBL, paymentAccount).build().print(out);
} }