Skip to content

Commit

Permalink
Resolves checkstyle errors for feature-toggle fluentinterface flux fl…
Browse files Browse the repository at this point in the history
…yweight 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
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 11, 2019
1 parent c954a43 commit 37599eb
Show file tree
Hide file tree
Showing 46 changed files with 196 additions and 257 deletions.
54 changes: 28 additions & 26 deletions feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,47 @@
import com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup;
import java.util.Properties;
import org.slf4j.Logger;
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
* to be controlled by either dynamic methods just as {@link User} information or by {@link Properties}. In the App
* below there are two examples. Firstly the {@link Properties} version of the feature toggle, where the enhanced
* version of the welcome message which 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
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease.
* This allows features to be controlled by either dynamic methods just as {@link User} information
* or by {@link Properties}. In the App below there are two examples. Firstly the {@link Properties}
* version of the feature toggle, where the enhanced version of the welcome message which 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
* {@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
* unmaintained code within the codebase.
*
* <p>Note that this pattern can easily introduce code complexity, and if not kept in check can
* result in redundant unmaintained code within the codebase.
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
* toggle to enabled.
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
* setting the feature toggle to enabled.
*
* Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
* toggle to disabled. Notice the difference with the printed welcome message the username is not included.
* <p>Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
* 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
* set up with two users on who is on the free level, while the other is on the paid level. When the
* {@link Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome message
* contains their username, while the same service call with the free tier user is more generic. No username is
* printed.
* <p>Block 3 shows the {@link
* com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being set up with
* two users on who is on the free level, while the other is on the paid level. When the {@link
* Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome
* message contains their username, while the same service call with the free tier user is more
* generic. No username is printed.
*
* @see User
* @see UserGroup
* @see Service
* @see PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
* @see User
* @see UserGroup
* @see Service
* @see PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
*/
public static void main(String[] args) {

Expand All @@ -82,11 +83,12 @@ public static void main(String[] args) {
final Properties turnedOff = new Properties();
turnedOff.put("enhancedWelcome", false);
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);

// --------------------------------------------

Service service2 = new TieredFeatureToggleVersion();

final User paidUser = new User("Jamie Coder");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
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
* a helper method to gather the the status of the feature toggle. In some cases there is no need for the
* {@link Service#isEnhanced()} in {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion}
* where the toggle is determined by the actual {@link User}.
* Simple interfaces to allow the calling of the method to generate the welcome message for a given
* user. While there is a helper method to gather the the status of the feature toggle. In some
* cases there is no need for the {@link Service#isEnhanced()} in {@link
* 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.tieredversion.TieredFeatureToggleVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;

import java.util.Properties;

/**
* This example of the Feature Toogle pattern is less dynamic version than
* {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is turned on
* or off at the time of creation of the service. This example uses simple Java {@link Properties} however it could as
* easily be done with an external configuration file loaded by Spring and so on. A good example of when to use this
* version of the feature toggle is when new features are being developed. So you could have a configuration property
* boolean named development or some sort of system environment variable.
* This example of the Feature Toogle pattern is less dynamic version than {@link
* com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is
* turned on or off at the time of creation of the service. This example uses simple Java {@link
* Properties} however it could as easily be done with an external configuration file loaded by
* Spring and so on. A good example of when to use this version of the feature toggle is when new
* features are being developed. So you could have a configuration property boolean named
* development or some sort of system environment variable.
*
* @see Service
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
Expand All @@ -45,9 +45,10 @@ public class PropertiesFeatureToggleVersion implements Service {
private boolean isEnhanced;

/**
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link Properties} to determine,
* the status of the feature toggle {@link PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive
* code to ensure the {@link Properties} passed are as expected.
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link
* Properties} to determine, the status of the feature toggle {@link
* 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.
* @throws IllegalArgumentException when the passed {@link Properties} is not as expected
Expand All @@ -66,14 +67,14 @@ public PropertiesFeatureToggleVersion(final Properties properties) {
}

/**
* Generate a welcome message based on the user being passed and the status of the feature toggle. If the enhanced
* version is enabled, then the message will be personalised with the name of the passed {@link User}. However if
* disabled then a generic version fo the message is returned.
* Generate a welcome message based on the user being passed and the status of the feature toggle.
* If the enhanced version is enabled, then the message will be personalised with the name of the
* 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
* {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is enabled, then the
* message will be personalised with the name of the 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 {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
* enabled, then the message will be personalised with the name of the passed {@link
* User}. However if disabled then a generic version fo the message is returned.
* @return Resulting welcome message.
* @see User
*/
Expand All @@ -88,9 +89,9 @@ public String getWelcomeMessage(final User user) {
}

/**
* Method that checks if the welcome message to be returned is the enhanced venison or not. For this service it will
* see the value of the boolean that was set in the constructor
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
* Method that checks if the welcome message to be returned is the enhanced venison or not. For
* this service it will see the value of the boolean that was set in the constructor {@link
* PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
*
* @return Boolean value {@code true} if enhanced.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
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
* showing its use within a tiered application where the paying users get access to different content or
* better versions of features. So in this instance a {@link User} is passed in and if they are found to be
* on the {@link UserGroup#isPaid(User)} they are welcomed with a personalised message. While the other is more
* generic. However this pattern is limited to simple examples such as the one below.
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link
* User}. Therefore showing its use within a tiered application where the paying users get access to
* different content or better versions of features. So in this instance a {@link User} is passed in
* and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
* personalised message. While the other is more generic. However this pattern is limited to simple
* examples such as the one below.
*
* @see Service
* @see User
Expand All @@ -42,12 +43,13 @@
public class TieredFeatureToggleVersion implements Service {

/**
* Generates a welcome message from the passed {@link User}. The resulting message depends on the group of the
* {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then the enhanced version of the
* welcome message will be returned where the username is displayed.
* Generates a welcome message from the passed {@link User}. The resulting message depends on the
* group of the {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then
* 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
* in the {@link UserGroup#isPaid(User)} or {@link UserGroup#freeGroup}
* @param user the {@link User} to generate the welcome message for, different messages are
* displayed if the user is in the {@link UserGroup#isPaid(User)} or {@link
* UserGroup#freeGroup}
* @return Resulting welcome message.
* @see User
* @see UserGroup
Expand All @@ -62,9 +64,9 @@ public String getWelcomeMessage(User user) {
}

/**
* Method that checks if the welcome message to be returned is the enhanced version. For this instance as the logic
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
* enhanced version available.
* Method that checks if the welcome message to be returned is the enhanced version. For this
* instance as the logic is driven by the user group. This method is a little redundant. However
* can be used to show that there is an enhanced version available.
*
* @return Boolean value {@code true} if enhanced.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
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 {

Expand All @@ -41,7 +42,9 @@ public User(String name) {

/**
* {@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
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import java.util.List;

/**
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered example of feature
* toggle. Allowing certain features to be available to only certain groups of users.
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered
* example of feature toggle. Allowing certain features to be available to only certain groups of
* users.
*
* @see User
*/
Expand Down Expand Up @@ -76,7 +77,6 @@ public static void addUserToPaidGroup(final User user) throws IllegalArgumentExc
* 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}
*
* @return true if the {@link User} is in {@link UserGroup#paidGroup}
*/
public static boolean isPaid(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -90,16 +88,16 @@ public static void main(String[] args) {
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() {
Expand All @@ -119,7 +117,7 @@ private static <E> void prettyPrint(String prefix, Iterable<E> iterable) {
}

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()) {
Expand Down

0 comments on commit 37599eb

Please sign in to comment.