...
Code Block |
---|
S → SS S → (S) S → () S → key KEY KEY → operator OPERATOR OPERATOR → value VALUE OPERATOR → value VALUE → value VALUE VALUE → value VALUE → and AND VALUE → or OR AND → S OR → S |
Psuedocode
Criteria and Builder
The mechanism by which the user can create a valid Criteria with guidance.
Code Block |
---|
public class Criteria {
// Static Methods
public static Builder builder();
// Variables
private final List<Symbol> symbols;
// Constructor
protected Criteria();
// Methods
protected void addSymbol(Symbol symbol);
public static final Builder {
// Static methods
protected static Builder newBuilder();
// Variables
private final Criteria criteria;
private State state;
// Constructor
private Builder(Criteria criteria);
}
} |
Symbol
A marker interface to indicate an object that can be included in a Criteria
Code Block |
---|
interface Symbol {} //marker interface |
Conjunction
An enum that represents the possible conjunction symbols.
Code Block |
---|
enum Conjunction implements Symbol {
AND, OR;
} |
Parenthesis
An enum that represents the possible parenthesis symbols.
Code Block |
---|
enum Parenthesis implements Symbol {
LEFT, RIGHT;
} |
Key
A symbol that represents a "key" in a Criteria.
Code Block |
---|
class Key implements Symbol {
public String getKey();
} |
Value
A symbol that represents a "value" in a Criteria.
Code Block |
---|
class Value implements Symbol {
public Object getValue();
} |
State
A state
Code Block |
---|
abstract class State {
Criteria criteria;
} |
Code Block |
---|
interface Symbol { } //marker interface
KeySymbol implements Symbol {
String key;
}
ValueSymbol implements Symbol {
Object value;
}
OperatorSymbol implements Symbol {
Operator operator;
} |
Order of Operations
Given validly formed grouped criteria, we must process everything with the correct order of operations. For this, we should use the Shunting-yard algorithm. I've written this algorithm in PHP so we should port it to Java.
...