Created
February 23, 2015 18:57
-
-
Save Ivorforce/f3007ff7bab2fb777be5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2014, Lukas Tenbrink. | |
* * http://lukas.axxim.net | |
*/ | |
package ivorius.reccomplex.utils; | |
import com.google.common.base.Function; | |
import com.google.common.base.Predicate; | |
/** | |
* Created by lukas on 23.02.15. | |
*/ | |
public abstract class BooleanExpression | |
{ | |
public static Predicate<Predicate<String>> parse(String string) | |
{ | |
int index = 0; | |
while (index < string.length()) | |
{ | |
break; | |
} | |
return null; | |
} | |
public static <T> Predicate<Predicate<T>> mapExpression(final Predicate<Predicate<String>> expression, final Function<String, T> mapping) | |
{ | |
return new Predicate<Predicate<T>>() | |
{ | |
@Override | |
public boolean apply(final Predicate<T> tPredicate) | |
{ | |
return expression.apply(new Predicate<String>() | |
{ | |
@Override | |
public boolean apply(String input) | |
{ | |
return tPredicate.apply(mapping.apply(input)); | |
} | |
}); | |
} | |
}; | |
} | |
public abstract static class Unary implements Predicate<Predicate<String>> | |
{ | |
public Predicate<Predicate<String>> expression; | |
public Unary(Predicate<Predicate<String>> expression) | |
{ | |
this.expression = expression; | |
} | |
} | |
public abstract static class Binary implements Predicate<Predicate<String>> | |
{ | |
public Predicate<Predicate<String>> left; | |
public Predicate<Predicate<String>> right; | |
public Binary(Predicate<Predicate<String>> left, Predicate<Predicate<String>> right) | |
{ | |
this.left = left; | |
this.right = right; | |
} | |
} | |
public static class Variable implements Predicate<Predicate<String>> | |
{ | |
public String variable; | |
public Variable(String variable) | |
{ | |
this.variable = variable; | |
} | |
@Override | |
public boolean apply(Predicate<String> input) | |
{ | |
return input != null && input.apply(variable); | |
} | |
} | |
public static class Not extends Unary | |
{ | |
public Not(Predicate<Predicate<String>> expression) | |
{ | |
super(expression); | |
} | |
@Override | |
public boolean apply(Predicate<String> input) | |
{ | |
return !expression.apply(input); | |
} | |
} | |
public static class And extends Binary | |
{ | |
public And(Predicate<Predicate<String>> left, Predicate<Predicate<String>> right) | |
{ | |
super(left, right); | |
} | |
@Override | |
public boolean apply(Predicate<String> input) | |
{ | |
return left.apply(input) && right.apply(input); | |
} | |
} | |
public static class Or extends Binary | |
{ | |
public Or(Predicate<Predicate<String>> left, Predicate<Predicate<String>> right) | |
{ | |
super(left, right); | |
} | |
@Override | |
public boolean apply(Predicate<String> input) | |
{ | |
return left.apply(input) || right.apply(input); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment