Skip to content

Commit

Permalink
make retriable and unretriable exceptions runtime exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pitabwire committed Aug 14, 2024
1 parent b759d98 commit 7e86ae0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
/**
* @author Peter J. Bwire <bwire517@gmail.com>
*/
public class RetriableException extends Exception {
public class RetriableException extends RuntimeException {
private final int status;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
/**
* @author Peter J. Bwire <bwire517@gmail.com>
*/
public class UnRetriableException extends Exception {
public class UnRetriableException extends RuntimeException {
private final int status;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ public static String toString(Money money) {

}

public static boolean isEqual(Money a, Money b) throws UnRetriableException {
public static boolean isEqual(Money a, Money b) {
return compare(a, b) == 0;
}

public static boolean isZero(Money money) throws UnRetriableException {
public static boolean isZero(Money money) {
return isEqual(money, zeroMoney(money.getCurrencyCode()));
}

public static boolean isGreaterThan(Money a, Money b) throws UnRetriableException {
return compare(a, b) > 0;
}

public static boolean isGreaterThanZero(Money money) throws UnRetriableException {
public static boolean isGreaterThanZero(Money money) {
return isGreaterThan(money, zeroMoney(money.getCurrencyCode()));
}

public static boolean isLessThan(Money a, Money b) throws UnRetriableException {
public static boolean isLessThan(Money a, Money b) {
return compare(a, b) < 0;
}

public static boolean isLessThanZero(Money money) throws UnRetriableException {
public static boolean isLessThanZero(Money money) {
return isLessThan(money, zeroMoney(money.getCurrencyCode()));
}

public static Money zeroMoney(String currency) {
return from(BigDecimal.ZERO, currency);
}

public static Money add(Money a, Money b) throws UnRetriableException {
public static Money add(Money a, Money b) {
if (Objects.isNull(a) || Objects.isNull(b)) {
throw new UnRetriableException(STATUSCODES.BAD_DATE_ERROR, "Attempting to add null money");
}
Expand All @@ -90,7 +90,7 @@ public static Money add(Money a, Money b) throws UnRetriableException {
return from(toBigDecimal(a).add(toBigDecimal(b)), a.getCurrencyCode());
}

public static Money subtract(Money a, Money b) throws UnRetriableException {
public static Money subtract(Money a, Money b) {
if (Objects.isNull(a) || Objects.isNull(b)) {
throw new UnRetriableException(STATUSCODES.BAD_DATE_ERROR, "Attempting to subtract null money");
}
Expand All @@ -102,7 +102,7 @@ public static Money subtract(Money a, Money b) throws UnRetriableException {
return from(toBigDecimal(a).subtract(toBigDecimal(b)), a.getCurrencyCode());
}

public static Money multiply(Money a, BigDecimal b) throws UnRetriableException {
public static Money multiply(Money a, BigDecimal b) {
if (Objects.isNull(a) || Objects.isNull(b)) {
throw new UnRetriableException(STATUSCODES.BAD_DATE_ERROR, "Attempting to multiply with nulls ");
}
Expand All @@ -111,7 +111,7 @@ public static Money multiply(Money a, BigDecimal b) throws UnRetriableException
return from(toBigDecimal(a).multiply(b), a.getCurrencyCode());
}

public static Money divide(Money a, BigDecimal b) throws UnRetriableException {
public static Money divide(Money a, BigDecimal b) {
if (Objects.isNull(a) || Objects.isNull(b)) {
throw new UnRetriableException(STATUSCODES.BAD_DATE_ERROR, "Attempting to divide with nulls ");
}
Expand All @@ -123,16 +123,16 @@ public static String format(Money money) {
return String.format("%s %s", money.getCurrencyCode(), toBigDecimal(money).setScale(2, RoundingMode.DOWN).toPlainString());
}

public static Money min(Money a, Money b) throws UnRetriableException {
public static Money min(Money a, Money b) {
return compare(a, b) <= 0 ? a : b;
}


public static Money max(Money a, Money b) throws UnRetriableException {
public static Money max(Money a, Money b) {
return compare(a, b) >= 0 ? a : b;
}

public static int compare(Money a, Money b) throws UnRetriableException {
public static int compare(Money a, Money b) {
validateMoney(a, b);

if (!a.getCurrencyCode().equals(b.getCurrencyCode())) {
Expand All @@ -143,7 +143,7 @@ public static int compare(Money a, Money b) throws UnRetriableException {
return unitsComparison != 0 ? unitsComparison : Integer.compare(a.getNanos(), b.getNanos());
}

private static void validateMoney(Money... moneys) throws UnRetriableException {
private static void validateMoney(Money... moneys) {
String currency = null;
for (Money money : moneys) {
if (Objects.isNull(money)) {
Expand Down

0 comments on commit 7e86ae0

Please sign in to comment.