Skip to content

Commit c46a566

Browse files
committed
Updating code of new withRegex function to make it more efficient.
1 parent b15f946 commit c46a566

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/DpiMasking.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String r
115115
*/
116116
@Nonnull
117117
public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String replacement) {
118-
val newEntities = new ArrayList<>(entitiesDTO);
119-
newEntities.add(
120-
DPICustomEntity.create()
121-
.regex(regex)
122-
.replacementStrategy(
123-
DPIMethodConstant.create()
124-
.method(DPIMethodConstant.MethodEnum.CONSTANT)
125-
.value(replacement)));
126-
return new DpiMasking(maskingMethod, newEntities, maskGroundingInput, allowList);
118+
return new DpiMasking(
119+
maskingMethod,
120+
Stream.concat(
121+
entitiesDTO.stream(),
122+
Stream.of(
123+
DPICustomEntity.create()
124+
.regex(regex)
125+
.replacementStrategy(
126+
DPIMethodConstant.create()
127+
.method(DPIMethodConstant.MethodEnum.CONSTANT)
128+
.value(replacement))))
129+
.toList(),
130+
maskGroundingInput,
131+
allowList);
127132
}
128133

129134
/**

0 commit comments

Comments
 (0)