mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 00:54:32 +08:00
Add automatic linter (#4214)
This commit is contained in:
@ -25,24 +25,15 @@ public class FibonacciJavaStreams {
|
||||
return Optional.of(BigDecimal.ONE);
|
||||
}
|
||||
|
||||
final List<BigDecimal> results
|
||||
= Stream
|
||||
.iterate(
|
||||
index, x -> x.compareTo(BigDecimal.ZERO) > 0, x -> x.subtract(BigDecimal.ONE))
|
||||
.reduce(List.of(),
|
||||
(list, current)
|
||||
-> list.isEmpty() || list.size() < 2
|
||||
? List.of(BigDecimal.ZERO, BigDecimal.ONE)
|
||||
: List.of(list.get(1), list.get(0).add(list.get(1))),
|
||||
(list1, list2) -> list1);
|
||||
final List<BigDecimal> results = Stream.iterate(index, x -> x.compareTo(BigDecimal.ZERO) > 0, x -> x.subtract(BigDecimal.ONE))
|
||||
.reduce(List.of(), (list, current) -> list.isEmpty() || list.size() < 2 ? List.of(BigDecimal.ZERO, BigDecimal.ONE) : List.of(list.get(1), list.get(0).add(list.get(1))), (list1, list2) -> list1);
|
||||
|
||||
return results.isEmpty() ? Optional.empty() : Optional.of(results.get(results.size() - 1));
|
||||
}
|
||||
|
||||
public static void assertThat(final Object actual, final Object expected) {
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
throw new AssertionError(
|
||||
String.format("expected=%s but was actual=%s", expected, actual));
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s", expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,8 +95,7 @@ public class FibonacciJavaStreams {
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(200));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value
|
||||
-> assertThat(value, new BigDecimal("280571172992510140037611932413038677189525")));
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal("280571172992510140037611932413038677189525")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user