Skip to content

Commit

Permalink
Fix issues with commit
Browse files Browse the repository at this point in the history
- toString() boolean properly
- Use a , not ;
  • Loading branch information
sabihoshi committed Feb 28, 2020
1 parent 620c1af commit c897261
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/main/java/com/jagrosh/jagtag/libraries/Functional.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
/**
* Functional Library
* Methods for conditionals and mathematics
*
*
* @author John Grosh (jagrosh)
*/
public class Functional {

public static Collection<Method> getMethods() {
return Arrays.asList(
// equivalent to a comment; gets removed at runtime
new Method("note", (env,in) -> ""),

// chooses randomly between options
new Method("choose", (env,in) -> {return in.length==0 ? "" : in[(int)(Math.random()*in.length)];}, true),

// picks a random number in the provided range
new Method("range", (env,in) -> {
try{
Expand All @@ -52,7 +52,7 @@ public static Collection<Method> getMethods() {
return in[0]+"|"+in[1];
}
}, "|"),

// performs a conditional
new Method("if", (env,in) -> {
if(in[0].equalsIgnoreCase("true"))
Expand All @@ -70,8 +70,8 @@ public static Collection<Method> getMethods() {
return "true";
if(in[0].equalsIgnoreCase("false"))
return "false";
return evaluateStatement(in[0]);
});
return Boolean.toString(evaluateStatement(in[0]));
}),

// performs a switch conditional
new Method("switch", (env,in) -> {
Expand All @@ -87,12 +87,12 @@ public static Collection<Method> getMethods() {

return in[in.length - 1];
}, "|cases:", "|default:"),

// performs basic mathematical function
new Method("math", (env,in) -> {
return evaluateMath(in[0]);
}),

// returns the absolute value of the provided number
new Method("abs", (env,in) -> {
try {
Expand All @@ -103,7 +103,7 @@ public static Collection<Method> getMethods() {
} catch(NumberFormatException e){}
return in[0];
}),

// rounds a number down
new Method("floor", (env,in) -> {
try {
Expand All @@ -112,7 +112,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// rounds a number up
new Method("ceil", (env,in) -> {
try {
Expand All @@ -121,7 +121,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// rounds a number up if the decimal part is .5 or greater, down otherwise
new Method("round", (env,in) -> {
try {
Expand All @@ -130,7 +130,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// takes the sine of radians
new Method("sin", (env,in) -> {
try {
Expand All @@ -139,7 +139,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// takes the cosine of radians
new Method("cos", (env,in) -> {
try {
Expand All @@ -148,7 +148,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// takes the tangent of radians
new Method("tan", (env,in) -> {
try {
Expand All @@ -157,7 +157,7 @@ public static Collection<Method> getMethods() {
return in[0];
}
}),

// converts a number to a different base
new Method("base", (env, in) -> {
try {
Expand All @@ -168,7 +168,7 @@ public static Collection<Method> getMethods() {
},true)
);
}

private static String evaluateMath(String statement)
{
int index = statement.lastIndexOf("|+|");
Expand Down Expand Up @@ -225,7 +225,7 @@ private static String evaluateMath(String statement)
}
return statement;
}

private static boolean evaluateStatement(String statement)
{
int index = statement.indexOf("|=|");
Expand All @@ -241,7 +241,7 @@ private static boolean evaluateStatement(String statement)
return false;
String s1 = statement.substring(0, index).trim();
String s2 = statement.substring(index+3).trim();

try{
double i1 = Double.parseDouble(s1);
double i2 = Double.parseDouble(s2);
Expand All @@ -257,7 +257,7 @@ private static boolean evaluateStatement(String statement)
return (i1<i2);
}
}catch(NumberFormatException e){}

switch(statement.substring(index, index+3))
{
case "|=|":
Expand Down

0 comments on commit c897261

Please sign in to comment.