• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/exist-core/src/main/java/org/exist/xquery/functions/fn/FnInnerMost.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 */
24
package org.exist.xquery.functions.fn;
25

26
import org.exist.dom.QName;
27
import org.exist.numbering.NodeId;
28
import org.exist.xquery.*;
29
import org.exist.xquery.value.*;
30

31
import java.util.ArrayList;
32
import java.util.HashSet;
33
import java.util.List;
34
import java.util.Set;
35

36

37
public class FnInnerMost extends BasicFunction {
38

39
    public final static FunctionSignature FNS_INNERMOST = new FunctionSignature(
1✔
40
            new QName("innermost", Function.BUILTIN_FUNCTION_NS),
1✔
41
            "Returns every node within the input sequence that is not an ancestor of another member of the input sequence; the nodes are returned in document order with duplicates eliminated.",
1✔
42
            new SequenceType[] {
1✔
43
                    new FunctionParameterSequenceType("nodes", Type.NODE, Cardinality.ZERO_OR_MORE, "The nodes to test")
1✔
44
            },
45
            new FunctionReturnSequenceType(Type.NODE, Cardinality.ZERO_OR_MORE, "The nodes that are not an ancestor of another node in the input sequence")
1✔
46
    );
1✔
47

48
    public FnInnerMost(final XQueryContext context, final FunctionSignature signature) {
49
        super(context, signature);
1✔
50
    }
1✔
51

52
    @Override
53
    public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
54
        final Sequence nodes = args[0];
1✔
55
        if(nodes.isEmpty()) {
1!
56
            return Sequence.EMPTY_SEQUENCE;
×
57
        } else if(nodes.hasOne()) {
1!
58
            return nodes;
×
59
        } else {
60
            final Sequence results = new ValueSequence();
1✔
61

62
            final List<NodeId> nodeIds = getNodeIds(nodes);
1✔
63
            final Set<NodeId> found = new HashSet<>();
1✔
64

65
            final SequenceIterator it = nodes.iterate();
1✔
66
            while(it.hasNext()) {
1✔
67
                final Item item = it.nextItem();
1✔
68
                final NodeValue node = ((NodeValue)item);
1✔
69
                final NodeId currentNodeId = node.getNodeId();
1✔
70

71
                if(!found.contains(currentNodeId) &&
1✔
72
                        nodeIds.parallelStream().noneMatch(nodeId -> nodeId.isDescendantOf(currentNodeId))) {
1✔
73
                    results.add(node);
1✔
74
                    found.add(currentNodeId);
1✔
75
                }
76
            }
77

78
            return results;
1✔
79
        }
80
    }
81

82
    private List<NodeId> getNodeIds(final Sequence nodes) throws XPathException {
83
        final List<NodeId> nodeIds = new ArrayList<>();
1✔
84
        final SequenceIterator it = nodes.iterate();
1✔
85
        while(it.hasNext()) {
1✔
86
            final Item item = it.nextItem();
1✔
87
            final NodeValue node = ((NodeValue)item);
1✔
88
            nodeIds.add(node.getNodeId());
1✔
89
        }
90
        return nodeIds;
1✔
91
    }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc