2
2
3
3
import java .util .ArrayList ;
4
4
5
+ /**
6
+ * A user that has their username, password, whether they have admin access, and the list of all the ids
7
+ * of the flashcard sets that belong to them
8
+ *<p>
9
+ * Enterprise Business Rules
10
+ * @author Aryan Chablani
11
+ */
12
+
5
13
public class CommonUser implements User {
6
14
7
15
private String username ;
8
-
9
16
private String password ;
10
17
private boolean isAdmin ;
11
18
final String ADMIN_KEY = "BuiltDifferent" ;
12
19
final ArrayList <Integer > flashcardSetIds ;
13
20
21
+ /**
22
+ * Constructor for Common User
23
+ * Precondition: No common user for this username exists yet
24
+ * @param username the username of the user
25
+ * @param password the password of the user
26
+ * @param isAdmin whether the user is an admin or not
27
+ * @return a CommonUser object
28
+ * Post Condition: A common user will be instantiated.
29
+ */
14
30
public CommonUser (String username , String password , boolean isAdmin ){
15
31
this .username = username ;
16
32
this .password = password ;
17
33
this .isAdmin = isAdmin ;
18
34
this .flashcardSetIds = new ArrayList <>();
19
35
}
20
36
37
+ //GETTERS AND SETTERS
21
38
@ Override
22
39
public String getUsername () {
23
40
return username ;
@@ -36,11 +53,6 @@ public void setPassword(String password) {
36
53
this .password = password ;
37
54
}
38
55
39
- @ Override
40
- public boolean passwordIsValid () {
41
- return password != null && password .length () > 5 ;
42
- }
43
-
44
56
@ Override
45
57
public boolean getIsAdmin () {
46
58
return isAdmin ;
@@ -55,6 +67,20 @@ public ArrayList<Integer> getFlashcardSetIds() {
55
67
return flashcardSetIds ;
56
68
}
57
69
70
+ /**
71
+ * Checks whether the password is valid by not being nothing and greater in length by 5
72
+ * @return whether the password is valid
73
+ */
74
+ @ Override
75
+ public boolean passwordIsValid () {
76
+ return password != null && password .length () > 5 ;
77
+ }
78
+
79
+ /**
80
+ * Checks whether the admin key entered is similar to the actual admin key in the business rules
81
+ * @param adminKey the username of the use
82
+ * @return whether the admin is the same as the one stored in the enterprise rules
83
+ */
58
84
@ Override
59
85
public boolean adminKeyValid (String adminKey ) {
60
86
return adminKey .equals (ADMIN_KEY );
0 commit comments