Skip to content

Commit 37f2139

Browse files
committed
[ignore] Code cleanup
1 parent 28b2565 commit 37f2139

File tree

1 file changed

+73
-74
lines changed
  • exist-core/src/main/java/org/exist/xquery/functions/fn

1 file changed

+73
-74
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunRoot.java

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
package org.exist.xquery.functions.fn;
2323

24-
import org.exist.dom.memtree.DocumentImpl;
2524
import org.exist.dom.persistent.ExtArrayNodeSet;
2625
import org.exist.dom.persistent.NodeProxy;
2726
import org.exist.dom.QName;
@@ -47,99 +46,99 @@
4746
* @author <a href="mailto:[email protected]">Wolfgang Meier</a>
4847
*/
4948
public class FunRoot extends Function {
50-
51-
protected static final String FUNCTION_DESCRIPTION_0_PARAM =
52-
"Returns the root of the tree to which the context item belongs. ";
53-
protected static final String FUNCTION_DESCRIPTION_1_PARAM =
54-
"Returns the root of the tree to which $arg belongs. " +
55-
"This will usually, but not necessarily, be a document node.\n\n" +
56-
"If $arg is the empty sequence, the empty sequence is returned.\n\n" +
57-
"If $arg is a document node, $arg is returned.\n\n" +
58-
" The behavior of the zero argument version of the function is " +
59-
"exactly the same as if the context item had been passed in $arg.";
60-
49+
50+
protected static final String FUNCTION_DESCRIPTION_0_PARAM =
51+
"Returns the root of the tree to which the context item belongs. ";
52+
protected static final String FUNCTION_DESCRIPTION_1_PARAM =
53+
"Returns the root of the tree to which $arg belongs. " +
54+
"This will usually, but not necessarily, be a document node.\n\n" +
55+
"If $arg is the empty sequence, the empty sequence is returned.\n\n" +
56+
"If $arg is a document node, $arg is returned.\n\n" +
57+
" The behavior of the zero argument version of the function is " +
58+
"exactly the same as if the context item had been passed in $arg.";
59+
6160
public final static FunctionSignature[] signatures = {
62-
new FunctionSignature(
63-
new QName("root", Function.BUILTIN_FUNCTION_NS),
64-
FUNCTION_DESCRIPTION_0_PARAM,
65-
new SequenceType[0],
66-
new FunctionReturnSequenceType(Type.NODE, Cardinality.EXACTLY_ONE, "the root node of the tree to which the context node belongs")
67-
),
68-
new FunctionSignature(
69-
new QName("root", Function.BUILTIN_FUNCTION_NS),
70-
FUNCTION_DESCRIPTION_1_PARAM,
71-
new SequenceType[] { new FunctionParameterSequenceType("arg", Type.NODE, Cardinality.ZERO_OR_ONE, "The input node") },
72-
new FunctionReturnSequenceType(Type.NODE, Cardinality.ZERO_OR_ONE, "the root node of the tree to which $arg belongs")
73-
)
61+
new FunctionSignature(
62+
new QName("root", Function.BUILTIN_FUNCTION_NS),
63+
FUNCTION_DESCRIPTION_0_PARAM,
64+
new SequenceType[0],
65+
new FunctionReturnSequenceType(Type.NODE, Cardinality.EXACTLY_ONE, "the root node of the tree to which the context node belongs")
66+
),
67+
new FunctionSignature(
68+
new QName("root", Function.BUILTIN_FUNCTION_NS),
69+
FUNCTION_DESCRIPTION_1_PARAM,
70+
new SequenceType[]{new FunctionParameterSequenceType("arg", Type.NODE, Cardinality.ZERO_OR_ONE, "The input node")},
71+
new FunctionReturnSequenceType(Type.NODE, Cardinality.ZERO_OR_ONE, "the root node of the tree to which $arg belongs")
72+
)
7473
};
7574

76-
public FunRoot(XQueryContext context, FunctionSignature signature) {
75+
public FunRoot(final XQueryContext context, final FunctionSignature signature) {
7776
super(context, signature);
7877
}
79-
80-
/* (non-Javadoc)
81-
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
82-
*/
83-
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
78+
79+
@Override
80+
public Sequence eval(Sequence contextSequence, final Item contextItem) throws XPathException {
8481
if (context.getProfiler().isEnabled()) {
8582
context.getProfiler().start(this);
8683
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
87-
if (contextSequence != null)
88-
{context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);}
89-
if (contextItem != null)
90-
{context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
84+
if (contextSequence != null) {
85+
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
86+
}
87+
if (contextItem != null) {
88+
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
89+
}
90+
}
91+
92+
if (contextItem != null) {
93+
contextSequence = contextItem.toSequence();
94+
}
95+
96+
//If we have one argument, we take it into account
97+
final Sequence seq;
98+
if (getSignature().getArgumentCount() > 0) {
99+
seq = getArgument(0).eval(contextSequence, contextItem);
100+
} else {
101+
//Otherwise, we take the context sequence and we iterate over it
102+
seq = contextSequence;
103+
}
104+
105+
if (seq == null) {
106+
throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
91107
}
92-
93-
94-
Sequence seq;
95-
Sequence result;
96-
Item item;
97-
98-
if (contextItem != null)
99-
{contextSequence = contextItem.toSequence();}
100-
if (contextSequence == null || contextSequence.isEmpty())
101-
{result = Sequence.EMPTY_SEQUENCE;}
102-
103-
//If we have one argumment, we take it into account
104-
if (getSignature().getArgumentCount() > 0)
105-
{seq = getArgument(0).eval(contextSequence, contextItem);}
106-
//Otherwise, we take the context sequence and we iterate over it
107-
else
108-
{seq = contextSequence;}
109-
110-
if (seq == null)
111-
{throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");}
112108

113-
if (seq.isPersistentSet())
114-
{result = new ExtArrayNodeSet(seq.getItemCount());}
115-
else
116-
{result = new ValueSequence(seq.getItemCount());}
109+
final Sequence result;
110+
if (seq.isPersistentSet()) {
111+
result = new ExtArrayNodeSet(seq.getItemCount());
112+
} else {
113+
result = new ValueSequence(seq.getItemCount());
114+
}
115+
116+
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
117+
final Item item = i.nextItem();
118+
if (!Type.subTypeOf(item.getType(), Type.NODE)) {
119+
throw new XPathException(this, ErrorCodes.XPTY0004, "Item is not a node; got '" + item + "'", seq);
120+
}
117121

118-
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
119-
item = i.nextItem();
120-
if (!Type.subTypeOf(item.getType(), Type.NODE))
121-
{throw new XPathException(this, ErrorCodes.XPTY0004, "Item is not a node; got '" + item + "'", seq);}
122122
final Sequence s = item.toSequence();
123123

124124
if (s.isPersistentSet()) {
125125
final NodeProxy p = s.toNodeSet().get(0);
126126
result.add(new NodeProxy(p.getOwnerDocument()));
127127
} else {
128128
if (seq.hasOne() && item.getType() == Type.ATTRIBUTE) {
129-
result.add(item);
130-
} else if(item.getType() == Type.DOCUMENT) {
131-
result.add((DocumentImpl)item);
129+
result.add(item);
130+
} else if (item.getType() == Type.DOCUMENT) {
131+
result.add(item);
132132
} else {
133-
result.add(((NodeImpl)item).getOwnerDocument());
133+
result.add(((NodeImpl) item).getOwnerDocument());
134134
}
135135
}
136-
}
137-
138-
if (context.getProfiler().isEnabled())
139-
{context.getProfiler().end(this, "", result);}
140-
136+
}
137+
138+
if (context.getProfiler().isEnabled()) {
139+
context.getProfiler().end(this, "", result);
140+
}
141+
141142
return result;
142-
143-
}
144-
143+
}
145144
}

0 commit comments

Comments
 (0)