Class PredicateParser
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.query.node.PredicateParser
-
public class PredicateParser extends java.lang.Object
Basically follows Dijkstra's shunting yard algorithm to ensure correct handling of operator precedence as the expression nodes are added
-
-
Constructor Summary
Constructors Constructor Description PredicateParser()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add()
Add an addition + node to the expressionvoid
addToken(ExpNode token)
Allow expression nodes to be added directly to the list of tokens.void
and()
Push an AND node to the stack, taking into account precedencevoid
between()
Add a BETWEEN node to the expressionvoid
bindMarker(BindMarkerNode node)
Add a bind marker ? and its value to the expressionvoid
column(java.lang.String columnName)
Push a node representing the column reference onto the stackvoid
column(java.lang.String tableAlias, java.lang.String columnName)
Add a column to the expressionvoid
div()
Add a division node to the expressionvoid
eq()
Add an EQ node to the expressionvoid
escape()
Add an ESCAPE node to the expressionvoid
gt()
Add a GT > node to the expressionvoid
gte()
Add a GTE >= node to the expressionvoid
inLiteral(java.lang.Long[] inList)
Convenience function to add an IN list of literal long values.void
inLiteral(java.lang.String[] inList)
Convenience function to add an IN list of literal string values.void
inLong(java.util.List<java.lang.Long> inList)
Convenience function to add an IN list of `` bind markers void
inString(java.util.List<java.lang.String> inList)
Convenience function to add an IN list of `` bind markers boolean
isEmpty()
Check if anything has been added to this parservoid
isNotNull()
Add an IS NOT NULL node to the expression tokensvoid
isNull()
Add an IS NULL node to the expression tokensvoid
leftParen()
Add a LEFT PAREN ( node to the expressionvoid
like()
Add a LIKE node to the expressionvoid
literal(java.lang.Double dbl)
Add a Double literal to the expressionvoid
literal(java.lang.Long lng)
Add a Long literal to the expressionvoid
literal(java.lang.String str)
Add a string literal to the expressionvoid
lt()
Add a LT < node to the expressionvoid
lte()
Add a LTE <= node to the expressionvoid
mult()
Add a multiplication node to the expressionvoid
neq()
Add a NEQ node to the expressionvoid
not()
Add a NOT node to the expressionvoid
or()
Push an or node to the stack, taking into account precedenceExpNode
parse()
Applies the shunting-yard algorithm, collapsing the operatorStack as much as possible.java.lang.String
parserState()
Get a list of the nodes as a string, to help debug expression building and parsing.void
rightParen()
Add a RIGHT PAREN ) node to the expressionvoid
sub()
Add a subtraction node to the expression
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Check if anything has been added to this parser- Returns:
- true if nothing has been added
-
parse
public ExpNode parse()
Applies the shunting-yard algorithm, collapsing the operatorStack as much as possible. If the expression is valid, there should be a single node sitting on the operandStack.- Returns:
-
parserState
public java.lang.String parserState()
Get a list of the nodes as a string, to help debug expression building and parsing. We don't use the visitor, because the expression node might not be fully configured- Returns:
-
column
public void column(java.lang.String columnName)
Push a node representing the column reference onto the stack- Parameters:
columnName
-
-
column
public void column(java.lang.String tableAlias, java.lang.String columnName)
Add a column to the expression- Parameters:
tableAlias
-columnName
-
-
literal
public void literal(java.lang.String str)
Add a string literal to the expression- Parameters:
str
-
-
literal
public void literal(java.lang.Double dbl)
Add a Double literal to the expression- Parameters:
dbl
-
-
literal
public void literal(java.lang.Long lng)
Add a Long literal to the expression- Parameters:
lng
-
-
and
public void and()
Push an AND node to the stack, taking into account precedence
-
or
public void or()
Push an or node to the stack, taking into account precedence
-
eq
public void eq()
Add an EQ node to the expression
-
like
public void like()
Add a LIKE node to the expression
-
escape
public void escape()
Add an ESCAPE node to the expression
-
neq
public void neq()
Add a NEQ node to the expression
-
gt
public void gt()
Add a GT > node to the expression
-
gte
public void gte()
Add a GTE >= node to the expression
-
lt
public void lt()
Add a LT < node to the expression
-
lte
public void lte()
Add a LTE <= node to the expression
-
not
public void not()
Add a NOT node to the expression
-
between
public void between()
Add a BETWEEN node to the expression
-
add
public void add()
Add an addition + node to the expression
-
sub
public void sub()
Add a subtraction node to the expression
-
mult
public void mult()
Add a multiplication node to the expression
-
div
public void div()
Add a division node to the expression
-
leftParen
public void leftParen()
Add a LEFT PAREN ( node to the expression
-
rightParen
public void rightParen()
Add a RIGHT PAREN ) node to the expression
-
bindMarker
public void bindMarker(BindMarkerNode node)
Add a bind marker ? and its value to the expression- Parameters:
node
-
-
inLiteral
public void inLiteral(java.lang.String[] inList)
Convenience function to add an IN list of literal string values. This should be used only where the string values are internal values, never input data. If the values come from input data, then for security it is important to use bind markers instead.- Parameters:
inList
-
-
inLiteral
public void inLiteral(java.lang.Long[] inList)
Convenience function to add an IN list of literal long values.- Parameters:
inList
-
-
inString
public void inString(java.util.List<java.lang.String> inList)
Convenience function to add an IN list of `` bind markers - Parameters:
bindMarkerCount
-
-
inLong
public void inLong(java.util.List<java.lang.Long> inList)
Convenience function to add an IN list of `` bind markers - Parameters:
bindMarkerCount
-
-
addToken
public void addToken(ExpNode token)
Allow expression nodes to be added directly to the list of tokens. Wrap non-operands in a paren to ensure the expression is treated atomically, which is the intent of this method.- Parameters:
node
-
-
isNotNull
public void isNotNull()
Add an IS NOT NULL node to the expression tokens
-
isNull
public void isNull()
Add an IS NULL node to the expression tokens
-
-