Skip to content

Commit 60bb4c1

Browse files
authored
Merge pull request #4627 from line-o/refactor/Sequence
[refactor] Sequence.of
2 parents 8dc13d3 + 52a9dc4 commit 60bb4c1

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

exist-core/src/main/java/org/exist/xquery/value/Sequence.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.exist.numbering.NodeId;
3030
import org.exist.xmldb.XmldbURI;
3131
import org.exist.xquery.Cardinality;
32+
import org.exist.xquery.Expression;
3233
import org.exist.xquery.XPathException;
3334
import org.exist.xquery.XQueryContext;
3435

@@ -362,23 +363,23 @@ default int getItemCount() {
362363
void destroy(final XQueryContext context, @Nullable final Sequence contextSequence);
363364

364365
static Sequence of(@Nullable final XmldbURI... uris) throws XPathException {
365-
if (uris == null || uris.length == 0 || (uris.length == 1 && uris[0] == null)) {
366-
return Sequence.EMPTY_SEQUENCE;
367-
}
368-
return ValueSequence.of(FunctionE.<XmldbURI, Item, XPathException>lift(thing -> new StringValue(thing.toString())), uris);
366+
final FunctionE liftedMapper = FunctionE.<XmldbURI, Item, XPathException>lift(
367+
thing -> new StringValue(thing.toString()));
368+
return of(liftedMapper, uris);
369369
}
370370

371371
static Sequence of(@Nullable final Integer... ints) throws XPathException {
372-
if (ints == null || ints.length == 0 || (ints.length == 1 && ints[0] == null)) {
373-
return Sequence.EMPTY_SEQUENCE;
374-
}
375-
return ValueSequence.of(thing -> new IntegerValue(thing, Type.INT), ints);
372+
return of(thing -> new IntegerValue(thing, Type.INT), ints);
376373
}
377374

378375
static Sequence of(@Nullable final BigInteger... bigIntegers) throws XPathException {
379-
if (bigIntegers == null || bigIntegers.length == 0 || (bigIntegers.length == 1 && bigIntegers[0] == null)) {
376+
return of(thing -> new IntegerValue(thing.toString(), Type.INTEGER), bigIntegers);
377+
}
378+
379+
static <T> Sequence of(final FunctionE<T, Item, XPathException> mapper, @Nullable final T... things) throws XPathException {
380+
if (things == null || things.length == 0 || (things.length == 1 && things[0] == null)) {
380381
return Sequence.EMPTY_SEQUENCE;
381382
}
382-
return ValueSequence.of(thing -> new IntegerValue(thing.toString(), Type.INTEGER), bigIntegers);
383+
return ValueSequence.of(mapper, things);
383384
}
384385
}

0 commit comments

Comments
 (0)