| 17 | */ |
| 18 | public final class FnRemove extends StandardFunc { |
| 19 | @Override |
| 20 | public Iter iter(final QueryContext qc) throws QueryException { |
| 21 | final Iter input = arg(0).iter(qc); |
| 22 | final LongList pos = positions(qc); |
| 23 | |
| 24 | // value-based iterator |
| 25 | if(input.valueIter() || pos.size() > 1) return value(input.value(qc, null), pos, qc).iter(); |
| 26 | |
| 27 | final long size = input.size(); |
| 28 | return new Iter() { |
| 29 | final long p = pos.get(0); |
| 30 | long c; |
| 31 | |
| 32 | @Override |
| 33 | public Item next() throws QueryException { |
| 34 | return c++ != p || input.next() != null ? input.next() : null; |
| 35 | } |
| 36 | @Override |
| 37 | public Item get(final long i) throws QueryException { |
| 38 | return input.get(i < p ? i : i + 1); |
| 39 | } |
| 40 | @Override |
| 41 | public long size() { |
| 42 | return Math.max(-1, size - 1); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public Value value(final QueryContext qc) throws QueryException { |