Checks if a path can be evaluated iteratively (i.e., if all results will be in distinct document order without final sorting). @param root root expression (can be null) @param steps path steps @return result of check
(final Expr root, final Expr... steps)
| 445 | * @return result of check |
| 446 | */ |
| 447 | private static boolean iterative(final Expr root, final Expr... steps) { |
| 448 | if(root == null || !root.ddo()) return false; |
| 449 | |
| 450 | final SeqType st = root.seqType(); |
| 451 | boolean atMostOne = st.zeroOrOne(); |
| 452 | boolean sameDepth = atMostOne || st.type.instanceOf(NodeType.DOCUMENT); |
| 453 | |
| 454 | for(final Expr expr : steps) { |
| 455 | final Step step = (Step) expr; |
| 456 | switch(step.axis) { |
| 457 | case ATTRIBUTE: |
| 458 | case SELF: |
| 459 | // nothing changes |
| 460 | break; |
| 461 | case PARENT: |
| 462 | case FOLLOWING_SIBLING: |
| 463 | case FOLLOWING_SIBLING_OR_SELF: |
| 464 | // can overlap, preserves level |
| 465 | if(!atMostOne) return false; |
| 466 | break; |
| 467 | case CHILD: |
| 468 | // order is only ensured if all nodes are on the same level |
| 469 | if(!sameDepth) return false; |
| 470 | break; |
| 471 | case DESCENDANT: |
| 472 | case DESCENDANT_OR_SELF: |
| 473 | // non-overlapping if all nodes are on the same level |
| 474 | if(!sameDepth) return false; |
| 475 | sameDepth = false; |
| 476 | break; |
| 477 | case ANCESTOR: |
| 478 | case ANCESTOR_OR_SELF: |
| 479 | case PRECEDING: |
| 480 | case PRECEDING_OR_SELF: |
| 481 | case PRECEDING_SIBLING: |
| 482 | case PRECEDING_SIBLING_OR_SELF: |
| 483 | // backwards axes must be reordered |
| 484 | return false; |
| 485 | case FOLLOWING: |
| 486 | case FOLLOWING_OR_SELF: |
| 487 | // can overlap |
| 488 | if(!atMostOne) return false; |
| 489 | sameDepth = false; |
| 490 | break; |
| 491 | default: |
| 492 | throw Util.notExpected(); |
| 493 | } |
| 494 | atMostOne &= step.seqType().zeroOrOne(); |
| 495 | } |
| 496 | return true; |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Assigns a sequence type and (if statically known) result size. |
no test coverage detected