Commit 6bd61858 authored by Oskars's avatar Oskars
Browse files

Add: main class, minor debug changes

parent 0321d9b1
package main;
import model.users.BusinessUser;
import model.users.PrivateUser;
import model.users.User;
import model.Post;
import model.Page;
import model.PostType;
public class main {
public static void main(String[] args) {
PrivateUser privateUser1 = new PrivateUser("Oskars Birgelis", "Oskars", "Birgelis", null, null);
PrivateUser privateUser2 = new PrivateUser("Peteris Petersons", "Peteris", "Petersons", null, null);
BusinessUser businessUser1 = new BusinessUser("Armands Armandsons", "Armands", "Armandsons", null);
BusinessUser businessUser2 = new BusinessUser("Pavels Pavelsons", "Pavels", "Pavelsons", null);
Post publicPost1 = new Post(PostType.PUBLIC, "this is public Post number 1");
Post publicPost2 = new Post(PostType.PUBLIC, "this is public Post number 2");
Post privatePost1 = new Post(PostType.PRIVATE, "this is private Post number 1");
Post privatePost2 = new Post(PostType.PRIVATE, "this is private Post number 2");
privateUser1.addPost(publicPost1);
privateUser1.addPost(privatePost1);
privateUser2.addPost(publicPost2);
privateUser2.addPost(privatePost2);
Page page1 = new Page("Physics","This is page about physics", null, null);
Page page2 = new Page("Mathematics","This is page about mathematics", null, null);
page1.addPostInPage(publicPost1);
page1.addPostInPage(publicPost2);
page2.addPostInPage(privatePost1);
page2.addPostInPage(privatePost2);
//printUserInfo(privateUser1);
}
// public static void printUserInfo(User user) {
// System.out.println(user.toString());
// }
}
......@@ -38,11 +38,11 @@ public class Page {
}
public void setFollowers(ArrayList<User> followers) {
followers = (followers != null)? followers : new ArrayList<User>();
this.followers = (followers != null)? followers : new ArrayList<User>();
}
public void setPostsInPage(ArrayList<Post> posts) {
posts = (posts != null)? postsInPage : new ArrayList<Post>();
postsInPage = (posts != null)? posts : new ArrayList<Post>();
}
// public void setAllPages(ArrayList<Page> pages) {
......@@ -71,6 +71,10 @@ public class Page {
return "Title: " + title + ", Description: " + description + ", Followers " + followers.size() + ", Posts: " + postsInPage.size();
}
public void addPostInPage(Post post) {
if(post !=null) postsInPage.add(post);
}
......
package model;
import java.util.regex.*;
public class Verification {
public static boolean verificateNameAndSurname(String fullName) {
if(fullName == null || fullName.length() > 50) return false;
return fullName.matches( "([A-Z][a-z]*)(( )[A-Z][a-z]*)*)" )? true : false; // regex - First Last Etc Etc
return fullName.matches( "([A-Z][a-z]*)(( )[A-Z][a-z]*)*" )? true : false; // regex - First Last Etc Etc
}
public static boolean verificateUsername (String username) {
......
......@@ -9,21 +9,18 @@ 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
......@@ -35,8 +32,6 @@ public class PrivateUser extends User{
this.followers = (followers != null)? followers : new ArrayList<User>();
}
//GETTERS
public ArrayList<Post> getPosts() {
return posts;
......@@ -46,10 +41,6 @@ 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();
......@@ -62,6 +53,10 @@ public class PrivateUser extends User{
privateUser.setFollowers(uf);
}
}
public void addPost(Post post) {
if(post != null) posts.add(post);
}
//DERRIVED ABSTRACT METHODS, includes IPost interface
@Override
......
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