#354 finished method javadocs
This commit is contained in:
		@@ -2,11 +2,31 @@ 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}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
 | 
			
		||||
 * @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
 | 
			
		||||
 * @see User
 | 
			
		||||
 */
 | 
			
		||||
public interface Service {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Generates a welcome message for the passed user.
 | 
			
		||||
   *
 | 
			
		||||
   * @param user the {@link User} to be used if the message is to be personalised.
 | 
			
		||||
   * @return Generated {@link String} welcome message
 | 
			
		||||
   */
 | 
			
		||||
  String getWelcomeMessage(User user);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns if the welcome message to be displayed will be the enhanced version.
 | 
			
		||||
   *
 | 
			
		||||
   * @return Boolean {@value true} if enhanced.
 | 
			
		||||
   */
 | 
			
		||||
  boolean isEnhanced();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,13 +5,21 @@ import com.iluwatar.featuretoggle.user.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Properties;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
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.
 | 
			
		||||
   *
 | 
			
		||||
   * @param properties {@link Properties} used to configure the service and toggle features.
 | 
			
		||||
   * @throws IllegalArgumentException when the passed {@link Properties} is not as expected
 | 
			
		||||
   * @see Properties
 | 
			
		||||
   */
 | 
			
		||||
  public PropertiesFeatureToggleVersion(final Properties properties) {
 | 
			
		||||
    if (properties == null) {
 | 
			
		||||
@@ -25,6 +33,18 @@ 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.
 | 
			
		||||
   *
 | 
			
		||||
   * @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
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getWelcomeMessage(final User user) {
 | 
			
		||||
 | 
			
		||||
@@ -35,6 +55,13 @@ public class PropertiesFeatureToggleVersion implements Service {
 | 
			
		||||
    return "Welcome to the application.";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 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 {@value true} if enhanced.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isEnhanced() {
 | 
			
		||||
    return isEnhanced;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,22 @@ import com.iluwatar.featuretoggle.pattern.Service;
 | 
			
		||||
import com.iluwatar.featuretoggle.user.User;
 | 
			
		||||
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.
 | 
			
		||||
   *
 | 
			
		||||
   * @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
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getWelcomeMessage(User user) {
 | 
			
		||||
    if (UserGroup.isPaid(user)) {
 | 
			
		||||
@@ -15,6 +29,13 @@ public class TieredFeatureToggleVersion implements Service {
 | 
			
		||||
    return "I suppose you can use this software.";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 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 {@value true} if enhanced.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isEnhanced() {
 | 
			
		||||
    return true;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ public class UserGroup {
 | 
			
		||||
   * Add the passed {@link User} to the free user group list.
 | 
			
		||||
   *
 | 
			
		||||
   * @param user {@link User} to be added to the free group
 | 
			
		||||
   * @throws IllegalArgumentException
 | 
			
		||||
   * @throws IllegalArgumentException when user is already added to the paid group
 | 
			
		||||
   * @see User
 | 
			
		||||
   */
 | 
			
		||||
  public static void addUserToFreeGroup(final User user) throws IllegalArgumentException {
 | 
			
		||||
@@ -36,7 +36,7 @@ public class UserGroup {
 | 
			
		||||
   * Add the passed {@link User} to the paid user group list.
 | 
			
		||||
   *
 | 
			
		||||
   * @param user {@link User} to be added to the paid group
 | 
			
		||||
   * @throws IllegalArgumentException
 | 
			
		||||
   * @throws IllegalArgumentException when the user is already added to the free group
 | 
			
		||||
   * @see User
 | 
			
		||||
   */
 | 
			
		||||
  public static void addUserToPaidGroup(final User user) throws IllegalArgumentException {
 | 
			
		||||
@@ -49,6 +49,13 @@ 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) {
 | 
			
		||||
    return paidGroup.contains(user);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user