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;
public class GuestUser {
import model.users.User;
public abstract class GuestUser {
private int generatedId;
private static int IdCounter = 0;
//CONSTRUCTOR
public GuestUser() {
generatedId = ++IdCounter;
......@@ -17,5 +20,6 @@ public class GuestUser {
return generatedId;
}
//OTHER METHODS
public abstract User findUser(int id);
}
......@@ -72,4 +72,7 @@ public class PrivateUser extends User{
}
}
......@@ -15,6 +15,7 @@ public abstract class User extends GuestUser implements IPost{
private String password;
private String generatedPassword;
//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
public User() {
......@@ -23,6 +24,7 @@ public abstract class User extends GuestUser implements IPost{
username = "Empty";
password = "Empty";
generatedPassword = null;
allUsers.add(this);
}
public User(String nameAndSurname, String username, String password) {
......@@ -38,6 +40,7 @@ public abstract class User extends GuestUser implements IPost{
this.password = "Empty";
generatedPassword = null;
}
allUsers.add(this);
}
......@@ -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
public String getNameAndSurname() {
......@@ -81,6 +88,10 @@ public abstract class User extends GuestUser implements IPost{
return generatedPassword;
}
public ArrayList<User> getAllUsers() {
return allUsers;
}
//OTHER METHODS
public String toString() {
return "User ID: " + super.getId() + "Full name: " + nameAndSurname + ", Username: " + username;
......@@ -101,9 +112,13 @@ public abstract class User extends GuestUser implements IPost{
return false;
}
//IMPLEMENTED METHODS
//public void createPost(PostType postType, String msg) {}
//don't implement this if derived classes has to have implementation
//}
//DERRIVED METHODS
@Override
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