Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Attempt to fix "java.lang.ArithmeticException: / by zero" #91

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -926,55 +926,63 @@ public String[] getInfoData() {
// Check if the system is charging or discharging
if (avgIn > avgOut) {
// Calculate time to full if charging
if (avgIn != 0) {
double timeToFull = (capacity.longValue() - stored.longValue()) / avgIn / 20;
String timeToFullString = formatTime(timeToFull);
ll.add("Time to Full: " + timeToFullString);
}
} else {
try {
if (avgIn != 0) {
double timeToFull = (capacity.longValue() - stored.longValue()) / avgIn / 20;
String timeToFullString = formatTime(timeToFull);
ll.add("Time to Full: " + timeToFullString);
} throw new DivideByZeroException("avgIn: Division by zero is undifined!");
} catch (DivideByZeroException e) {
System.err.print(e.getMessage());
}
} else {
// In case of a discharging LSC
// Calculate time to empty if discharging
if (avgOut != 0) {
double timeToEmpty = stored.longValue() / avgOut / 20;
String timeToEmptyString = formatTime(timeToEmpty);
ll.add("Time to Empty: " + timeToEmptyString);
}
try {
if (avgOut != 0) {
double timeToEmpty = stored.longValue() / avgOut / 20;
String timeToEmptyString = formatTime(timeToEmpty);
ll.add("Time to Empty: " + timeToEmptyString);
} throw new DivideByZeroException("avgOut: Division by zero is undifined!");
} catch (DivideByZeroException e) {
System.err.print(e.getMessage());
}
}
ll.add(
"Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus())
? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET
: EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET));
"Maintenance Status: " + ((super.getRepairStatus() == super.getIdealStatus())
? EnumChatFormatting.GREEN + "Working perfectly" + EnumChatFormatting.RESET
: EnumChatFormatting.RED + "Has Problems" + EnumChatFormatting.RESET));
ll.add(
"Wireless mode: " + (wireless_mode ? EnumChatFormatting.GREEN + "enabled" + EnumChatFormatting.RESET
: EnumChatFormatting.RED + "disabled" + EnumChatFormatting.RESET));
"Wireless mode: " + (wireless_mode ? EnumChatFormatting.GREEN + "enabled" + EnumChatFormatting.RESET
: EnumChatFormatting.RED + "disabled" + EnumChatFormatting.RESET));
ll.add(
GT_Values.TIER_COLORS[9] + GT_Values.VN[9]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUHVCapacitorCount());
GT_Values.TIER_COLORS[9] + GT_Values.VN[9]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUHVCapacitorCount());
ll.add(
GT_Values.TIER_COLORS[10] + GT_Values.VN[10]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUEVCapacitorCount());
GT_Values.TIER_COLORS[10] + GT_Values.VN[10]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUEVCapacitorCount());
ll.add(
GT_Values.TIER_COLORS[11] + GT_Values.VN[11]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUIVCapacitorCount());
GT_Values.TIER_COLORS[11] + GT_Values.VN[11]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUIVCapacitorCount());
ll.add(
GT_Values.TIER_COLORS[12] + GT_Values.VN[12]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUMVCapacitorCount());
GT_Values.TIER_COLORS[12] + GT_Values.VN[12]
+ EnumChatFormatting.RESET
+ " Capacitors detected: "
+ getUMVCapacitorCount());
ll.add(
"Total wireless EU: " + EnumChatFormatting.RED
+ nf.format(WirelessNetworkManager.getUserEU(global_energy_user_uuid))
+ " EU");
"Total wireless EU: " + EnumChatFormatting.RED
+ nf.format(WirelessNetworkManager.getUserEU(global_energy_user_uuid))
+ " EU");
ll.add(
"Total wireless EU: " + EnumChatFormatting.RED
+ toStandardForm(WirelessNetworkManager.getUserEU(global_energy_user_uuid))
+ " EU");

"Total wireless EU: " + EnumChatFormatting.RED
+ toStandardForm(WirelessNetworkManager.getUserEU(global_energy_user_uuid))
+ " EU");
final String[] a = new String[ll.size()];
return ll.toArray(a);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/exceptions/DivideByZeroException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package exceptions;

public class DivideByZeroException extends RuntimeException {

private static final long serialVersionUID = 1L;

DivideByZeroException(String errorMessage){
super(errorMessage);
}
}