@Test public void testProcessFilterItem() { FilterItem filterItem = new FilterItem(); Column column = new Column(); IdentifierNode colName = new IdentifierNode("testCol"); Comparator comparator = new Comparator(ComparisionOperator.GT); IdentifierNode colValue = new IdentifierNode("50"); filterItem.addChildNode(column); filterItem.addChildNode(comparator); filterItem.addChildNode(colValue); column.addChildNode(colName); RangeNode<?> actual = rangeOperations.processFilterItem(filterItem, "TestTable", "TestCol"); RangeNode<Long> expected = new RangeNode<>("TestTable", "TestCol"); expected.getRangeList().addRange(new Range<Long>(51l, Long.MAX_VALUE)); assertEquals(expected, actual); }
public RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName) { Comparator comparator = filterItem.getChildType(Comparator.class, 0); String column = columnName == null ? filterItem.getChildType(Column.class, 0).getChildType(IdentifierNode.class, 0).getValue() : columnName; String valueString = filterItem.getChildType(IdentifierNode.class, 0).getValue(); RangeNode<T> rangeNode = new RangeNode<>(table, column); T value = getValue(valueString.replaceAll("'", "")); if (value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0) { String errMsg = "Value: " + value + " is not in valid range"; logger.error(errMsg); throw new BlkchnException(errMsg); } if (comparator.isEQ()) { Range<T> range = new Range<T>(value, value); rangeNode.getRangeList().addRange(range); } else if (comparator.isGT()) { Range<T> range = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isGTE()) { Range<T> range = new Range<T>(value, getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isLT()) { Range<T> range = new Range<T>(getMinValue(), subtract(value, 1)); rangeNode.getRangeList().addRange(range); } else if (comparator.isLTE()) { Range<T> range = new Range<T>(getMinValue(), value); rangeNode.getRangeList().addRange(range); } else { Range<T> range1 = new Range<T>(getMinValue(), subtract(value, 1)); Range<T> range2 = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addAllRanges(range1, range2); } return rangeNode; }
RangeOperations { public RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName) { Comparator comparator = filterItem.getChildType(Comparator.class, 0); String column = columnName == null ? filterItem.getChildType(Column.class, 0).getChildType(IdentifierNode.class, 0).getValue() : columnName; String valueString = filterItem.getChildType(IdentifierNode.class, 0).getValue(); RangeNode<T> rangeNode = new RangeNode<>(table, column); T value = getValue(valueString.replaceAll("'", "")); if (value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0) { String errMsg = "Value: " + value + " is not in valid range"; logger.error(errMsg); throw new BlkchnException(errMsg); } if (comparator.isEQ()) { Range<T> range = new Range<T>(value, value); rangeNode.getRangeList().addRange(range); } else if (comparator.isGT()) { Range<T> range = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isGTE()) { Range<T> range = new Range<T>(value, getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isLT()) { Range<T> range = new Range<T>(getMinValue(), subtract(value, 1)); rangeNode.getRangeList().addRange(range); } else if (comparator.isLTE()) { Range<T> range = new Range<T>(getMinValue(), value); rangeNode.getRangeList().addRange(range); } else { Range<T> range1 = new Range<T>(getMinValue(), subtract(value, 1)); Range<T> range2 = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addAllRanges(range1, range2); } return rangeNode; } }
RangeOperations { public RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName) { Comparator comparator = filterItem.getChildType(Comparator.class, 0); String column = columnName == null ? filterItem.getChildType(Column.class, 0).getChildType(IdentifierNode.class, 0).getValue() : columnName; String valueString = filterItem.getChildType(IdentifierNode.class, 0).getValue(); RangeNode<T> rangeNode = new RangeNode<>(table, column); T value = getValue(valueString.replaceAll("'", "")); if (value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0) { String errMsg = "Value: " + value + " is not in valid range"; logger.error(errMsg); throw new BlkchnException(errMsg); } if (comparator.isEQ()) { Range<T> range = new Range<T>(value, value); rangeNode.getRangeList().addRange(range); } else if (comparator.isGT()) { Range<T> range = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isGTE()) { Range<T> range = new Range<T>(value, getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isLT()) { Range<T> range = new Range<T>(getMinValue(), subtract(value, 1)); rangeNode.getRangeList().addRange(range); } else if (comparator.isLTE()) { Range<T> range = new Range<T>(getMinValue(), value); rangeNode.getRangeList().addRange(range); } else { Range<T> range1 = new Range<T>(getMinValue(), subtract(value, 1)); Range<T> range2 = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addAllRanges(range1, range2); } return rangeNode; }  }
RangeOperations { public RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName) { Comparator comparator = filterItem.getChildType(Comparator.class, 0); String column = columnName == null ? filterItem.getChildType(Column.class, 0).getChildType(IdentifierNode.class, 0).getValue() : columnName; String valueString = filterItem.getChildType(IdentifierNode.class, 0).getValue(); RangeNode<T> rangeNode = new RangeNode<>(table, column); T value = getValue(valueString.replaceAll("'", "")); if (value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0) { String errMsg = "Value: " + value + " is not in valid range"; logger.error(errMsg); throw new BlkchnException(errMsg); } if (comparator.isEQ()) { Range<T> range = new Range<T>(value, value); rangeNode.getRangeList().addRange(range); } else if (comparator.isGT()) { Range<T> range = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isGTE()) { Range<T> range = new Range<T>(value, getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isLT()) { Range<T> range = new Range<T>(getMinValue(), subtract(value, 1)); rangeNode.getRangeList().addRange(range); } else if (comparator.isLTE()) { Range<T> range = new Range<T>(getMinValue(), value); rangeNode.getRangeList().addRange(range); } else { Range<T> range1 = new Range<T>(getMinValue(), subtract(value, 1)); Range<T> range2 = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addAllRanges(range1, range2); } return rangeNode; }  RangeList<T> and(Range<T> r1, Range<T> r2); RangeList<T> or(Range<T> r1, Range<T> r2); RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName); RangeNode<T> rangeNodeOr(RangeNode<T> left, RangeNode<T> right); RangeNode<T> rangeNodeAnd(RangeNode<T> left, RangeNode<T> right); @SuppressWarnings("unchecked") RangeNode<T> processRangeNodes(RangeNode<?> left, RangeNode<?> right, LogicalOperation logicalOperation); abstract T getValue(String valueString); abstract T getMinValue(); abstract T getMaxValue(); abstract T add(T value, int step); abstract T subtract(T value, int step); }
RangeOperations { public RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName) { Comparator comparator = filterItem.getChildType(Comparator.class, 0); String column = columnName == null ? filterItem.getChildType(Column.class, 0).getChildType(IdentifierNode.class, 0).getValue() : columnName; String valueString = filterItem.getChildType(IdentifierNode.class, 0).getValue(); RangeNode<T> rangeNode = new RangeNode<>(table, column); T value = getValue(valueString.replaceAll("'", "")); if (value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0) { String errMsg = "Value: " + value + " is not in valid range"; logger.error(errMsg); throw new BlkchnException(errMsg); } if (comparator.isEQ()) { Range<T> range = new Range<T>(value, value); rangeNode.getRangeList().addRange(range); } else if (comparator.isGT()) { Range<T> range = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isGTE()) { Range<T> range = new Range<T>(value, getMaxValue()); rangeNode.getRangeList().addRange(range); } else if (comparator.isLT()) { Range<T> range = new Range<T>(getMinValue(), subtract(value, 1)); rangeNode.getRangeList().addRange(range); } else if (comparator.isLTE()) { Range<T> range = new Range<T>(getMinValue(), value); rangeNode.getRangeList().addRange(range); } else { Range<T> range1 = new Range<T>(getMinValue(), subtract(value, 1)); Range<T> range2 = new Range<T>(add(value, 1), getMaxValue()); rangeNode.getRangeList().addAllRanges(range1, range2); } return rangeNode; }  RangeList<T> and(Range<T> r1, Range<T> r2); RangeList<T> or(Range<T> r1, Range<T> r2); RangeNode<T> processFilterItem(FilterItem filterItem, String table, String columnName); RangeNode<T> rangeNodeOr(RangeNode<T> left, RangeNode<T> right); RangeNode<T> rangeNodeAnd(RangeNode<T> left, RangeNode<T> right); @SuppressWarnings("unchecked") RangeNode<T> processRangeNodes(RangeNode<?> left, RangeNode<?> right, LogicalOperation logicalOperation); abstract T getValue(String valueString); abstract T getMinValue(); abstract T getMaxValue(); abstract T add(T value, int step); abstract T subtract(T value, int step);  }