@Test public void unboundedRange(){ Range<Double> lessThan = toRange(Interval.Closure.OPEN_OPEN, null, 0d); assertTrue(lessThan.contains(-Double.MAX_VALUE)); assertFalse(lessThan.contains(0d)); assertFalse(lessThan.contains(Double.MAX_VALUE)); Range<Double> atMost = toRange(Interval.Closure.OPEN_CLOSED, null, 0d); assertTrue(atMost.contains(-Double.MAX_VALUE)); assertTrue(atMost.contains(0d)); assertFalse(atMost.contains(Double.MAX_VALUE)); Range<Double> greaterThan = toRange(Interval.Closure.OPEN_OPEN, 0d, null); assertFalse(greaterThan.contains(-Double.MAX_VALUE)); assertFalse(greaterThan.contains(0d)); assertTrue(greaterThan.contains(Double.MAX_VALUE)); Range<Double> atLeast = toRange(Interval.Closure.CLOSED_OPEN, 0d, null); assertFalse(atLeast.contains(-Double.MAX_VALUE)); assertTrue(atLeast.contains(0d)); assertTrue(atLeast.contains(Double.MAX_VALUE)); }
static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } }
DiscretizationUtil { static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } } }
DiscretizationUtil { static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } } private  DiscretizationUtil(); }
DiscretizationUtil { static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } } private  DiscretizationUtil(); static FieldValue discretize(Discretize discretize, FieldValue value); static Object discretize(Discretize discretize, Double value); static FieldValue mapValue(MapValues mapValues, Map<String, FieldValue> values); static Range<Double> toRange(Interval interval); }
DiscretizationUtil { static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } } private  DiscretizationUtil(); static FieldValue discretize(Discretize discretize, FieldValue value); static Object discretize(Discretize discretize, Double value); static FieldValue mapValue(MapValues mapValues, Map<String, FieldValue> values); static Range<Double> toRange(Interval interval);  }