Skip to content

Commit eafb3ab

Browse files
monikakusterivicac
authored andcommitted
3484 Support String and List operands in contains function
1 parent 7343441 commit eafb3ab

File tree

1 file changed

+15
-5
lines changed
  • server/libs/core/evaluator/evaluator-impl/src/main/java/com/bytechef/evaluator

1 file changed

+15
-5
lines changed

server/libs/core/evaluator/evaluator-impl/src/main/java/com/bytechef/evaluator/Contains.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ class Contains implements MethodExecutor {
3333

3434
@Override
3535
public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
36-
List<?> l1 = (List<?>) arguments[0];
37-
Object value = arguments[1];
36+
Object firstArgument = arguments[0];
3837

39-
if (l1 == null) {
38+
if (firstArgument == null) {
4039
return new TypedValue(false);
41-
}
40+
} else {
41+
if (firstArgument instanceof List<?> list) {
42+
Object value = arguments[1];
43+
44+
return new TypedValue(list.contains(value));
45+
} else if (firstArgument instanceof String string) {
46+
String substring = (String) arguments[1];
4247

43-
return new TypedValue(l1.contains(value));
48+
return new TypedValue(string.contains(substring));
49+
} else {
50+
throw new IllegalArgumentException(
51+
"Invalid arguments for contains. Expected 2 string or list and element.");
52+
}
53+
}
4454
}
4555
}

0 commit comments

Comments
 (0)