Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions netflix-sel/src/main/java/com/netflix/sel/type/SelArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ public SelLong field(SelString field) {
throw new UnsupportedOperationException(type() + " DO NOT support accessing field: " + field);
}

@Override
public SelType call(String methodName, SelType[] args) {
if ("contains".equals(methodName) && args.length == 1) {
return contains(args[0]);
}
throw new UnsupportedOperationException(
type()
+ " DO NOT support calling method: "
+ methodName
+ " with args: "
+ Arrays.toString(args));
}

private SelBoolean contains(SelType element) {
for (SelType item : val) {
SelBoolean isEqual = (SelBoolean) item.binaryOps(SelOp.EQUAL, element);
if (isEqual.booleanVal()) {
return SelBoolean.of(true);
}
}
return SelBoolean.of(false);
}

@Override
public String toString() {
return Arrays.toString(val);
Expand Down
22 changes: 22 additions & 0 deletions netflix-sel/src/test/java/com/netflix/sel/type/SelArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,26 @@ public void field() {
public void invalidField() {
one.field(SelString.of("size"));
}

@Test
public void testContainsTrue() {
SelBoolean result = (SelBoolean) one.call("contains", new SelType[] {SelString.of("foo")});
assertTrue(result.booleanVal());
}

@Test
public void testContainsFalse() {
SelBoolean result = (SelBoolean) one.call("contains", new SelType[] {SelString.of("baz")});
assertFalse(result.booleanVal());
}

@Test(expected = UnsupportedOperationException.class)
public void testContainsInvalidArgs() {
one.call("contains", new SelType[] {});
}

@Test(expected = UnsupportedOperationException.class)
public void testInvalidMethod() {
one.call("invalidMethod", new SelType[] {SelString.of("test")});
}
}