Skip to content

Commit

Permalink
Incorporated changes based on CodeRabbit review.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed May 26, 2024
1 parent 1deb3f0 commit 342eddd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public ISequence<?> accept(

ISequence<?> roots = ObjectUtils.notNull(focus.stream()
.map(ItemUtils::checkItemIsNodeItemForStep)
.map(item -> Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item)).findFirst().get())
// the previous checks for a null instance
.flatMap(item -> Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item)).limit(1))
.collect(ISequence.toSequence()));

return getExpression().accept(dynamicContext, roots);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,13 @@ ISequence<?> execute(
*/
@NonNull
default String toSignature() {
StringBuilder builder = new StringBuilder()
.append("Q{")
.append(getNamespace())
.append('}')
.append(getName()) // name
.append('('); // arguments

List<IArgument> arguments = getArguments();
if (arguments.isEmpty()) {
builder.append("()");
} else {
builder.append(arguments.stream().map(IArgument::toSignature).collect(Collectors.joining(",")));

if (isArityUnbounded()) {
builder.append(", ...");
}
}

builder.append(") as ")
.append(getResult().toSignature());// return type

return ObjectUtils.notNull(builder.toString());
return ObjectUtils.notNull(String.format("Q{%s}%s(%s) as %s",
getNamespace(),
getName(),
getArguments().isEmpty() ? "()"
: getArguments().stream().map(IArgument::toSignature).collect(Collectors.joining(","))
+ (isArityUnbounded() ? ", ..." : ""),
getResult().toSignature()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,9 @@ private static ISequence<IAnyUriItem> executeNoArg(@NonNull IFunction function,

INodeItem item = FunctionUtils.requireTypeOrNull(INodeItem.class, focus);

ISequence<IAnyUriItem> retval;
if (item instanceof IDocumentNodeItem) {
IAnyUriItem uri = fnDocumentUri((IDocumentNodeItem) item);
retval = ISequence.of(uri);
} else {
retval = ISequence.empty();
}
return retval;
return item instanceof IDocumentNodeItem
? ISequence.of(fnDocumentUri((IDocumentNodeItem) item))
: ISequence.empty();
}

@SuppressWarnings("unused")
Expand All @@ -109,16 +104,9 @@ private static ISequence<IAnyUriItem> executeOneArg(@NonNull IFunction function,

INodeItem item = arg.getFirstItem(true);

ISequence<IAnyUriItem> retval;
if (item == null) {
retval = ISequence.empty();
} else if (item instanceof IDocumentNodeItem) {
IAnyUriItem uri = fnDocumentUri((IDocumentNodeItem) item);
retval = ISequence.of(uri);
} else {
retval = ISequence.empty();
}
return retval;
return item instanceof IDocumentNodeItem
? ISequence.of(fnDocumentUri((IDocumentNodeItem) item))
: ISequence.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<ITEM> getValue() {
@Override
public Stream<ITEM> stream() {
@NonNull Stream<ITEM> retval;
// Ensure thread safety and prevent multiple consumptions of the stream
synchronized (this) {
if (list == null) {
if (stream == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* A representation of a Metapath array item type.
* <p>
* Instances of this interface are required to enforce non-mutability for array
* contents.
*
* @param <ITEM>
* the Metapath item type of array members
*/
@SuppressWarnings("PMD.ShortMethodName")
public interface IArrayItem<ITEM extends ICollectionValue> extends IFunction, IItem, List<ITEM>, IStringValued {
@NonNull
Expand Down

0 comments on commit 342eddd

Please sign in to comment.