|
1 | 1 | /* |
| 2 | + * Elemental |
| 3 | + * Copyright (C) 2024, Evolved Binary Ltd |
| 4 | + * |
| 5 | + |
| 6 | + * https://www.evolvedbinary.com | https://www.elemental.xyz |
| 7 | + * |
| 8 | + * This library is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU Lesser General Public |
| 10 | + * License as published by the Free Software Foundation; version 2.1. |
| 11 | + * |
| 12 | + * This library is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this library; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | + * |
| 21 | + * NOTE: Parts of this file contain code from 'The eXist-db Authors'. |
| 22 | + * The original license header is included below. |
| 23 | + * |
| 24 | + * ===================================================================== |
| 25 | + * |
2 | 26 | * eXist-db Open Source Native XML Database |
3 | 27 | * Copyright (C) 2001 The eXist-db Authors |
4 | 28 | * |
|
27 | 51 | import org.exist.xquery.value.FunctionReturnSequenceType; |
28 | 52 | import org.exist.xquery.value.Item; |
29 | 53 | import org.exist.xquery.value.Sequence; |
30 | | -import org.exist.xquery.value.SequenceIterator; |
| 54 | +import org.exist.xquery.value.ValueSequence; |
31 | 55 | import org.exist.xquery.value.SequenceType; |
32 | 56 | import org.exist.xquery.value.Type; |
33 | | -import org.exist.xquery.value.ValueSequence; |
34 | 57 |
|
35 | 58 | /** |
36 | 59 | * Implements the fn:reverse function. |
37 | 60 | * |
38 | 61 | * @author <a href="mailto:[email protected]">Piotr Kaminski</a> |
| 62 | + * @author <a href="mailto:[email protected]">Adam Retter</a> |
39 | 63 | */ |
40 | 64 | public class FunReverse extends Function { |
41 | 65 |
|
@@ -79,37 +103,34 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException |
79 | 103 | argumentsChecked = true; |
80 | 104 | } |
81 | 105 |
|
82 | | - public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException { |
| 106 | + @Override |
| 107 | + public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException { |
83 | 108 | if (context.getProfiler().isEnabled()) { |
84 | | - context.getProfiler().start(this); |
| 109 | + context.getProfiler().start(this); |
85 | 110 | context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies())); |
86 | | - if (contextSequence != null) |
87 | | - {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);} |
88 | | - if (contextItem != null) |
89 | | - {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());} |
90 | | - } |
91 | | - |
92 | | - Sequence result; |
| 111 | + if (contextSequence != null) { |
| 112 | + context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence); |
| 113 | + } |
| 114 | + if (contextItem != null) { |
| 115 | + context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence()); |
| 116 | + } |
| 117 | + } |
| 118 | + |
93 | 119 | final Sequence seq = getArguments(contextSequence, contextItem)[0]; |
94 | | - if (seq.isEmpty()) |
95 | | - {result = Sequence.EMPTY_SEQUENCE;} |
96 | | - else { |
97 | | - final Sequence tmp = new ValueSequence(); |
98 | | - Item item; |
99 | | - for(final SequenceIterator i = seq.iterate(); i.hasNext(); ) { |
100 | | - item = i.nextItem(); |
101 | | - tmp.add(item); |
102 | | - } |
103 | | - result = new ValueSequence(); |
104 | | - for (int i = seq.getItemCount() - 1; i >= 0; i--) { |
105 | | - result.add(tmp.itemAt(i)); |
106 | | - } |
| 120 | + final Sequence result; |
| 121 | + if (seq.isEmpty()) { |
| 122 | + result = Sequence.EMPTY_SEQUENCE; |
| 123 | + } else { |
| 124 | + result = new ValueSequence(); |
| 125 | + for (int i = seq.getItemCount() - 1; i >= 0; i--) { |
| 126 | + result.add(seq.itemAt(i)); |
| 127 | + } |
107 | 128 | } |
108 | 129 |
|
109 | | - if (context.getProfiler().isEnabled()) |
110 | | - {context.getProfiler().end(this, "", result);} |
111 | | - |
112 | | - return result; |
113 | | - } |
| 130 | + if (context.getProfiler().isEnabled()) { |
| 131 | + context.getProfiler().end(this, "", result); |
| 132 | + } |
114 | 133 |
|
| 134 | + return result; |
| 135 | + } |
115 | 136 | } |
0 commit comments