aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils/Calculator.java
diff options
context:
space:
mode:
authorolim <bobq4582@gmail.com>2024-04-26 18:01:09 +0100
committerolim <bobq4582@gmail.com>2024-05-09 22:42:35 +0100
commitfeee94e2c2ce01262f3eb47d7b356ca9821bdb79 (patch)
treef8ad3cec616891250d445b2cf02f4dbc5504466b /src/main/java/de/hysky/skyblocker/utils/Calculator.java
parenta442eefc1d47fdc66d361a6dc35a9412521626f8 (diff)
downloadSkyblocker-feee94e2c2ce01262f3eb47d7b356ca9821bdb79.tar.gz
Skyblocker-feee94e2c2ce01262f3eb47d7b356ca9821bdb79.tar.bz2
Skyblocker-feee94e2c2ce01262f3eb47d7b356ca9821bdb79.zip
add command
add command to be able to use the calculator and fix crash with emty equations
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/Calculator.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/Calculator.java14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Calculator.java b/src/main/java/de/hysky/skyblocker/utils/Calculator.java
index c8dcb6d8..19155708 100644
--- a/src/main/java/de/hysky/skyblocker/utils/Calculator.java
+++ b/src/main/java/de/hysky/skyblocker/utils/Calculator.java
@@ -1,6 +1,5 @@
package de.hysky.skyblocker.utils;
-import de.hysky.skyblocker.skyblock.SignCalculator;
import net.minecraft.util.Util;
import java.util.*;
@@ -148,9 +147,7 @@ public class Calculator {
case "*","/" -> {
return 1;
}
- default -> {
- throw new UnsupportedOperationException("invalid operator");
- }
+ default -> throw new UnsupportedOperationException("Invalid operator");
}
}
@@ -188,24 +185,27 @@ public class Calculator {
}
}
case L_PARENTHESIS, R_PARENTHESIS -> {
- throw new UnsupportedOperationException("equation is not in RPN");
+ throw new UnsupportedOperationException("Equation is not in RPN");
}
}
}
+ if (values.isEmpty()) {
+ throw new UnsupportedOperationException("Equation is empty");
+ }
return values.pop();
}
private static double calculateValue(String value) {
Matcher numberMatcher = NUMBER_PATTERN.matcher(value.toLowerCase());
if (!numberMatcher.matches()) {
- throw new UnsupportedOperationException("invalid number");
+ throw new UnsupportedOperationException("Invalid number");
}
double number = Double.parseDouble(numberMatcher.group(1));
String magnitude = numberMatcher.group(2);
if (!magnitude.isEmpty()) {
if (!magnitudeValues.containsKey(magnitude)) {//its invalid if its another letter
- throw new UnsupportedOperationException("invalid magnitude");
+ throw new UnsupportedOperationException("Invalid magnitude");
}
number *= magnitudeValues.get(magnitude);
}