Skip to content

Commit 37599eb

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Resolves checkstyle errors for feature-toggle fluentinterface flux flyweight front-controller (iluwatar#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
1 parent c954a43 commit 37599eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+196
-257
lines changed

feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,47 @@
2828
import com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
2929
import com.iluwatar.featuretoggle.user.User;
3030
import com.iluwatar.featuretoggle.user.UserGroup;
31+
import java.util.Properties;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

34-
import java.util.Properties;
35-
3635
/**
37-
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease. This allows features
38-
* to be controlled by either dynamic methods just as {@link User} information or by {@link Properties}. In the App
39-
* below there are two examples. Firstly the {@link Properties} version of the feature toggle, where the enhanced
40-
* version of the welcome message which is personalised is turned either on or off at instance creation. This method
41-
* is not as dynamic as the {@link User} driven version where the feature of the personalised welcome message is
36+
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease.
37+
* This allows features to be controlled by either dynamic methods just as {@link User} information
38+
* or by {@link Properties}. In the App below there are two examples. Firstly the {@link Properties}
39+
* version of the feature toggle, where the enhanced version of the welcome message which is
40+
* personalised is turned either on or off at instance creation. This method is not as dynamic as
41+
* the {@link User} driven version where the feature of the personalised welcome message is
4242
* dependant on the {@link UserGroup} the {@link User} is in. So if the user is a memeber of the
4343
* {@link UserGroup#isPaid(User)} then they get an ehanced version of the welcome message.
4444
*
45-
* Note that this pattern can easily introduce code complexity, and if not kept in check can result in redundant
46-
* unmaintained code within the codebase.
47-
*
45+
* <p>Note that this pattern can easily introduce code complexity, and if not kept in check can
46+
* result in redundant unmaintained code within the codebase.
4847
*/
4948
public class App {
5049

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

5352
/**
54-
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
55-
* toggle to enabled.
53+
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
54+
* setting the feature toggle to enabled.
5655
*
57-
* Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
58-
* toggle to disabled. Notice the difference with the printed welcome message the username is not included.
56+
* <p>Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties}
57+
* setting the feature toggle to disabled. Notice the difference with the printed welcome message
58+
* the username is not included.
5959
*
60-
* Block 3 shows the {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being
61-
* set up with two users on who is on the free level, while the other is on the paid level. When the
62-
* {@link Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome message
63-
* contains their username, while the same service call with the free tier user is more generic. No username is
64-
* printed.
60+
* <p>Block 3 shows the {@link
61+
* com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being set up with
62+
* two users on who is on the free level, while the other is on the paid level. When the {@link
63+
* Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome
64+
* message contains their username, while the same service call with the free tier user is more
65+
* generic. No username is printed.
6566
*
66-
* @see User
67-
* @see UserGroup
68-
* @see Service
69-
* @see PropertiesFeatureToggleVersion
70-
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
67+
* @see User
68+
* @see UserGroup
69+
* @see Service
70+
* @see PropertiesFeatureToggleVersion
71+
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
7172
*/
7273
public static void main(String[] args) {
7374

@@ -82,11 +83,12 @@ public static void main(String[] args) {
8283
final Properties turnedOff = new Properties();
8384
turnedOff.put("enhancedWelcome", false);
8485
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
85-
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
86+
final String welcomeMessageturnedOff =
87+
turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
8688
LOGGER.info(welcomeMessageturnedOff);
8789

8890
// --------------------------------------------
89-
91+
9092
Service service2 = new TieredFeatureToggleVersion();
9193

9294
final User paidUser = new User("Jamie Coder");

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/Service.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
import com.iluwatar.featuretoggle.user.User;
2727

2828
/**
29-
* Simple interfaces to allow the calling of the method to generate the welcome message for a given user. While there is
30-
* a helper method to gather the the status of the feature toggle. In some cases there is no need for the
31-
* {@link Service#isEnhanced()} in {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion}
32-
* where the toggle is determined by the actual {@link User}.
29+
* Simple interfaces to allow the calling of the method to generate the welcome message for a given
30+
* user. While there is a helper method to gather the the status of the feature toggle. In some
31+
* cases there is no need for the {@link Service#isEnhanced()} in {@link
32+
* com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the toggle is
33+
* determined by the actual {@link User}.
3334
*
3435
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
3536
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersion.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
import com.iluwatar.featuretoggle.pattern.Service;
2727
import com.iluwatar.featuretoggle.user.User;
28-
2928
import java.util.Properties;
3029

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

4747
/**
48-
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link Properties} to determine,
49-
* the status of the feature toggle {@link PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive
50-
* code to ensure the {@link Properties} passed are as expected.
48+
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link
49+
* Properties} to determine, the status of the feature toggle {@link
50+
* PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive code to ensure the
51+
* {@link Properties} passed are as expected.
5152
*
5253
* @param properties {@link Properties} used to configure the service and toggle features.
5354
* @throws IllegalArgumentException when the passed {@link Properties} is not as expected
@@ -66,14 +67,14 @@ public PropertiesFeatureToggleVersion(final Properties properties) {
6667
}
6768

6869
/**
69-
* Generate a welcome message based on the user being passed and the status of the feature toggle. If the enhanced
70-
* version is enabled, then the message will be personalised with the name of the passed {@link User}. However if
71-
* disabled then a generic version fo the message is returned.
70+
* Generate a welcome message based on the user being passed and the status of the feature toggle.
71+
* If the enhanced version is enabled, then the message will be personalised with the name of the
72+
* passed {@link User}. However if disabled then a generic version fo the message is returned.
7273
*
73-
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled see
74-
* {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is enabled, then the
75-
* message will be personalised with the name of the passed {@link User}. However if disabled then a
76-
* generic version fo the message is returned.
74+
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled
75+
* see {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
76+
* enabled, then the message will be personalised with the name of the passed {@link
77+
* User}. However if disabled then a generic version fo the message is returned.
7778
* @return Resulting welcome message.
7879
* @see User
7980
*/
@@ -88,9 +89,9 @@ public String getWelcomeMessage(final User user) {
8889
}
8990

9091
/**
91-
* Method that checks if the welcome message to be returned is the enhanced venison or not. For this service it will
92-
* see the value of the boolean that was set in the constructor
93-
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
92+
* Method that checks if the welcome message to be returned is the enhanced venison or not. For
93+
* this service it will see the value of the boolean that was set in the constructor {@link
94+
* PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
9495
*
9596
* @return Boolean value {@code true} if enhanced.
9697
*/

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersion.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
import com.iluwatar.featuretoggle.user.UserGroup;
2929

3030
/**
31-
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link User}. Therefore
32-
* showing its use within a tiered application where the paying users get access to different content or
33-
* better versions of features. So in this instance a {@link User} is passed in and if they are found to be
34-
* on the {@link UserGroup#isPaid(User)} they are welcomed with a personalised message. While the other is more
35-
* generic. However this pattern is limited to simple examples such as the one below.
31+
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link
32+
* User}. Therefore showing its use within a tiered application where the paying users get access to
33+
* different content or better versions of features. So in this instance a {@link User} is passed in
34+
* and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
35+
* personalised message. While the other is more generic. However this pattern is limited to simple
36+
* examples such as the one below.
3637
*
3738
* @see Service
3839
* @see User
@@ -42,12 +43,13 @@
4243
public class TieredFeatureToggleVersion implements Service {
4344

4445
/**
45-
* Generates a welcome message from the passed {@link User}. The resulting message depends on the group of the
46-
* {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then the enhanced version of the
47-
* welcome message will be returned where the username is displayed.
46+
* Generates a welcome message from the passed {@link User}. The resulting message depends on the
47+
* group of the {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then
48+
* the enhanced version of the welcome message will be returned where the username is displayed.
4849
*
49-
* @param user the {@link User} to generate the welcome message for, different messages are displayed if the user is
50-
* in the {@link UserGroup#isPaid(User)} or {@link UserGroup#freeGroup}
50+
* @param user the {@link User} to generate the welcome message for, different messages are
51+
* displayed if the user is in the {@link UserGroup#isPaid(User)} or {@link
52+
* UserGroup#freeGroup}
5153
* @return Resulting welcome message.
5254
* @see User
5355
* @see UserGroup
@@ -62,9 +64,9 @@ public String getWelcomeMessage(User user) {
6264
}
6365

6466
/**
65-
* Method that checks if the welcome message to be returned is the enhanced version. For this instance as the logic
66-
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
67-
* enhanced version available.
67+
* Method that checks if the welcome message to be returned is the enhanced version. For this
68+
* instance as the logic is driven by the user group. This method is a little redundant. However
69+
* can be used to show that there is an enhanced version available.
6870
*
6971
* @return Boolean value {@code true} if enhanced.
7072
*/

feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/User.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
package com.iluwatar.featuretoggle.user;
2525

2626
/**
27-
* Used to demonstrate the purpose of the feature toggle. This class actually has nothing to do with the pattern.
27+
* Used to demonstrate the purpose of the feature toggle. This class actually has nothing to do with
28+
* the pattern.
2829
*/
2930
public class User {
3031

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

4243
/**
4344
* {@inheritDoc}
44-
* @return The {@link String} representation of the User, in this case just return the name of the user.
45+
*
46+
* @return The {@link String} representation of the User, in this case just return the name of the
47+
* user.
4548
*/
4649
@Override
4750
public String toString() {

feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/UserGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import java.util.List;
2828

2929
/**
30-
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered example of feature
31-
* toggle. Allowing certain features to be available to only certain groups of users.
30+
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered
31+
* example of feature toggle. Allowing certain features to be available to only certain groups of
32+
* users.
3233
*
3334
* @see User
3435
*/
@@ -76,7 +77,6 @@ public static void addUserToPaidGroup(final User user) throws IllegalArgumentExc
7677
* Method to take a {@link User} to determine if the user is in the {@link UserGroup#paidGroup}.
7778
*
7879
* @param user {@link User} to check if they are in the {@link UserGroup#paidGroup}
79-
*
8080
* @return true if the {@link User} is in {@link UserGroup#paidGroup}
8181
*/
8282
public static boolean isPaid(User user) {

fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,37 @@
2323

2424
package com.iluwatar.fluentinterface.app;
2525

26+
import static java.lang.String.valueOf;
27+
2628
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
2729
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
2830
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
31-
3231
import java.util.ArrayList;
3332
import java.util.Iterator;
3433
import java.util.List;
3534
import java.util.StringJoiner;
3635
import java.util.function.Function;
3736
import java.util.function.Predicate;
38-
39-
import static java.lang.String.valueOf;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
4039

4140
/**
4241
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
4342
* Those interfaces tend to mimic domain specific languages, so they can nearly be read as human
4443
* languages.
45-
* <p>
46-
* In this example two implementations of a {@link FluentIterable} interface are given. The
44+
*
45+
* <p>In this example two implementations of a {@link FluentIterable} interface are given. The
4746
* {@link SimpleFluentIterable} evaluates eagerly and would be too costly for real world
4847
* applications. The {@link LazyFluentIterable} is evaluated on termination. Their usage is
4948
* demonstrated with a simple number list that is filtered, transformed and collected. The result is
5049
* printed afterwards.
51-
*
5250
*/
5351
public class App {
5452

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

5755
/**
58-
* Program entry point
56+
* Program entry point.
5957
*/
6058
public static void main(String[] args) {
6159

@@ -90,16 +88,16 @@ public static void main(String[] args) {
9088
List<String> lastTwoOfFirstFourStringMapped =
9189
LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2)
9290
.map(number -> "String[" + valueOf(number) + "]").asList();
93-
prettyPrint(
94-
"The lazy list contains the last two of the first four positive numbers mapped to Strings: ",
95-
lastTwoOfFirstFourStringMapped);
91+
prettyPrint("The lazy list contains the last two of the first four positive numbers "
92+
+ "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
9693

9794
LazyFluentIterable
9895
.from(integerList)
9996
.filter(negatives())
10097
.first(2)
10198
.last()
102-
.ifPresent(lastOfFirstTwo -> LOGGER.info("The last of the first two negatives is: {}", lastOfFirstTwo));
99+
.ifPresent(lastOfFirstTwo -> LOGGER
100+
.info("The last of the first two negatives is: {}", lastOfFirstTwo));
103101
}
104102

105103
private static Function<Integer, String> transformToString() {
@@ -119,7 +117,7 @@ private static <E> void prettyPrint(String prefix, Iterable<E> iterable) {
119117
}
120118

121119
private static <E> void prettyPrint(String delimiter, String prefix,
122-
Iterable<E> iterable) {
120+
Iterable<E> iterable) {
123121
StringJoiner joiner = new StringJoiner(delimiter, prefix, ".");
124122
Iterator<E> iterator = iterable.iterator();
125123
while (iterator.hasNext()) {

0 commit comments

Comments
 (0)