if (child.getType() == JexlOperatorConstants.JJTGTNODE) {
if (log.isDebugEnabled()) {
log.debug("refactor: GT " + child.getContents());
}
if (ranges.containsKey(child.getFieldName())) {
RangeBounds rb = ranges.get(child.getFieldName());
rb.setLower(child.getFieldValue());
} else {
RangeBounds rb = new RangeBounds();
rb.setLower(child.getFieldValue());
ranges.put(child.getFieldName(), rb);
}
} else if (child.getType() == JexlOperatorConstants.JJTGENODE) {
if (log.isDebugEnabled()) {
log.debug("refactor: GE " + child.getContents());
}
if (ranges.containsKey(child.getFieldName())) {
RangeBounds rb = ranges.get(child.getFieldName());
rb.setLower(child.getFieldValue());
} else {
RangeBounds rb = new RangeBounds();
rb.setLower(child.getFieldValue());
ranges.put(child.getFieldName(), rb);
}
} else if (child.getType() == JexlOperatorConstants.JJTLTNODE) {
if (log.isDebugEnabled()) {
log.debug("refactor: LT " + child.getContents());
}
if (ranges.containsKey(child.getFieldName())) {
RangeBounds rb = ranges.get(child.getFieldName());
rb.setUpper(child.getFieldValue());
} else {
RangeBounds rb = new RangeBounds();
rb.setUpper(child.getFieldValue());
ranges.put(child.getFieldName(), rb);
}
} else if (child.getType() == JexlOperatorConstants.JJTLENODE) {
if (log.isDebugEnabled()) {
log.debug("refactor: LE " + child.getContents());
}
if (ranges.containsKey(child.getFieldName())) {
RangeBounds rb = ranges.get(child.getFieldName());
rb.setUpper(child.getFieldValue());
} else {
RangeBounds rb = new RangeBounds();
rb.setUpper(child.getFieldValue());
ranges.put(child.getFieldName(), rb);
}
}
}
}
if (allNegated) {
node.setChildrenAllNegated(true);
}
// see if the AND node had a range.
if (node.getType() == ParserTreeConstants.JJTANDNODE) {
// if(ranges.containsKey(node.getFieldName())){
if (!ranges.isEmpty()) {
// we have a range, process it
if (node.getChildCount() <= 2 && ranges.size() == 1) {
if (log.isDebugEnabled()) {
log.debug("AND range 2 children or less");
}
// only has a range, modify the node
node.setType(ParserTreeConstants.JJTORNODE);
node.removeAllChildren();
// RangeBounds rb = ranges.get(node.getFieldName());
for (Entry<Text,RangeBounds> entry : ranges.entrySet()) {
Text fName = entry.getKey();
RangeBounds rb = entry.getValue();
node.setFieldName(fName);
node.setFieldValue(new Text(""));
node.setLowerBound(rb.getLower());
node.setUpperBound(rb.getUpper());
node.setRangeNode(true);
}
rangerators.add(node);
if (log.isDebugEnabled()) {
log.debug("refactor: " + node.getContents());
log.debug("refactor: " + node.getLowerBound() + " " + node.getUpperBound());
}
} else {
if (log.isDebugEnabled()) {
log.debug("AND range more than 2 children");
}
// node has range plus other children, create another node from the range
// remove lt,le,gt,ge from parent and push in a single node
// removing nodes via enumeration doesn't work, push into a list
// and walk backwards
List<BooleanLogicTreeNode> temp = new ArrayList<BooleanLogicTreeNode>();
Enumeration<?> e = node.children();
while (e.hasMoreElements()) {
BooleanLogicTreeNode c = (BooleanLogicTreeNode) e.nextElement();
temp.add(c);
}
for (int j = temp.size() - 1; j >= 0; j--) {
BooleanLogicTreeNode c = temp.get(j);
if (c.getType() == JexlOperatorConstants.JJTLENODE || c.getType() == JexlOperatorConstants.JJTLTNODE
|| c.getType() == JexlOperatorConstants.JJTGENODE || c.getType() == JexlOperatorConstants.JJTGTNODE) {
c.removeFromParent();
}
}
for (Entry<Text,RangeBounds> entry : ranges.entrySet()) {
Text fName = entry.getKey();
BooleanLogicTreeNode nchild = new BooleanLogicTreeNode(ParserTreeConstants.JJTORNODE, fName.toString(), "");
RangeBounds rb = entry.getValue();
nchild.setFieldValue(new Text(""));
nchild.setLowerBound(rb.getLower());
nchild.setUpperBound(rb.getUpper());
nchild.setRangeNode(true);
node.add(nchild);
rangerators.add(nchild);
}