Skip to content

Commit

Permalink
. F Queryable.as accepting a Set, fixes #372
Browse files Browse the repository at this point in the history
Co-authored-by: Jay Bazuzi <[email protected]>
Co-authored-by: Llewellyn Falco <[email protected]>
  • Loading branch information
3 people committed Oct 28, 2024
1 parent 4ac45c9 commit 402c45d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -212,4 +213,18 @@ void testRecursive()
Queryable<Integer> integers = Queryable.as(48, 8);
Approvals.verifyAll("", integers.selectRecursivelyUntil(i -> i / 2, i -> i <= 1));
}
@Test
void testOf()
{
Approvals.settings().allowMultipleVerifyCallsForThisMethod();
verifyQueryable(Queryable.of(1, 2, 3));
verifyQueryable(Queryable.of(Set.of(1, 2, 3)));
verifyQueryable(Queryable.as(Set.of(1, 2, 3)));
verifyQueryable(Queryable.of(Set.of(1, 2, 3), Integer.class));
verifyQueryable(Queryable.as(Set.of(1, 2, 3), Integer.class));
}
private static void verifyQueryable(Queryable<Integer> queryable)
{
Approvals.verifyAll("", queryable.orderBy(i -> i));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0] = 1
[1] = 2
[2] = 3
17 changes: 17 additions & 0 deletions approvaltests-util/src/main/java/org/lambda/query/Queryable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -130,6 +131,14 @@ public static <T> Queryable<T> of(List<T> list, Class<T> type)
{
return as(list, type);
}
public static <T> Queryable<T> of(Set<T> set)
{
return as(set);
}
public static <T> Queryable<T> of(Set<T> set, Class<T> type)
{
return as(set, type);
}
public static <T> Queryable<T> of(T... array)
{
return as(array);
Expand All @@ -151,6 +160,14 @@ public static <T> Queryable<T> as(List<T> list, Class<T> type)
q.addAll(list);
return q;
}
public static <T> Queryable<T> as(Set<T> set)
{
return as(new ArrayList<>(set));
}
public static <T> Queryable<T> as(Set<T> set, Class<T> type)
{
return as(new ArrayList<>(set), type);
}
public static <T> Queryable<T> as(T... array)
{
return as(Arrays.asList(array), (Class<T>) array.getClass().getComponentType());
Expand Down

0 comments on commit 402c45d

Please sign in to comment.