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

@ -28,46 +28,47 @@ import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureTog
import com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion; import com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
import com.iluwatar.featuretoggle.user.User; import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup; import com.iluwatar.featuretoggle.user.UserGroup;
import java.util.Properties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Properties;
/** /**
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease. This allows features * The Feature Toggle pattern allows for complete code executions to be turned on or off with ease.
* to be controlled by either dynamic methods just as {@link User} information or by {@link Properties}. In the App * This allows features to be controlled by either dynamic methods just as {@link User} information
* below there are two examples. Firstly the {@link Properties} version of the feature toggle, where the enhanced * or by {@link Properties}. In the App below there are two examples. Firstly the {@link Properties}
* version of the welcome message which is personalised is turned either on or off at instance creation. This method * version of the feature toggle, where the enhanced version of the welcome message which is
* is not as dynamic as the {@link User} driven version where the feature of the personalised welcome message is * personalised is turned either on or off at instance creation. This method is not as dynamic as
* the {@link User} driven version where the feature of the personalised welcome message is
* dependant on the {@link UserGroup} the {@link User} is in. So if the user is a memeber of the * dependant on the {@link UserGroup} the {@link User} is in. So if the user is a memeber of the
* {@link UserGroup#isPaid(User)} then they get an ehanced version of the welcome message. * {@link UserGroup#isPaid(User)} then they get an ehanced version of the welcome message.
* *
* Note that this pattern can easily introduce code complexity, and if not kept in check can result in redundant * <p>Note that this pattern can easily introduce code complexity, and if not kept in check can
* unmaintained code within the codebase. * result in redundant unmaintained code within the codebase.
*
*/ */
public class App { public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/** /**
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature * Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
* toggle to enabled. * setting the feature toggle to enabled.
* *
* Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature * <p>Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
* toggle to disabled. Notice the difference with the printed welcome message the username is not included. * setting the feature toggle to disabled. Notice the difference with the printed welcome message
* the username is not included.
* *
* Block 3 shows the {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being * <p>Block 3 shows the {@link
* set up with two users on who is on the free level, while the other is on the paid level. When the * com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being set up with
* {@link Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome message * two users on who is on the free level, while the other is on the paid level. When the {@link
* contains their username, while the same service call with the free tier user is more generic. No username is * Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome
* printed. * message contains their username, while the same service call with the free tier user is more
* generic. No username is printed.
* *
* @see User * @see User
* @see UserGroup * @see UserGroup
* @see Service * @see Service
* @see PropertiesFeatureToggleVersion * @see PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion * @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
*/ */
public static void main(String[] args) { public static void main(String[] args) {
@ -82,11 +83,12 @@ public class App {
final Properties turnedOff = new Properties(); final Properties turnedOff = new Properties();
turnedOff.put("enhancedWelcome", false); turnedOff.put("enhancedWelcome", false);
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff); Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code")); final String welcomeMessageturnedOff =
turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
LOGGER.info(welcomeMessageturnedOff); LOGGER.info(welcomeMessageturnedOff);
// -------------------------------------------- // --------------------------------------------
Service service2 = new TieredFeatureToggleVersion(); Service service2 = new TieredFeatureToggleVersion();
final User paidUser = new User("Jamie Coder"); final User paidUser = new User("Jamie Coder");

View File

@ -26,10 +26,11 @@ package com.iluwatar.featuretoggle.pattern;
import com.iluwatar.featuretoggle.user.User; import com.iluwatar.featuretoggle.user.User;
/** /**
* Simple interfaces to allow the calling of the method to generate the welcome message for a given user. While there is * Simple interfaces to allow the calling of the method to generate the welcome message for a given
* a helper method to gather the the status of the feature toggle. In some cases there is no need for the * user. While there is a helper method to gather the the status of the feature toggle. In some
* {@link Service#isEnhanced()} in {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} * cases there is no need for the {@link Service#isEnhanced()} in {@link
* where the toggle is determined by the actual {@link User}. * com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the toggle is
* determined by the actual {@link User}.
* *
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion * @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion * @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion

View File

@ -25,16 +25,16 @@ package com.iluwatar.featuretoggle.pattern.propertiesversion;
import com.iluwatar.featuretoggle.pattern.Service; import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User; import com.iluwatar.featuretoggle.user.User;
import java.util.Properties; import java.util.Properties;
/** /**
* This example of the Feature Toogle pattern is less dynamic version than * This example of the Feature Toogle pattern is less dynamic version than {@link
* {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is turned on * com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is
* or off at the time of creation of the service. This example uses simple Java {@link Properties} however it could as * turned on or off at the time of creation of the service. This example uses simple Java {@link
* easily be done with an external configuration file loaded by Spring and so on. A good example of when to use this * Properties} however it could as easily be done with an external configuration file loaded by
* version of the feature toggle is when new features are being developed. So you could have a configuration property * Spring and so on. A good example of when to use this version of the feature toggle is when new
* boolean named development or some sort of system environment variable. * features are being developed. So you could have a configuration property boolean named
* development or some sort of system environment variable.
* *
* @see Service * @see Service
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion * @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
@ -45,9 +45,10 @@ public class PropertiesFeatureToggleVersion implements Service {
private boolean isEnhanced; private boolean isEnhanced;
/** /**
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link Properties} to determine, * Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link
* the status of the feature toggle {@link PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive * Properties} to determine, the status of the feature toggle {@link
* code to ensure the {@link Properties} passed are as expected. * PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive code to ensure the
* {@link Properties} passed are as expected.
* *
* @param properties {@link Properties} used to configure the service and toggle features. * @param properties {@link Properties} used to configure the service and toggle features.
* @throws IllegalArgumentException when the passed {@link Properties} is not as expected * @throws IllegalArgumentException when the passed {@link Properties} is not as expected
@ -66,14 +67,14 @@ public class PropertiesFeatureToggleVersion implements Service {
} }
/** /**
* Generate a welcome message based on the user being passed and the status of the feature toggle. If the enhanced * Generate a welcome message based on the user being passed and the status of the feature toggle.
* version is enabled, then the message will be personalised with the name of the passed {@link User}. However if * If the enhanced version is enabled, then the message will be personalised with the name of the
* disabled then a generic version fo the message is returned. * passed {@link User}. However if disabled then a generic version fo the message is returned.
* *
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled see * @param user the {@link User} to be displayed in the message if the enhanced version is enabled
* {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is enabled, then the * see {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
* message will be personalised with the name of the passed {@link User}. However if disabled then a * enabled, then the message will be personalised with the name of the passed {@link
* generic version fo the message is returned. * User}. However if disabled then a generic version fo the message is returned.
* @return Resulting welcome message. * @return Resulting welcome message.
* @see User * @see User
*/ */
@ -88,9 +89,9 @@ public class PropertiesFeatureToggleVersion implements Service {
} }
/** /**
* Method that checks if the welcome message to be returned is the enhanced venison or not. For this service it will * Method that checks if the welcome message to be returned is the enhanced venison or not. For
* see the value of the boolean that was set in the constructor * this service it will see the value of the boolean that was set in the constructor {@link
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)} * PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
* *
* @return Boolean value {@code true} if enhanced. * @return Boolean value {@code true} if enhanced.
*/ */

View File

@ -28,11 +28,12 @@ import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup; import com.iluwatar.featuretoggle.user.UserGroup;
/** /**
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link User}. Therefore * This example of the Feature Toogle pattern shows how it could be implemented based on a {@link
* showing its use within a tiered application where the paying users get access to different content or * User}. Therefore showing its use within a tiered application where the paying users get access to
* better versions of features. So in this instance a {@link User} is passed in and if they are found to be * different content or better versions of features. So in this instance a {@link User} is passed in
* on the {@link UserGroup#isPaid(User)} they are welcomed with a personalised message. While the other is more * and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
* generic. However this pattern is limited to simple examples such as the one below. * personalised message. While the other is more generic. However this pattern is limited to simple
* examples such as the one below.
* *
* @see Service * @see Service
* @see User * @see User
@ -42,12 +43,13 @@ import com.iluwatar.featuretoggle.user.UserGroup;
public class TieredFeatureToggleVersion implements Service { public class TieredFeatureToggleVersion implements Service {
/** /**
* Generates a welcome message from the passed {@link User}. The resulting message depends on the group of the * Generates a welcome message from the passed {@link User}. The resulting message depends on the
* {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then the enhanced version of the * group of the {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then
* welcome message will be returned where the username is displayed. * the enhanced version of the welcome message will be returned where the username is displayed.
* *
* @param user the {@link User} to generate the welcome message for, different messages are displayed if the user is * @param user the {@link User} to generate the welcome message for, different messages are
* in the {@link UserGroup#isPaid(User)} or {@link UserGroup#freeGroup} * displayed if the user is in the {@link UserGroup#isPaid(User)} or {@link
* UserGroup#freeGroup}
* @return Resulting welcome message. * @return Resulting welcome message.
* @see User * @see User
* @see UserGroup * @see UserGroup
@ -62,9 +64,9 @@ public class TieredFeatureToggleVersion implements Service {
} }
/** /**
* Method that checks if the welcome message to be returned is the enhanced version. For this instance as the logic * Method that checks if the welcome message to be returned is the enhanced version. For this
* is driven by the user group. This method is a little redundant. However can be used to show that there is an * instance as the logic is driven by the user group. This method is a little redundant. However
* enhanced version available. * can be used to show that there is an enhanced version available.
* *
* @return Boolean value {@code true} if enhanced. * @return Boolean value {@code true} if enhanced.
*/ */

View File

@ -24,7 +24,8 @@
package com.iluwatar.featuretoggle.user; package com.iluwatar.featuretoggle.user;
/** /**
* Used to demonstrate the purpose of the feature toggle. This class actually has nothing to do with the pattern. * Used to demonstrate the purpose of the feature toggle. This class actually has nothing to do with
* the pattern.
*/ */
public class User { public class User {
@ -41,7 +42,9 @@ public class User {
/** /**
* {@inheritDoc} * {@inheritDoc}
* @return The {@link String} representation of the User, in this case just return the name of the user. *
* @return The {@link String} representation of the User, in this case just return the name of the
* user.
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -27,8 +27,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered example of feature * Contains the lists of users of different groups paid and free. Used to demonstrate the tiered
* toggle. Allowing certain features to be available to only certain groups of users. * example of feature toggle. Allowing certain features to be available to only certain groups of
* users.
* *
* @see User * @see User
*/ */
@ -76,7 +77,6 @@ public class UserGroup {
* Method to take a {@link User} to determine if the user is in the {@link UserGroup#paidGroup}. * Method to take a {@link User} to determine if the user is in the {@link UserGroup#paidGroup}.
* *
* @param user {@link User} to check if they are in the {@link UserGroup#paidGroup} * @param user {@link User} to check if they are in the {@link UserGroup#paidGroup}
*
* @return true if the {@link User} is in {@link UserGroup#paidGroup} * @return true if the {@link User} is in {@link UserGroup#paidGroup}
*/ */
public static boolean isPaid(User user) { public static boolean isPaid(User user) {

View File

@ -23,39 +23,37 @@
package com.iluwatar.fluentinterface.app; package com.iluwatar.fluentinterface.app;
import static java.lang.String.valueOf;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable; import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable; import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable; import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.slf4j.Logger;
import static java.lang.String.valueOf; import org.slf4j.LoggerFactory;
/** /**
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API. * 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 * Those interfaces tend to mimic domain specific languages, so they can nearly be read as human
* languages. * 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 * {@link SimpleFluentIterable} evaluates eagerly and would be too costly for real world
* applications. The {@link LazyFluentIterable} is evaluated on termination. Their usage is * 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 * demonstrated with a simple number list that is filtered, transformed and collected. The result is
* printed afterwards. * printed afterwards.
*
*/ */
public class App { public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/** /**
* Program entry point * Program entry point.
*/ */
public static void main(String[] args) { public static void main(String[] args) {
@ -90,16 +88,16 @@ public class App {
List<String> lastTwoOfFirstFourStringMapped = List<String> lastTwoOfFirstFourStringMapped =
LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2) LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2)
.map(number -> "String[" + valueOf(number) + "]").asList(); .map(number -> "String[" + valueOf(number) + "]").asList();
prettyPrint( prettyPrint("The lazy list contains the last two of the first four positive numbers "
"The lazy list contains the last two of the first four positive numbers mapped to Strings: ", + "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
lastTwoOfFirstFourStringMapped);
LazyFluentIterable LazyFluentIterable
.from(integerList) .from(integerList)
.filter(negatives()) .filter(negatives())
.first(2) .first(2)
.last() .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() { private static Function<Integer, String> transformToString() {
@ -119,7 +117,7 @@ public class App {
} }
private static <E> void prettyPrint(String delimiter, String prefix, private static <E> void prettyPrint(String delimiter, String prefix,
Iterable<E> iterable) { Iterable<E> iterable) {
StringJoiner joiner = new StringJoiner(delimiter, prefix, "."); StringJoiner joiner = new StringJoiner(delimiter, prefix, ".");
Iterator<E> iterator = iterable.iterator(); Iterator<E> iterator = iterable.iterator();
while (iterator.hasNext()) { 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 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 * 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. * be complete. It was inspired by Guava's com.google.common.collect.FluentIterable.
* *
* @param <E> is the class of objects the iterable contains * @param <E> is the class of objects the iterable contains
*/ */
public interface FluentIterable<E> extends Iterable<E> { 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 * Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate. * the predicate.
* *
* @param predicate the condition to test with for the filtering. If the test is negative, the * @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 * @return a filtered FluentIterable
*/ */
FluentIterable<E> filter(Predicate<? super E> predicate); 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 * Returns an Optional containing the first element of this iterable if present, else returns
* Optional.empty(). * Optional.empty().
* *
* @return the first element after the iteration is evaluated * @return the first element after the iteration is evaluated
*/ */
Optional<E> first(); Optional<E> first();
/** /**
* Evaluates the iteration and leaves only the count first elements. * Evaluates the iteration and leaves only the count first elements.
* *
* @return the first count elements as an Iterable * @return the first count elements as an Iterable
*/ */
FluentIterable<E> first(int count); FluentIterable<E> first(int count);
/** /**
* Evaluates the iteration and returns the last element. This is a terminating operation. * Evaluates the iteration and returns the last element. This is a terminating operation.
* *
* @return the last element after the iteration is evaluated * @return the last element after the iteration is evaluated
*/ */
Optional<E> last(); Optional<E> last();
/** /**
* Evaluates the iteration and leaves only the count last elements. * Evaluates the iteration and leaves only the count last elements.
* *
* @return the last counts elements as an Iterable * @return the last counts elements as an Iterable
*/ */
FluentIterable<E> last(int count); FluentIterable<E> last(int count);
/** /**
* Transforms this FluentIterable into a new one containing objects of the type T. * 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 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 * @return a new FluentIterable of the new type
*/ */
<T> FluentIterable<T> map(Function<? super E, T> function); <T> FluentIterable<T> map(Function<? super E, T> function);
/** /**
* Returns the contents of this Iterable as a List. * Returns the contents of this Iterable as a List.
* *
* @return a List representation of this Iterable * @return a List representation of this Iterable
*/ */
List<E> asList(); List<E> asList();
/** /**
* Utility method that iterates over iterable and adds the contents to a list. * Utility method that iterates over iterable and adds the contents to a list.
* *
* @param iterable the iterable to collect * @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 * @return a list with all objects of the given iterator
*/ */
static <E> List<E> copyToList(Iterable<E> iterable) { 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 * This class is used to realize LazyFluentIterables. It decorates a given iterator. Does not
* support consecutive hasNext() calls. * support consecutive hasNext() calls.
*
* @param <E> Iterable Collection of Elements of Type E * @param <E> Iterable Collection of Elements of Type E
*/ */
public abstract class DecoratingIterator<E> implements Iterator<E> { public abstract class DecoratingIterator<E> implements Iterator<E> {

View File

@ -23,6 +23,7 @@
package com.iluwatar.fluentinterface.fluentiterable.lazy; package com.iluwatar.fluentinterface.fluentiterable.lazy;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -30,12 +31,10 @@ import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
/** /**
* This is a lazy implementation of the FluentIterable interface. It evaluates all chained * This is a lazy implementation of the FluentIterable interface. It evaluates all chained
* operations when a terminating operation is applied. * operations when a terminating operation is applied.
* *
* @param <E> the type of the objects the iteration is about * @param <E> the type of the objects the iteration is about
*/ */
public class LazyFluentIterable<E> implements FluentIterable<E> { 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. * This constructor creates a new LazyFluentIterable. It wraps the given iterable.
* *
* @param iterable the iterable this FluentIterable works on. * @param iterable the iterable this FluentIterable works on.
*/ */
protected LazyFluentIterable(Iterable<E> iterable) { 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 * Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate. * the predicate.
* *
* @param predicate the condition to test with for the filtering. If the test is negative, the * @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 * @return a new FluentIterable object that decorates the source iterable
*/ */
@Override @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. * Can be used to collect objects from the iteration. Is a terminating operation.
* *
* @return an Optional containing the first object of this Iterable * @return an Optional containing the first object of this Iterable
*/ */
@Override @Override
@ -101,10 +100,10 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/** /**
* Can be used to collect objects from the iteration. * Can be used to collect objects from the iteration.
* *
* @param count defines the number of objects to return * @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' first * @return the same FluentIterable with a collection decimated to a maximum of 'count' first
* objects. * objects.
*/ */
@Override @Override
public FluentIterable<E> first(int count) { 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. * Can be used to collect objects from the iteration. Is a terminating operation.
* *
* @return an Optional containing the last object of this Iterable * @return an Optional containing the last object of this Iterable
*/ */
@Override @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 * 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 * memory intensive, because the contents of this Iterable are collected into a List, when the
* next object is requested. * next object is requested.
* *
* @param count defines the number of objects to return * @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' last * @return the same FluentIterable with a collection decimated to a maximum of 'count' last
* objects * objects
*/ */
@Override @Override
public FluentIterable<E> last(int count) { 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. * 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 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 * @return a new FluentIterable of the new type
*/ */
@Override @Override
@ -222,7 +221,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
/** /**
* Collects all remaining objects of this iteration into a list. * Collects all remaining objects of this iteration into a list.
* *
* @return a list with all remaining objects of this iteration * @return a list with all remaining objects of this iteration
*/ */
@Override @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. * @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); return new LazyFluentIterable<>(iterable);
} }

View File

@ -23,6 +23,7 @@
package com.iluwatar.fluentinterface.fluentiterable.simple; package com.iluwatar.fluentinterface.fluentiterable.simple;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -32,12 +33,10 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
/** /**
* This is a simple implementation of the FluentIterable interface. It evaluates all chained * 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. * operations eagerly. This implementation would be costly to be utilized in real applications.
* *
* @param <E> the type of the objects the iteration is about * @param <E> the type of the objects the iteration is about
*/ */
public class SimpleFluentIterable<E> implements FluentIterable<E> { 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. * This constructor creates a copy of a given iterable's contents.
* *
* @param iterable the iterable this interface copies to work on. * @param iterable the iterable this interface copies to work on.
*/ */
protected SimpleFluentIterable(Iterable<E> iterable) { 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 * Filters the contents of Iterable using the given predicate, leaving only the ones which satisfy
* the predicate. * the predicate.
* *
* @param predicate the condition to test with for the filtering. If the test is negative, the * @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 * @return the same FluentIterable with a filtered collection
*/ */
@Override @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. * Can be used to collect objects from the Iterable. Is a terminating operation.
* *
* @return an option of the first object of the Iterable * @return an option of the first object of the Iterable
*/ */
@Override @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. * Can be used to collect objects from the Iterable. Is a terminating operation.
* *
* @param count defines the number of objects to return * @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' first * @return the same FluentIterable with a collection decimated to a maximum of 'count' first
* objects. * objects.
*/ */
@Override @Override
public final FluentIterable<E> first(int count) { 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. * Can be used to collect objects from the Iterable. Is a terminating operation.
* *
* @return an option of the last object of the Iterable * @return an option of the last object of the Iterable
*/ */
@Override @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. * Can be used to collect objects from the Iterable. Is a terminating operation.
* *
* @param count defines the number of objects to return * @param count defines the number of objects to return
* @return the same FluentIterable with a collection decimated to a maximum of 'count' last * @return the same FluentIterable with a collection decimated to a maximum of 'count' last
* objects * objects
*/ */
@Override @Override
public final FluentIterable<E> last(int count) { 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. * 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 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 * @return a new FluentIterable of the new type
*/ */
@Override @Override
@ -161,7 +160,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/** /**
* Collects all remaining objects of this Iterable into a list. * Collects all remaining objects of this Iterable into a list.
* *
* @return a list with all remaining objects of this Iterable * @return a list with all remaining objects of this Iterable
*/ */
@Override @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. * @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
*/ */
public static <E> FluentIterable<E> from(Iterable<E> iterable) { 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 * @return the count of remaining objects of the current Iterable
*/ */
public final int getRemainingElementsCount() { 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. * Collects the remaining objects of the given iterator into a List.
* *
* @return a new List with the remaining objects. * @return a new List with the remaining objects.
*/ */
public static <E> List<E> toList(Iterator<E> iterator) { public static <E> List<E> toList(Iterator<E> iterator) {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flux.action; package com.iluwatar.flux.action;
/** /**
*
* Action is the data payload dispatched to the stores when something happens. * Action is the data payload dispatched to the stores when something happens.
*
*/ */
public abstract class Action { public abstract class Action {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flux.action; package com.iluwatar.flux.action;
/** /**
*
* Types of actions. * Types of actions.
*
*/ */
public enum ActionType { public enum ActionType {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flux.action; package com.iluwatar.flux.action;
/** /**
*
* Content items. * Content items.
*
*/ */
public enum Content { public enum Content {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flux.action; package com.iluwatar.flux.action;
/** /**
*
* ContentAction is a concrete action. * ContentAction is a concrete action.
*
*/ */
public class ContentAction extends Action { public class ContentAction extends Action {

View File

@ -25,9 +25,7 @@ package com.iluwatar.flux.action;
/** /**
*
* MenuAction is a concrete action. * MenuAction is a concrete action.
*
*/ */
public class MenuAction extends Action { public class MenuAction extends Action {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flux.action; package com.iluwatar.flux.action;
/** /**
*
* Menu items. * Menu items.
*
*/ */
public enum MenuItem { public enum MenuItem {

View File

@ -31,26 +31,24 @@ import com.iluwatar.flux.view.ContentView;
import com.iluwatar.flux.view.MenuView; import com.iluwatar.flux.view.MenuView;
/** /**
*
* Flux is the application architecture that Facebook uses for building client-side web * Flux is the application architecture that Facebook uses for building client-side web
* applications. Flux eschews MVC in favor of a unidirectional data flow. When a user interacts with * applications. Flux eschews MVC in favor of a unidirectional data flow. When a user interacts with
* a React view, the view propagates an action through a central dispatcher, to the various stores * a React view, the view propagates an action through a central dispatcher, to the various stores
* that hold the application's data and business logic, which updates all of the views that are * that hold the application's data and business logic, which updates all of the views that are
* affected. * affected.
* <p>
* This example has two views: menu and content. They represent typical main menu and content area
* of a web page. When menu item is clicked it triggers events through the dispatcher. The events
* are received and handled by the stores updating their data as needed. The stores then notify the
* views that they should rerender themselves.
* <p>
* http://facebook.github.io/flux/docs/overview.html
* *
* <p>This example has two views: menu and content. They represent typical main menu and content
* area of a web page. When menu item is clicked it triggers events through the dispatcher. The
* events are received and handled by the stores updating their data as needed. The stores then
* notify the views that they should rerender themselves.
*
* <p>http://facebook.github.io/flux/docs/overview.html
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -23,20 +23,17 @@
package com.iluwatar.flux.dispatcher; package com.iluwatar.flux.dispatcher;
import java.util.LinkedList;
import java.util.List;
import com.iluwatar.flux.action.Action; import com.iluwatar.flux.action.Action;
import com.iluwatar.flux.action.Content; import com.iluwatar.flux.action.Content;
import com.iluwatar.flux.action.ContentAction; import com.iluwatar.flux.action.ContentAction;
import com.iluwatar.flux.action.MenuAction; import com.iluwatar.flux.action.MenuAction;
import com.iluwatar.flux.action.MenuItem; import com.iluwatar.flux.action.MenuItem;
import com.iluwatar.flux.store.Store; import com.iluwatar.flux.store.Store;
import java.util.LinkedList;
import java.util.List;
/** /**
*
* Dispatcher sends Actions to registered Stores. * Dispatcher sends Actions to registered Stores.
*
*/ */
public final class Dispatcher { public final class Dispatcher {
@ -44,7 +41,8 @@ public final class Dispatcher {
private List<Store> stores = new LinkedList<>(); private List<Store> stores = new LinkedList<>();
private Dispatcher() {} private Dispatcher() {
}
public static Dispatcher getInstance() { public static Dispatcher getInstance() {
return instance; return instance;
@ -55,7 +53,7 @@ public final class Dispatcher {
} }
/** /**
* Menu item selected handler * Menu item selected handler.
*/ */
public void menuItemSelected(MenuItem menuItem) { public void menuItemSelected(MenuItem menuItem) {
dispatchAction(new MenuAction(menuItem)); dispatchAction(new MenuAction(menuItem));

View File

@ -29,9 +29,7 @@ import com.iluwatar.flux.action.Content;
import com.iluwatar.flux.action.ContentAction; import com.iluwatar.flux.action.ContentAction;
/** /**
*
* ContentStore is a concrete store. * ContentStore is a concrete store.
*
*/ */
public class ContentStore extends Store { public class ContentStore extends Store {

View File

@ -29,9 +29,7 @@ import com.iluwatar.flux.action.MenuAction;
import com.iluwatar.flux.action.MenuItem; import com.iluwatar.flux.action.MenuItem;
/** /**
*
* MenuStore is a concrete store. * MenuStore is a concrete store.
*
*/ */
public class MenuStore extends Store { public class MenuStore extends Store {

View File

@ -23,16 +23,13 @@
package com.iluwatar.flux.store; package com.iluwatar.flux.store;
import com.iluwatar.flux.action.Action;
import com.iluwatar.flux.view.View;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import com.iluwatar.flux.action.Action;
import com.iluwatar.flux.view.View;
/** /**
*
* Store is a data model. * Store is a data model.
*
*/ */
public abstract class Store { public abstract class Store {

View File

@ -30,9 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* ContentView is a concrete view. * ContentView is a concrete view.
*
*/ */
public class ContentView implements View { public class ContentView implements View {

View File

@ -31,9 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* MenuView is a concrete view. * MenuView is a concrete view.
*
*/ */
public class MenuView implements View { public class MenuView implements View {

View File

@ -26,9 +26,7 @@ package com.iluwatar.flux.view;
import com.iluwatar.flux.store.Store; import com.iluwatar.flux.store.Store;
/** /**
*
* Views define the representation of data. * Views define the representation of data.
*
*/ */
public interface View { public interface View {

View File

@ -23,16 +23,13 @@
package com.iluwatar.flyweight; package com.iluwatar.flyweight;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
/** /**
*
* AlchemistShop holds potions on its shelves. It uses PotionFactory to provide the potions. * AlchemistShop holds potions on its shelves. It uses PotionFactory to provide the potions.
*
*/ */
public class AlchemistShop { public class AlchemistShop {
@ -42,31 +39,31 @@ public class AlchemistShop {
private List<Potion> bottomShelf; private List<Potion> bottomShelf;
/** /**
* Constructor * Constructor.
*/ */
public AlchemistShop() { public AlchemistShop() {
PotionFactory factory = new PotionFactory(); PotionFactory factory = new PotionFactory();
topShelf = List.of( topShelf = List.of(
factory.createPotion(PotionType.INVISIBILITY), factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.INVISIBILITY), factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH), factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING), factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.INVISIBILITY), factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH), factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING), factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.HEALING) factory.createPotion(PotionType.HEALING)
); );
bottomShelf = List.of( bottomShelf = List.of(
factory.createPotion(PotionType.POISON), factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON), factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON), factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.HOLY_WATER), factory.createPotion(PotionType.HOLY_WATER),
factory.createPotion(PotionType.HOLY_WATER) factory.createPotion(PotionType.HOLY_WATER)
); );
} }
/** /**
* Get a read-only list of all the items on the top shelf * Get a read-only list of all the items on the top shelf.
* *
* @return The top shelf potions * @return The top shelf potions
*/ */
@ -75,7 +72,7 @@ public class AlchemistShop {
} }
/** /**
* Get a read-only list of all the items on the bottom shelf * Get a read-only list of all the items on the bottom shelf.
* *
* @return The bottom shelf potions * @return The bottom shelf potions
*/ */
@ -84,7 +81,7 @@ public class AlchemistShop {
} }
/** /**
* Enumerate potions * Enumerate potions.
*/ */
public void enumerate() { public void enumerate() {

View File

@ -24,24 +24,22 @@
package com.iluwatar.flyweight; package com.iluwatar.flyweight;
/** /**
*
* Flyweight pattern is useful when the program needs a huge amount of objects. It provides means to * Flyweight pattern is useful when the program needs a huge amount of objects. It provides means to
* decrease resource usage by sharing object instances. * decrease resource usage by sharing object instances.
* <p> *
* In this example {@link AlchemistShop} has great amount of potions on its shelves. To fill the * <p>In this example {@link AlchemistShop} has great amount of potions on its shelves. To fill the
* shelves {@link AlchemistShop} uses {@link PotionFactory} (which represents the Flyweight in this * shelves {@link AlchemistShop} uses {@link PotionFactory} (which represents the Flyweight in this
* example). Internally {@link PotionFactory} holds a map of the potions and lazily creates new ones * example). Internally {@link PotionFactory} holds a map of the potions and lazily creates new ones
* when requested. * when requested.
* <p> *
* To enable safe sharing, between clients and threads, Flyweight objects must be immutable. * <p>To enable safe sharing, between clients and threads, Flyweight objects must be immutable.
* Flyweight objects are by definition value objects. * Flyweight objects are by definition value objects.
*
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* * HealingPotion.
* HealingPotion
*
*/ */
public class HealingPotion implements Potion { public class HealingPotion implements Potion {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* * HolyWaterPotion.
* HolyWaterPotion
*
*/ */
public class HolyWaterPotion implements Potion { public class HolyWaterPotion implements Potion {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* * InvisibilityPotion.
* InvisibilityPotion
*
*/ */
public class InvisibilityPotion implements Potion { public class InvisibilityPotion implements Potion {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* * PoisonPotion.
* PoisonPotion
*
*/ */
public class PoisonPotion implements Potion { public class PoisonPotion implements Potion {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flyweight; package com.iluwatar.flyweight;
/** /**
*
* Interface for Potions. * Interface for Potions.
*
*/ */
public interface Potion { public interface Potion {

View File

@ -27,11 +27,9 @@ import java.util.EnumMap;
import java.util.Map; import java.util.Map;
/** /**
*
* PotionFactory is the Flyweight in this example. It minimizes memory use by sharing object * PotionFactory is the Flyweight in this example. It minimizes memory use by sharing object
* instances. It holds a map of potion instances and new potions are created only when none of the * instances. It holds a map of potion instances and new potions are created only when none of the
* type already exists. * type already exists.
*
*/ */
public class PotionFactory { public class PotionFactory {

View File

@ -24,9 +24,7 @@
package com.iluwatar.flyweight; package com.iluwatar.flyweight;
/** /**
*
* Enumeration for potion types. * Enumeration for potion types.
*
*/ */
public enum PotionType { public enum PotionType {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* * StrengthPotion.
* StrengthPotion
*
*/ */
public class StrengthPotion implements Potion { public class StrengthPotion implements Potion {

View File

@ -24,30 +24,27 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* The Front Controller is a presentation tier pattern. Essentially it defines a controller that * The Front Controller is a presentation tier pattern. Essentially it defines a controller that
* handles all requests for a web site. * handles all requests for a web site.
* <p> *
* The Front Controller pattern consolidates request handling through a single handler object ( * <p>The Front Controller pattern consolidates request handling through a single handler object (
* {@link FrontController}). This object can carry out the common the behavior such as * {@link FrontController}). This object can carry out the common the behavior such as
* authorization, request logging and routing requests to corresponding views. * authorization, request logging and routing requests to corresponding views.
* <p>
* Typically the requests are mapped to command objects ({@link Command}) which then display the
* correct view ({@link View}).
* <p>
* In this example we have implemented two views: {@link ArcherView} and {@link CatapultView}. These
* are displayed by sending correct request to the {@link FrontController} object. For example, the
* {@link ArcherView} gets displayed when {@link FrontController} receives request "Archer". When
* the request is unknown, we display the error view ({@link ErrorView}).
* *
* <p>Typically the requests are mapped to command objects ({@link Command}) which then display the
* correct view ({@link View}).
*
* <p>In this example we have implemented two views: {@link ArcherView} and {@link CatapultView}.
* These are displayed by sending correct request to the {@link FrontController} object. For
* example, the {@link ArcherView} gets displayed when {@link FrontController} receives request
* "Archer". When the request is unknown, we display the error view ({@link ErrorView}).
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args * @param args command line args
* command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
FrontController controller = new FrontController(); FrontController controller = new FrontController();

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
* * Custom exception type.
* Custom exception type
*
*/ */
public class ApplicationException extends RuntimeException { public class ApplicationException extends RuntimeException {

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* Command for archers. * Command for archers.
*
*/ */
public class ArcherCommand implements Command { public class ArcherCommand implements Command {

View File

@ -27,12 +27,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* View for archers. * View for archers.
*
*/ */
public class ArcherView implements View { public class ArcherView implements View {
private static final Logger LOGGER = LoggerFactory.getLogger(ArcherView.class); private static final Logger LOGGER = LoggerFactory.getLogger(ArcherView.class);
@Override @Override

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* Command for catapults. * Command for catapults.
*
*/ */
public class CatapultCommand implements Command { public class CatapultCommand implements Command {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* View for catapults. * View for catapults.
*
*/ */
public class CatapultView implements View { public class CatapultView implements View {

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* Commands are the intermediary between requests and views. * Commands are the intermediary between requests and views.
*
*/ */
public interface Command { public interface Command {

View File

@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* View for errors. * View for errors.
*
*/ */
public class ErrorView implements View { public class ErrorView implements View {

View File

@ -24,10 +24,8 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* FrontController is the handler class that takes in all the requests and renders the correct * FrontController is the handler class that takes in all the requests and renders the correct
* response. * response.
*
*/ */
public class FrontController { public class FrontController {

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* Default command in case the mapping is not successful. * Default command in case the mapping is not successful.
*
*/ */
public class UnknownCommand implements Command { public class UnknownCommand implements Command {

View File

@ -24,9 +24,7 @@
package com.iluwatar.front.controller; package com.iluwatar.front.controller;
/** /**
*
* Views are the representations rendered for the user. * Views are the representations rendered for the user.
*
*/ */
public interface View { public interface View {