Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1fa8a60
Sharding Pattern (#1056)
Azureyjt Nov 8, 2019
6d1c0b1
Resolves checkstyle errors for ambassador, async-method-invocation, b…
anuragagarwal561994 Nov 9, 2019
efc17fc
Resolves checkstyle errors for business-delegate, bytecode, caching (…
anuragagarwal561994 Nov 9, 2019
31f27a7
Resolves checkstyle errors for callback, chain, circuit-breaker (#1060)
anuragagarwal561994 Nov 9, 2019
2f49648
Resolves checkstyle errors for collection-pipeline, command, commande…
anuragagarwal561994 Nov 9, 2019
4f9ee01
Resolves checkstyle errors for converter, cqrs (#1063)
anuragagarwal561994 Nov 10, 2019
dda0953
Resolves checkstyle errors for guarded-suspension, half-sync-half-asy…
anuragagarwal561994 Nov 10, 2019
7f06f3b
Resolves checkstyle errors for intercepting-filter, interpreter, iter…
anuragagarwal561994 Nov 10, 2019
eae09fc
Resolves checkstyle errors for api-gateway, lazy-loading, leader-elec…
anuragagarwal561994 Nov 10, 2019
01e489c
Resolves checkstyle errors for dao data-bus data-locality data-mapper…
anuragagarwal561994 Nov 10, 2019
f2c91eb
Resolves checkstyle errors for delegation dependency-injection dirty-…
anuragagarwal561994 Nov 10, 2019
7c888e8
Resolves checkstyle errors for eip-* (#1069)
anuragagarwal561994 Nov 10, 2019
5ae2ce6
Resolves checkstyle errors for event-* (#1070)
anuragagarwal561994 Nov 10, 2019
4dae1fa
Resolves checkstyle errors for execute-around extension-objects (#1071)
anuragagarwal561994 Nov 10, 2019
9c8ad44
Resolves checkstyle errors for patterns starting with letter r (#1072)
anuragagarwal561994 Nov 10, 2019
b92eb52
Resolves checkstyle errors for template-method thread-pool throttling…
anuragagarwal561994 Nov 10, 2019
f0f0143
Resolves checkstyle errors for trampoline twin typeobjectpattern unit…
anuragagarwal561994 Nov 10, 2019
c441831
Java 11 migration: ambassador async-method-invocation balking bridge …
anuragagarwal561994 Nov 11, 2019
329479d
#984 update Ambassador readme
iluwatar Nov 11, 2019
0272d71
#984 update Bridge readme
iluwatar Nov 11, 2019
2628cc0
#984 update Builder readme
iluwatar Nov 11, 2019
c954a43
Resolves checkstyle errors for facade factory-kit spatial-partition s…
anuragagarwal561994 Nov 11, 2019
37599eb
Resolves checkstyle errors for feature-toggle fluentinterface flux fl…
anuragagarwal561994 Nov 11, 2019
3907951
Resolves checkstyle issues for semaphore servant serverless service-l…
anuragagarwal561994 Nov 11, 2019
1e76d91
Resolves checkstyle errors for abstract-document abstract-factory acy…
anuragagarwal561994 Nov 11, 2019
6ef840f
Resolves checkstyle errors for naked-objects null-object object-mothe…
anuragagarwal561994 Nov 12, 2019
33ea733
Java 11 migration: patterns (remaining b-c) (#1081)
anuragagarwal561994 Nov 12, 2019
3c57bf7
#984 #987 update readmes
iluwatar Nov 12, 2019
f04fc3c
Java 11 migration: patterns starting with a (#1084)
anuragagarwal561994 Nov 13, 2019
160b737
Add another real world example for Builder
iluwatar Nov 13, 2019
50467c9
Java 11 migration: patterns (t-v) (#1085)
anuragagarwal561994 Nov 14, 2019
cc571f4
Saga pattern (#1062)
besok Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resolves checkstyle errors for feature-toggle fluentinterface flux fl…
…yweight 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
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 11, 2019
commit 37599eb48f8f3f376d9b3b40f5f6ec9e79c762aa
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
Loading