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:
committed by
Ilkka Seppälä
parent
c954a436ad
commit
37599eb48f
@ -28,46 +28,47 @@ import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureTog
|
||||
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) {
|
||||
|
||||
@ -82,11 +83,12 @@ public class App {
|
||||
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");
|
||||
|
@ -26,10 +26,11 @@ package com.iluwatar.featuretoggle.pattern;
|
||||
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
|
||||
|
@ -25,16 +25,16 @@ package com.iluwatar.featuretoggle.pattern.propertiesversion;
|
||||
|
||||
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
|
||||
@ -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
|
||||
@ -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
|
||||
* 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
|
||||
*/
|
||||
@ -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
|
||||
* 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.
|
||||
*/
|
||||
|
@ -28,11 +28,12 @@ import com.iluwatar.featuretoggle.user.User;
|
||||
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
|
||||
@ -42,12 +43,13 @@ import com.iluwatar.featuretoggle.user.UserGroup;
|
||||
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
|
||||
@ -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
|
||||
* 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.
|
||||
*/
|
||||
|
@ -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 {
|
||||
|
||||
@ -41,7 +42,9 @@ public class User {
|
||||
|
||||
/**
|
||||
* {@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() {
|
||||
|
@ -27,8 +27,9 @@ import java.util.ArrayList;
|
||||
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
|
||||
*/
|
||||
@ -76,7 +77,6 @@ public class UserGroup {
|
||||
* 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) {
|
||||
|
Reference in New Issue
Block a user