📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -30,8 +30,7 @@ import java.util.List;
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
@ -44,10 +43,9 @@ import org.slf4j.LoggerFactory;
* demonstrated with a simple number list that is filtered, transformed and collected. The result is
* printed afterwards.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*/

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import lombok.RequiredArgsConstructor;
/**
* This is a lazy implementation of the FluentIterable interface. It evaluates all chained
@ -37,19 +38,11 @@ import java.util.function.Predicate;
*
* @param <E> the type of the objects the iteration is about
*/
@RequiredArgsConstructor
public class LazyFluentIterable<E> implements FluentIterable<E> {
private final Iterable<E> iterable;
/**
* This constructor creates a new LazyFluentIterable. It wraps the given iterable.
*
* @param iterable the iterable this FluentIterable works on.
*/
protected LazyFluentIterable(Iterable<E> iterable) {
this.iterable = iterable;
}
/**
* This constructor can be used to implement anonymous subclasses of the LazyFluentIterable.
*/

View File

@ -32,6 +32,7 @@ import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import lombok.RequiredArgsConstructor;
/**
* This is a simple implementation of the FluentIterable interface. It evaluates all chained
@ -39,19 +40,11 @@ import java.util.function.Predicate;
*
* @param <E> the type of the objects the iteration is about
*/
@RequiredArgsConstructor
public class SimpleFluentIterable<E> implements FluentIterable<E> {
private final Iterable<E> iterable;
/**
* This constructor creates a copy of a given iterable's contents.
*
* @param iterable the iterable this interface copies to work on.
*/
protected SimpleFluentIterable(Iterable<E> iterable) {
this.iterable = iterable;
}
/**
* Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate.

View File

@ -53,7 +53,7 @@ public abstract class FluentIterableTest {
protected abstract FluentIterable<Integer> createFluentIterable(final Iterable<Integer> integers);
@Test
public void testFirst() {
void testFirst() {
final var integers = List.of(1, 2, 3, 10, 9, 8);
final var first = createFluentIterable(integers).first();
assertNotNull(first);
@ -62,7 +62,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testFirstEmptyCollection() {
void testFirstEmptyCollection() {
final var integers = Collections.<Integer>emptyList();
final var first = createFluentIterable(integers).first();
assertNotNull(first);
@ -70,7 +70,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testFirstCount() {
void testFirstCount() {
final var integers = List.of(1, 2, 3, 10, 9, 8);
final var first4 = createFluentIterable(integers)
.first(4)
@ -86,7 +86,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testFirstCountLessItems() {
void testFirstCountLessItems() {
final var integers = List.of(1, 2, 3);
final var first4 = createFluentIterable(integers)
.first(4)
@ -101,7 +101,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testLast() {
void testLast() {
final var integers = List.of(1, 2, 3, 10, 9, 8);
final var last = createFluentIterable(integers).last();
assertNotNull(last);
@ -110,7 +110,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testLastEmptyCollection() {
void testLastEmptyCollection() {
final var integers = Collections.<Integer>emptyList();
final var last = createFluentIterable(integers).last();
assertNotNull(last);
@ -118,7 +118,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testLastCount() {
void testLastCount() {
final var integers = List.of(1, 2, 3, 10, 9, 8);
final var last4 = createFluentIterable(integers)
.last(4)
@ -133,7 +133,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testLastCountLessItems() {
void testLastCountLessItems() {
final var integers = List.of(1, 2, 3);
final var last4 = createFluentIterable(integers)
.last(4)
@ -148,7 +148,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testFilter() {
void testFilter() {
final var integers = List.of(1, 2, 3, 10, 9, 8);
final var evenItems = createFluentIterable(integers)
.filter(i -> i % 2 == 0)
@ -162,7 +162,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testMap() {
void testMap() {
final var integers = List.of(1, 2, 3);
final var longs = createFluentIterable(integers)
.map(Integer::longValue)
@ -176,7 +176,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testForEach() {
void testForEach() {
final var integers = List.of(1, 2, 3);
final Consumer<Integer> consumer = mock(Consumer.class);
@ -190,7 +190,7 @@ public abstract class FluentIterableTest {
}
@Test
public void testSpliterator() throws Exception {
void testSpliterator() throws Exception {
final var integers = List.of(1, 2, 3);
final var split = createFluentIterable(integers).spliterator();
assertNotNull(split);

View File

@ -31,7 +31,7 @@ import com.iluwatar.fluentinterface.fluentiterable.FluentIterableTest;
*
* @author Jeroen Meulemeester
*/
public class LazyFluentIterableTest extends FluentIterableTest {
class LazyFluentIterableTest extends FluentIterableTest {
@Override
protected FluentIterable<Integer> createFluentIterable(Iterable<Integer> integers) {

View File

@ -31,7 +31,7 @@ import com.iluwatar.fluentinterface.fluentiterable.FluentIterableTest;
*
* @author Jeroen Meulemeester
*/
public class SimpleFluentIterableTest extends FluentIterableTest {
class SimpleFluentIterableTest extends FluentIterableTest {
@Override
protected FluentIterable<Integer> createFluentIterable(Iterable<Integer> integers) {