MCPcopy Create free account
hub / github.com/BaseXdb/basex / test

Method test

basex-core/src/main/java/org/basex/query/expr/Instance.java:65–91  ·  view source on GitHub ↗
(final QueryContext qc, final InputInfo ii, final long pos)

Source from the content-addressed store, hash-verified

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 {

Callers 1

itemMethod · 0.95

Calls 7

valueIterMethod · 0.95
valueMethod · 0.95
nextMethod · 0.95
oneOrMoreMethod · 0.80
iterMethod · 0.65
nextMethod · 0.65
instanceMethod · 0.45

Tested by

no test coverage detected