Resolves checkstyle errors for feature-toggle fluentinterface flux flyweight front-controller (#1078)

* Reduces checkstyle errors in feature-toggle

* Reduces checkstyle errors in fluentinterface

* Reduces checkstyle errors in flux

* Reduces checkstyle errors in flyweight

* Reduces checkstyle errors in front-controller
This commit is contained in:
Anurag Agarwal
2019-11-12 01:54:23 +05:30
committed by Ilkka Seppälä
parent c954a436ad
commit 37599eb48f
46 changed files with 197 additions and 258 deletions

View File

@ -23,39 +23,37 @@
package com.iluwatar.fluentinterface.app;
import static java.lang.String.valueOf;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.function.Predicate;
import static java.lang.String.valueOf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
* Those interfaces tend to mimic domain specific languages, so they can nearly be read as human
* languages.
* <p>
* In this example two implementations of a {@link FluentIterable} interface are given. The
*
* <p>In this example two implementations of a {@link FluentIterable} interface are given. The
* {@link SimpleFluentIterable} evaluates eagerly and would be too costly for real world
* applications. The {@link LazyFluentIterable} is evaluated on termination. Their usage is
* demonstrated with a simple number list that is filtered, transformed and collected. The result is
* printed afterwards.
*
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
* Program entry point.
*/
public static void main(String[] args) {
@ -90,16 +88,16 @@ public class App {
List<String> lastTwoOfFirstFourStringMapped =
LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2)
.map(number -> "String[" + valueOf(number) + "]").asList();
prettyPrint(
"The lazy list contains the last two of the first four positive numbers mapped to Strings: ",
lastTwoOfFirstFourStringMapped);
prettyPrint("The lazy list contains the last two of the first four positive numbers "
+ "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
LazyFluentIterable
.from(integerList)
.filter(negatives())
.first(2)
.last()
.ifPresent(lastOfFirstTwo -> LOGGER.info("The last of the first two negatives is: {}", lastOfFirstTwo));
.ifPresent(lastOfFirstTwo -> LOGGER
.info("The last of the first two negatives is: {}", lastOfFirstTwo));
}
private static Function<Integer, String> transformToString() {
@ -119,7 +117,7 @@ public class App {
}
private static <E> void prettyPrint(String delimiter, String prefix,
Iterable<E> iterable) {
Iterable<E> iterable) {
StringJoiner joiner = new StringJoiner(delimiter, prefix, ".");
Iterator<E> iterator = iterable.iterator();
while (iterator.hasNext()) {

View File

@ -34,7 +34,7 @@ import java.util.function.Predicate;
* The FluentIterable is a more convenient implementation of the common iterable interface based on
* the fluent interface design pattern. This interface defines common operations, but doesn't aim to
* be complete. It was inspired by Guava's com.google.common.collect.FluentIterable.
*
*
* @param <E> is the class of objects the iterable contains
*/
public interface FluentIterable<E> extends Iterable<E> {
@ -42,9 +42,9 @@ public interface FluentIterable<E> extends Iterable<E> {
/**
* Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate.
*
*
* @param predicate the condition to test with for the filtering. If the test is negative, the
* tested object is removed by the iterator.
* tested object is removed by the iterator.
* @return a filtered FluentIterable
*/
FluentIterable<E> filter(Predicate<? super E> predicate);
@ -52,53 +52,53 @@ public interface FluentIterable<E> extends Iterable<E> {
/**
* Returns an Optional containing the first element of this iterable if present, else returns
* Optional.empty().
*
*
* @return the first element after the iteration is evaluated
*/
Optional<E> first();
/**
* Evaluates the iteration and leaves only the count first elements.
*
*
* @return the first count elements as an Iterable
*/
FluentIterable<E> first(int count);
/**
* Evaluates the iteration and returns the last element. This is a terminating operation.
*
*
* @return the last element after the iteration is evaluated
*/
Optional<E> last();
/**
* Evaluates the iteration and leaves only the count last elements.
*
*
* @return the last counts elements as an Iterable
*/
FluentIterable<E> last(int count);
/**
* Transforms this FluentIterable into a new one containing objects of the type T.
*
*
* @param function a function that transforms an instance of E into an instance of T
* @param <T> the target type of the transformation
* @param <T> the target type of the transformation
* @return a new FluentIterable of the new type
*/
<T> FluentIterable<T> map(Function<? super E, T> function);
/**
* Returns the contents of this Iterable as a List.
*
*
* @return a List representation of this Iterable
*/
List<E> asList();
/**
* Utility method that iterates over iterable and adds the contents to a list.
*
*
* @param iterable the iterable to collect
* @param <E> the type of the objects to iterate
* @param <E> the type of the objects to iterate
* @return a list with all objects of the given iterator
*/
static <E> List<E> copyToList(Iterable<E> iterable) {

View File

@ -28,6 +28,7 @@ import java.util.Iterator;
/**
* This class is used to realize LazyFluentIterables. It decorates a given iterator. Does not
* support consecutive hasNext() calls.
*
* @param <E> Iterable Collection of Elements of Type E
*/
public abstract class DecoratingIterator<E> implements Iterator<E> {

View File

@ -23,6 +23,7 @@
package com.iluwatar.fluentinterface.fluentiterable.lazy;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -30,12 +31,10 @@ import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
/**
* This is a lazy implementation of the FluentIterable interface. It evaluates all chained
* operations when a terminating operation is applied.
*
*
* @param <E> the type of the objects the iteration is about
*/
public class LazyFluentIterable<E> implements FluentIterable<E> {
@ -44,7 +43,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* This constructor creates a new LazyFluentIterable. It wraps the given iterable.
*
*
* @param iterable the iterable this FluentIterable works on.
*/
protected LazyFluentIterable(Iterable<E> iterable) {
@ -61,9 +60,9 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate.
*
*
* @param predicate the condition to test with for the filtering. If the test is negative, the
* tested object is removed by the iterator.
* tested object is removed by the iterator.
* @return a new FluentIterable object that decorates the source iterable
*/
@Override
@ -90,7 +89,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the iteration. Is a terminating operation.
*
*
* @return an Optional containing the first object of this Iterable
*/
@Override
@ -101,10 +100,10 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the iteration.
*
*
* @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' first
* objects.
* objects.
*/
@Override
public FluentIterable<E> first(int count) {
@ -130,7 +129,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the iteration. Is a terminating operation.
*
*
* @return an Optional containing the last object of this Iterable
*/
@Override
@ -143,10 +142,10 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
* Can be used to collect objects from the Iterable. Is a terminating operation. This operation is
* memory intensive, because the contents of this Iterable are collected into a List, when the
* next object is requested.
*
*
* @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' last
* objects
* objects
*/
@Override
public FluentIterable<E> last(int count) {
@ -193,9 +192,9 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Transforms this FluentIterable into a new one containing objects of the type T.
*
*
* @param function a function that transforms an instance of E into an instance of T
* @param <T> the target type of the transformation
* @param <T> the target type of the transformation
* @return a new FluentIterable of the new type
*/
@Override
@ -222,7 +221,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/**
* Collects all remaining objects of this iteration into a list.
*
*
* @return a list with all remaining objects of this iteration
*/
@Override
@ -241,9 +240,11 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
}
/**
* Constructors FluentIterable from given iterable.
*
* @return a FluentIterable from a given iterable. Calls the LazyFluentIterable constructor.
*/
public static final <E> FluentIterable<E> from(Iterable<E> iterable) {
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
return new LazyFluentIterable<>(iterable);
}

View File

@ -23,6 +23,7 @@
package com.iluwatar.fluentinterface.fluentiterable.simple;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -32,12 +33,10 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
/**
* This is a simple implementation of the FluentIterable interface. It evaluates all chained
* operations eagerly. This implementation would be costly to be utilized in real applications.
*
*
* @param <E> the type of the objects the iteration is about
*/
public class SimpleFluentIterable<E> implements FluentIterable<E> {
@ -46,7 +45,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* 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) {
@ -56,9 +55,9 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate.
*
*
* @param predicate the condition to test with for the filtering. If the test is negative, the
* tested object is removed by the iterator.
* tested object is removed by the iterator.
* @return the same FluentIterable with a filtered collection
*/
@Override
@ -75,7 +74,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the Iterable. Is a terminating operation.
*
*
* @return an option of the first object of the Iterable
*/
@Override
@ -86,10 +85,10 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the Iterable. Is a terminating operation.
*
*
* @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' first
* objects.
* objects.
*/
@Override
public final FluentIterable<E> first(int count) {
@ -107,7 +106,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the Iterable. Is a terminating operation.
*
*
* @return an option of the last object of the Iterable
*/
@Override
@ -121,10 +120,10 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Can be used to collect objects from the Iterable. Is a terminating operation.
*
*
* @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' last
* objects
* objects
*/
@Override
public final FluentIterable<E> last(int count) {
@ -144,9 +143,9 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Transforms this FluentIterable into a new one containing objects of the type T.
*
*
* @param function a function that transforms an instance of E into an instance of T
* @param <T> the target type of the transformation
* @param <T> the target type of the transformation
* @return a new FluentIterable of the new type
*/
@Override
@ -161,7 +160,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Collects all remaining objects of this Iterable into a list.
*
*
* @return a list with all remaining objects of this Iterable
*/
@Override
@ -170,6 +169,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
}
/**
* Constructs FluentIterable from iterable.
*
* @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
*/
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
@ -198,6 +199,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
}
/**
* Find the count of remaining objects of current iterable.
*
* @return the count of remaining objects of the current Iterable
*/
public final int getRemainingElementsCount() {
@ -212,7 +215,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/**
* Collects the remaining objects of the given iterator into a List.
*
*
* @return a new List with the remaining objects.
*/
public static <E> List<E> toList(Iterator<E> iterator) {