Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion api/src/org/labkey/api/data/NameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ protected int write()
.filter(s -> !s.isEmpty());
}

public static Stream<String> parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors)
public static @Nullable Stream<String> parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors)
{
if (value == null)
return Stream.empty();
Expand Down Expand Up @@ -783,6 +783,21 @@ else if (value instanceof JSONArray jsonArray)
throw new IllegalStateException("For parent values in naming pattern, expected string or collection for '" + parentColName + "': " + value);
}

if (values != null)
{
List<String> valueList = values.toList();
Set<String> valueSet = new HashSet<>();
List<String> duplicates = valueList.stream().filter(s -> !valueSet.add(s)).toList();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion from the stream to the list to the stream and then again to the stream is, uh, unfortunate and kind of defeats one of the purposes of using the stream. I would hope that we don't have a lot of values, of course, so maybe not a big deal (and I don't have a better suggestion).

if (!duplicates.isEmpty())
{
if (errors != null)
errors.addRowError(new ValidationException("Duplicate parent names found: " + StringUtils.join(duplicates, ", "), parentColName));
else
throw new IllegalStateException("Duplicate parent names found: " + StringUtils.join(duplicates, ", "));
}
return valueList.stream();
}

return values;
}

Expand Down
Loading