1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.NamePool; 4 import net.sf.saxon.trans.XPathException; 5 import net.sf.saxon.type.ItemType; 6 import net.sf.saxon.type.Type; 7 import net.sf.saxon.value.AtomicValue; 8 import net.sf.saxon.value.BooleanValue; 9 import net.sf.saxon.value.NumericValue; 10 11 import java.io.PrintStream ; 12 import java.util.Arrays ; 13 import java.util.Iterator ; 14 15 20 21 public class IntegerRangeTest extends ComputedExpression { 22 23 Expression value; 24 Expression min; 25 Expression max; 26 27 30 31 public IntegerRangeTest(Expression value, Expression min, Expression max) { 32 this.value = value; 33 this.min = min; 34 this.max = max; 35 } 36 37 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 38 return this; 41 } 42 43 60 61 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 62 return this; 63 } 64 65 68 69 public ItemType getItemType() { 70 return Type.BOOLEAN_TYPE; 71 } 72 73 76 77 public int computeCardinality() { 78 return StaticProperty.EXACTLY_ONE; 79 } 80 81 88 89 public Iterator iterateSubExpressions() { 90 Expression[] e = {value, min, max}; 91 return Arrays.asList(e).iterator(); 92 } 93 94 97 98 public Item evaluateItem(XPathContext c) throws XPathException { 99 AtomicValue av = (AtomicValue)value.evaluateItem(c); 100 if (av==null) { 101 return BooleanValue.FALSE; 102 } 103 NumericValue v = (NumericValue)av.getPrimitiveValue(); 104 105 AtomicValue av2 = (AtomicValue)min.evaluateItem(c); 106 NumericValue v2 = (NumericValue)av2.getPrimitiveValue(); 107 108 if (v.compareTo(v2) < 0) { 109 return BooleanValue.FALSE; 110 } 111 AtomicValue av3 = (AtomicValue)max.evaluateItem(c); 112 NumericValue v3 = (NumericValue)av3.getPrimitiveValue(); 113 114 return BooleanValue.get(v.compareTo(v3) <= 0); 115 } 116 117 120 121 public void display(int level, NamePool pool, PrintStream out) { 122 out.println(ExpressionTool.indent(level) + "rangeTest min<value<max"); 123 min.display(level+1, pool, out); 124 value.display(level+1, pool, out); 125 max.display(level+1, pool, out); 126 } 127 } 128 129 | Popular Tags |