Skip to content

Commit c2e750a

Browse files
committed
iluwatar#354 finished method javadocs
1 parent 98326a1 commit c2e750a

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22

33
import com.iluwatar.featuretoggle.user.User;
44

5-
5+
/**
6+
* Simple interfaces to allow the calling of the method to generate the welcome message for a given user. While there is
7+
* a helper method to gather the the status of the feature toggle. In some cases there is no need for the
8+
* {@link Service#isEnhanced()} in {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion}
9+
* where the toggle is determined by the actual {@link User}.
10+
*
11+
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
12+
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
13+
* @see User
14+
*/
615
public interface Service {
716

17+
/**
18+
* Generates a welcome message for the passed user.
19+
*
20+
* @param user the {@link User} to be used if the message is to be personalised.
21+
* @return Generated {@link String} welcome message
22+
*/
823
String getWelcomeMessage(User user);
924

25+
/**
26+
* Returns if the welcome message to be displayed will be the enhanced version.
27+
*
28+
* @return Boolean {@value true} if enhanced.
29+
*/
1030
boolean isEnhanced();
1131

1232
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
import java.util.Properties;
77

8+
/**
9+
*
10+
*/
811
public class PropertiesFeatureToggleVersion implements Service {
912

1013
private boolean isEnhanced;
1114

1215
/**
16+
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link Properties} to determine,
17+
* the status of the feature toggle {@link PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive
18+
* code to ensure the {@link Properties} passed are as expected.
1319
*
1420
* @param properties {@link Properties} used to configure the service and toggle features.
21+
* @throws IllegalArgumentException when the passed {@link Properties} is not as expected
22+
* @see Properties
1523
*/
1624
public PropertiesFeatureToggleVersion(final Properties properties) {
1725
if (properties == null) {
@@ -25,6 +33,18 @@ public PropertiesFeatureToggleVersion(final Properties properties) {
2533
}
2634
}
2735

36+
/**
37+
* Generate a welcome message based on the user being passed and the status of the feature toggle. If the enhanced
38+
* version is enabled, then the message will be personalised with the name of the passed {@link User}. However if
39+
* disabled then a generic version fo the message is returned.
40+
*
41+
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled see
42+
* {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is enabled, then the
43+
* message will be personalised with the name of the passed {@link User}. However if disabled then a
44+
* generic version fo the message is returned.
45+
* @return Resulting welcome message.
46+
* @see User
47+
*/
2848
@Override
2949
public String getWelcomeMessage(final User user) {
3050

@@ -35,6 +55,13 @@ public String getWelcomeMessage(final User user) {
3555
return "Welcome to the application.";
3656
}
3757

58+
/**
59+
* Method that checks if the welcome message to be returned is the enhanced venison or not. For this service it will
60+
* see the value of the boolean that was set in the constructor
61+
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
62+
*
63+
* @return Boolean value {@value true} if enhanced.
64+
*/
3865
@Override
3966
public boolean isEnhanced() {
4067
return isEnhanced;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44
import com.iluwatar.featuretoggle.user.User;
55
import com.iluwatar.featuretoggle.user.UserGroup;
66

7+
/**
8+
*
9+
*/
710
public class TieredFeatureToggleVersion implements Service {
811

12+
/**
13+
* Generates a welcome message from the passed {@link User}. The resulting message depends on the group of the
14+
* {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then the enhanced version of the
15+
* welcome message will be returned where the username is displayed.
16+
*
17+
* @param user the {@link User} to generate the welcome message for, different messages are displayed if the user is
18+
* in the {@link UserGroup#isPaid(User)} or {@link UserGroup#freeGroup}
19+
* @return Resulting welcome message.
20+
* @see User
21+
* @see UserGroup
22+
*/
923
@Override
1024
public String getWelcomeMessage(User user) {
1125
if (UserGroup.isPaid(user)) {
@@ -15,6 +29,13 @@ public String getWelcomeMessage(User user) {
1529
return "I suppose you can use this software.";
1630
}
1731

32+
/**
33+
* Method that checks if the welcome message to be returned is the enhanced version. For this instance as the logic
34+
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
35+
* enhanced version available.
36+
*
37+
* @return Boolean value {@value true} if enhanced.
38+
*/
1839
@Override
1940
public boolean isEnhanced() {
2041
return true;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class UserGroup {
1919
* Add the passed {@link User} to the free user group list.
2020
*
2121
* @param user {@link User} to be added to the free group
22-
* @throws IllegalArgumentException
22+
* @throws IllegalArgumentException when user is already added to the paid group
2323
* @see User
2424
*/
2525
public static void addUserToFreeGroup(final User user) throws IllegalArgumentException {
@@ -36,7 +36,7 @@ public static void addUserToFreeGroup(final User user) throws IllegalArgumentExc
3636
* Add the passed {@link User} to the paid user group list.
3737
*
3838
* @param user {@link User} to be added to the paid group
39-
* @throws IllegalArgumentException
39+
* @throws IllegalArgumentException when the user is already added to the free group
4040
* @see User
4141
*/
4242
public static void addUserToPaidGroup(final User user) throws IllegalArgumentException {
@@ -49,6 +49,13 @@ public static void addUserToPaidGroup(final User user) throws IllegalArgumentExc
4949
}
5050
}
5151

52+
/**
53+
* Method to take a {@link User} to determine if the user is in the {@link UserGroup#paidGroup}.
54+
*
55+
* @param user {@link User} to check if they are in the {@link UserGroup#paidGroup}
56+
*
57+
* @return true if the {@link User} is in {@link UserGroup#paidGroup}
58+
*/
5259
public static boolean isPaid(User user) {
5360
return paidGroup.contains(user);
5461
}

0 commit comments

Comments
 (0)