Commit 0321d9b1 authored by Oskars's avatar Oskars
Browse files

Add: finUser(), findPage(), findPublicPostsInPrivateUser(),...

Add: finUser(), findPage(), findPublicPostsInPrivateUser(), findPublicPostsInPage() methods to GuestUser Class.
parent 22af89bc
......@@ -9,6 +9,7 @@ public class Page {
private String description;
private ArrayList<User> followers; // Need to make class Users
private ArrayList<Post> postsInPage;
public static ArrayList<Page> allPages= new ArrayList<Page>();
//CONSTRUCTORS
public Page() {
......@@ -16,6 +17,7 @@ public class Page {
description = "Empty";
followers = new ArrayList<User>();
postsInPage = new ArrayList<Post>();
allPages.add(this);
}
public Page (String title, String description, ArrayList<User> followers, ArrayList<Post> postsInPage) {
......@@ -23,6 +25,7 @@ public class Page {
setDescription(description);
setFollowers(followers);
setPostsInPage(postsInPage);
allPages.add(this);
}
//SETTERS
......@@ -42,6 +45,10 @@ public class Page {
posts = (posts != null)? postsInPage : new ArrayList<Post>();
}
// public void setAllPages(ArrayList<Page> pages) {
// allPages = (pages != null)? allPages : new ArrayList<Page>();
// }
//GETTERS
public String getTitle() {
return title;
......@@ -55,6 +62,9 @@ public class Page {
public ArrayList<Post> getPostsInPage() {
return postsInPage;
}
public ArrayList<Page> getAllPages(){
return allPages;
}
//OTHER METHODS
public String toString() {
......
......@@ -53,6 +53,12 @@ public class BusinessUser extends User implements IPost{
return newPost;
}
@Override
public ArrayList<Post> findPublicPostsInPrivateUser(){
System.out.println("This user is not Private.");
return null;
}
public void createPostInPage(PostType postType, String message, Page page){
Post newPost = createPost(postType, message);
for(Page pag: listOfPages) {
......@@ -62,7 +68,7 @@ public class BusinessUser extends User implements IPost{
pag.setPostsInPage(postsInPage);
}
}
}
}
package model.users;
import model.users.User;
import java.util.ArrayList;
import model.Page;
import model.Post;
public abstract class GuestUser {
......@@ -20,6 +23,9 @@ public abstract class GuestUser {
return generatedId;
}
//OTHER METHODS
public abstract User findUser(int id);
public abstract User findUser(String username);
public abstract Page findPage(String title);
public abstract ArrayList<Post> findPublicPostsInPrivateUser();
public abstract ArrayList<Post> findPublicPostInPage(Page page);
}
......@@ -9,30 +9,24 @@ public class PrivateUser extends User{
private ArrayList<Post> posts;
private ArrayList<User> followers;
//public static ArrayList<PrivateUser> allPrivateUsers = new ArrayList<PrivateUser>();
//CONSTRUCTORS
public PrivateUser() {
super();
posts = new ArrayList<Post>();
followers = new ArrayList<User>();
//allPrivateUsers.add(this);
}
public PrivateUser(String nameAndSurname, String username, String password, ArrayList<Post> posts, ArrayList<User> followers) {
super(nameAndSurname, username, password);
setPosts(posts);
setFollowers(followers);
//allPrivateUsers.add(this);
}
//SETTERS
// public void setUser(User user) {
// if(user != null) {
// this.setNameAndSurname(user.getNameAndSurname());
// this.setUsername(user.getUsername());
// this.setPassword(user.getPassword());
// }
// }
//SETTERS
public void setPosts(ArrayList<Post> posts) {
this.posts = (posts != null)? posts : new ArrayList<Post>();
}
......@@ -41,6 +35,8 @@ public class PrivateUser extends User{
this.followers = (followers != null)? followers : new ArrayList<User>();
}
//GETTERS
public ArrayList<Post> getPosts() {
return posts;
......@@ -50,6 +46,10 @@ public class PrivateUser extends User{
return followers;
}
// public ArrayList<PrivateUser> getAllPrivateUsers(){
// return allPrivateUsers;
// }
//OTHER METHODS
public String toString() {
return super.toString() + ", Posts: " + posts.size() + ", Followers: " + followers.size();
......@@ -70,6 +70,18 @@ public class PrivateUser extends User{
posts.add(newPost);
return newPost;
}
@Override
public ArrayList<Post> findPublicPostsInPrivateUser(){
ArrayList<Post> publicPosts = new ArrayList<Post>();
for(Post post: posts) {
if(post.getPostType() == PostType.PUBLIC) {
publicPosts.add(post);
}
}
return publicPosts;
}
......
......@@ -3,6 +3,8 @@ package model.users;
import java.util.ArrayList;
import model.Encryption;
import model.Page;
import model.Post;
import model.PostType;
//import model.PostType;
import model.Verification;
import ifaces.IPost;
......@@ -66,9 +68,9 @@ public abstract class User extends GuestUser implements IPost{
}
public void setAllUsers(ArrayList<User> userList) {
allUsers = (userList != null) ? userList : new ArrayList<User>();
}
// public void setAllUsers(ArrayList<User> userList) {
// allUsers = (userList != null) ? userList : new ArrayList<User>();
// }
//GETTERS
......@@ -114,11 +116,34 @@ public abstract class User extends GuestUser implements IPost{
//DERRIVED METHODS
@Override
public User findUser(int id) {
public User findUser(String username) {
for(User usr: allUsers) {
if(usr.getId() == id) return usr;
if(usr.getUsername() == username) return usr;
}
return null;
}
@Override
public Page findPage(String title) {
for(Page pag: Page.allPages) {
if(pag.getTitle() == title) return pag;
}
return null;
}
@Override
public ArrayList<Post> findPublicPostInPage(Page page){
ArrayList<Post> publicPosts = new ArrayList<Post>();
for(Page pag : Page.allPages) {
if(pag.getTitle() == page.getTitle()) {
for(Post post: pag.getPostsInPage()) {
if(post.getPostType() == PostType.PUBLIC) publicPosts.add(post);
}
}
}
return publicPosts;
}
}
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