• 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

80.36
/exist-core/src/main/java/org/exist/xquery/functions/fn/FnHasChildren.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.dom.persistent.NodeProxy;
28
import org.exist.xquery.*;
29
import org.exist.xquery.value.*;
30
import org.w3c.dom.Node;
31

32
public class FnHasChildren extends Function {
33

34
    private final static QName QN_HAS_CHILDREN = new QName("has-children", Function.BUILTIN_FUNCTION_NS);
1✔
35

36
    public final static FunctionSignature FNS_HAS_CHILDREN_0 = new FunctionSignature(
1✔
37
            QN_HAS_CHILDREN,
1✔
38
            "Returns true if the context item has one or more child nodes",
1✔
39
            FunctionSignature.NO_ARGS,
1✔
40
            new FunctionReturnSequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE, "true if the context item has one of more child nodes, false otherwise")
1✔
41
    );
42

43
    public final static FunctionSignature FNS_HAS_CHILDREN_1 = new FunctionSignature(
1✔
44
            QN_HAS_CHILDREN,
1✔
45
            "Returns true if the supplied node has one or more child nodes",
1✔
46
            new SequenceType[] {
1✔
47
                    new FunctionParameterSequenceType("node", Type.NODE, Cardinality.ZERO_OR_ONE, "The node to test")
1✔
48
            },
49
            new FunctionReturnSequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE, "true if $node has one of more child nodes, false otherwise")
1✔
50
    );
1✔
51

52
    public FnHasChildren(final XQueryContext context, final FunctionSignature signature) {
53
        super(context, signature);
1✔
54
    }
1✔
55

56
    @Override
57
    public Sequence eval(Sequence contextSequence, final Item contextItem) throws XPathException {
58
        final NodeValue node;
59

60
        if(getArgumentCount() == 0) {
1✔
61
            // default to the context item
62

63
            if(contextSequence == null) {
1✔
64

65
                if (contextItem == null) {
1!
66
                    throw new XPathException(this, ErrorCodes.XPDY0002, "Context item is absent");
1✔
67
                }
68
                contextSequence = contextItem.toSequence();
×
69
            }
70

71
            if(contextSequence.isEmpty()) {
1!
72
                return BooleanValue.FALSE;
×
73
            }
74

75
            final Item item = contextSequence.itemAt(0);
1✔
76
            if(!Type.subTypeOf(item.getType(), Type.NODE)) {
1!
77
                throw new XPathException(this, ErrorCodes.XPTY0004, "Context item is not a node()");
×
78
            }
79

80
            node = (NodeValue)item;
1✔
81

82
        } else {
1✔
83
            final Sequence arg0 = getArgument(0).eval(contextSequence, contextItem);
1✔
84
            if(getArgumentCount() == 1 && arg0.isEmpty()) {
1!
85
                return BooleanValue.FALSE;
1✔
86
            } else {
87
                node = (NodeValue)arg0.itemAt(0);
1✔
88
            }
89
        }
90

91
        final Node w3cNode;
92
        if(node instanceof NodeProxy) {
1!
93
            w3cNode = node.getNode();
×
94
        } else if(node instanceof org.exist.dom.memtree.NodeImpl) {
1!
95
            w3cNode = ((org.exist.dom.memtree.NodeImpl)node);
1✔
96
        } else {
1✔
97
            throw new XPathException(this, ErrorCodes.XPTY0004, "Context item is not a node()");
×
98
        }
99

100
        return BooleanValue.valueOf(w3cNode.hasChildNodes());
1✔
101
    }
102
}
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