| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean test(final QueryContext qc, final InputInfo ii, final long pos) |
| 67 | throws QueryException { |
| 68 | // check instance of value |
| 69 | final Iter iter = expr.iter(qc); |
| 70 | if(iter.valueIter()) return seqType.instance(iter.value(qc, expr)); |
| 71 | |
| 72 | // only check item type |
| 73 | if(check == 2) { |
| 74 | for(Item item; (item = qc.next(iter)) != null;) { |
| 75 | if(!seqType.instance(item)) return false; |
| 76 | } |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | // only check occurrence indicator |
| 81 | final long max = seqType.occ.max; |
| 82 | if(check == 1) return iter.next() == null ? !seqType.oneOrMore() : |
| 83 | max > 1 || max > 0 && iter.next() == null; |
| 84 | |
| 85 | // check both occurrence indicator and type |
| 86 | long c = 0; |
| 87 | for(Item item; (item = qc.next(iter)) != null;) { |
| 88 | if(++c > max || !seqType.instance(item)) return false; |
| 89 | } |
| 90 | return c != 0 || !seqType.oneOrMore(); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public Expr simplifyFor(final Simplify mode, final CompileContext cc) throws QueryException { |