Skip to content

Commit

Permalink
a reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 22, 2024
1 parent 4aa3a52 commit 711baa2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,14 @@ private static void verifyQueryable(Queryable<Integer> queryable)
Approvals.verifyAll("", queryable.orderBy(i -> i));
}
@Test
void testFirstOrThrow() {
void testFirstOrThrow()
{
var expected = """
java.lang.RuntimeException: 4 not found
""";
java.lang.RuntimeException: 4 not found
""";
Queryable<Integer> queryable = Queryable.as(1, 2, 3);
assertEquals(3, queryable.first(i -> 2 < i));
Approvals.verifyException(() -> queryable.firstOrThrow(i -> i == 4, () -> new RuntimeException("4 not found")), new Options().inline(expected));
Approvals.verifyException(() -> queryable.firstOrThrow(i -> i == 4, () -> new RuntimeException("4 not found")),
new Options().inline(expected));
}
}
17 changes: 10 additions & 7 deletions approvaltests-util/src/main/java/org/lambda/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ public static <In> In first(Iterable<In> list, Function1<In, Boolean> filter)
}
return null;
}
public static <In, E extends Throwable> In firstOrThrow(In[] list, Function1<In, Boolean> filter, Function0<E> exception) throws E {
public static <In, E extends Throwable> In firstOrThrow(In[] list, Function1<In, Boolean> filter,
Function0<E> exception) throws E
{
return firstOrThrow(Arrays.asList(list), filter, exception);
}
public static <In, E extends Throwable> In firstOrThrow(Iterable<In> list, Function1<In, Boolean> filter, Function0<E> exception) throws E {
In i = first(list, filter);
if (i == null) {
throw exception.call();
public static <In, E extends Throwable> In firstOrThrow(Iterable<In> list, Function1<In, Boolean> filter,
Function0<E> exception) throws E
{
In i = first(list, filter);
if (i == null)
{ throw exception.call(); }
return i;
}
return i;
}
public static <In> Queryable<In> where(In[] list, Function1<In, Boolean> filter)
{
Queryable<In> out = new Queryable<In>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public In first(Function1<In, Boolean> filter)
{
return Query.first(this, filter);
}
public <E extends Throwable> In firstOrThrow(Function1<In, Boolean> filter, Function0<E> exception) throws E {
public <E extends Throwable> In firstOrThrow(Function1<In, Boolean> filter, Function0<E> exception) throws E
{
return Query.firstOrThrow(this, filter, exception);
}
public In firstOrDefault(In defaultValue)
{
return this.isEmpty() ? defaultValue : this.get(0);
}
public Action0 firstOrThrow(In i, Object o) {
public Action0 firstOrThrow(In i, Object o)
{
return null;
}
public boolean all(Function1<In, Boolean> filter)
Expand Down

0 comments on commit 711baa2

Please sign in to comment.