Commit 22af89bc authored by Oskars's avatar Oskars
Browse files

Add: finUser method to GuestUser class, implemented in User class

parent 37c9910e
package model.users; package model.users;
public class GuestUser { import model.users.User;
public abstract class GuestUser {
private int generatedId; private int generatedId;
private static int IdCounter = 0; private static int IdCounter = 0;
//CONSTRUCTOR //CONSTRUCTOR
public GuestUser() { public GuestUser() {
generatedId = ++IdCounter; generatedId = ++IdCounter;
...@@ -17,5 +20,6 @@ public class GuestUser { ...@@ -17,5 +20,6 @@ public class GuestUser {
return generatedId; return generatedId;
} }
//OTHER METHODS //OTHER METHODS
public abstract User findUser(int id);
} }
...@@ -70,6 +70,9 @@ public class PrivateUser extends User{ ...@@ -70,6 +70,9 @@ public class PrivateUser extends User{
posts.add(newPost); posts.add(newPost);
return newPost; return newPost;
} }
} }
...@@ -15,6 +15,7 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -15,6 +15,7 @@ public abstract class User extends GuestUser implements IPost{
private String password; private String password;
private String generatedPassword; private String generatedPassword;
//MD5 hashes are no longer considered cryptographically secure, and they should not be used for cryptographic authentication. //MD5 hashes are no longer considered cryptographically secure, and they should not be used for cryptographic authentication.
public static ArrayList<User> allUsers = new ArrayList<User>();
//CONSTRUCTORS //CONSTRUCTORS
public User() { public User() {
...@@ -23,6 +24,7 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -23,6 +24,7 @@ public abstract class User extends GuestUser implements IPost{
username = "Empty"; username = "Empty";
password = "Empty"; password = "Empty";
generatedPassword = null; generatedPassword = null;
allUsers.add(this);
} }
public User(String nameAndSurname, String username, String password) { public User(String nameAndSurname, String username, String password) {
...@@ -38,6 +40,7 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -38,6 +40,7 @@ public abstract class User extends GuestUser implements IPost{
this.password = "Empty"; this.password = "Empty";
generatedPassword = null; generatedPassword = null;
} }
allUsers.add(this);
} }
...@@ -63,6 +66,10 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -63,6 +66,10 @@ public abstract class User extends GuestUser implements IPost{
} }
public void setAllUsers(ArrayList<User> userList) {
allUsers = (userList != null) ? userList : new ArrayList<User>();
}
//GETTERS //GETTERS
public String getNameAndSurname() { public String getNameAndSurname() {
...@@ -81,6 +88,10 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -81,6 +88,10 @@ public abstract class User extends GuestUser implements IPost{
return generatedPassword; return generatedPassword;
} }
public ArrayList<User> getAllUsers() {
return allUsers;
}
//OTHER METHODS //OTHER METHODS
public String toString() { public String toString() {
return "User ID: " + super.getId() + "Full name: " + nameAndSurname + ", Username: " + username; return "User ID: " + super.getId() + "Full name: " + nameAndSurname + ", Username: " + username;
...@@ -101,9 +112,13 @@ public abstract class User extends GuestUser implements IPost{ ...@@ -101,9 +112,13 @@ public abstract class User extends GuestUser implements IPost{
return false; return false;
} }
//IMPLEMENTED METHODS //DERRIVED METHODS
//public void createPost(PostType postType, String msg) {} @Override
//don't implement this if derived classes has to have implementation public User findUser(int id) {
//} for(User usr: allUsers) {
if(usr.getId() == id) return usr;
}
return null;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment