46 lines
1.1 KiB
Java
Raw Normal View History

package com.iluwatar.featuretoggle.user;
import java.util.ArrayList;
import java.util.List;
2016-01-26 19:20:28 +00:00
/**
* Contains the lists of users of different groups paid and free
*/
public class UserGroup {
2016-01-26 19:20:28 +00:00
private static List<User> freeGroup = new ArrayList<>();
private static List<User> paidGroup = new ArrayList<>();
2016-01-26 19:20:28 +00:00
/**
*
* @param user {@link User} to be added to the free group
*/
public static void addUserToFreeGroup(final User user) {
if (paidGroup.contains(user)) {
throw new IllegalArgumentException("User all ready member of paid group.");
} else {
if (!freeGroup.contains(user)) {
freeGroup.add(user);
}
}
2016-01-26 19:20:28 +00:00
}
2016-01-26 19:20:28 +00:00
/**
*
* @param user {@link User} to be added to the paid group
*/
public static void addUserToPaidGroup(final User user) {
if (freeGroup.contains(user)) {
throw new IllegalArgumentException("User all ready member of free group.");
} else {
if (!paidGroup.contains(user)) {
paidGroup.add(user);
}
}
2016-01-26 19:20:28 +00:00
}
2016-01-26 19:20:28 +00:00
public static boolean isPaid(User user) {
return paidGroup.contains(user);
}
}