From 77d7c260af271ce65fb3fe88374eb557ef16afa3 Mon Sep 17 00:00:00 2001 From: Alexey Sinyuk Date: Mon, 16 Feb 2015 14:38:03 +0200 Subject: [PATCH 1/3] Webblog by Alexey Sinyuk initial commit --- AlexeySinyuk/src/Blog/MainClass.java | 23 +++++ AlexeySinyuk/src/Blog/Post.java | 120 +++++++++++++++++++++++++++ AlexeySinyuk/src/Blog/User.java | 41 +++++++++ 3 files changed, 184 insertions(+) create mode 100644 AlexeySinyuk/src/Blog/MainClass.java create mode 100644 AlexeySinyuk/src/Blog/Post.java create mode 100644 AlexeySinyuk/src/Blog/User.java diff --git a/AlexeySinyuk/src/Blog/MainClass.java b/AlexeySinyuk/src/Blog/MainClass.java new file mode 100644 index 0000000..0d3bcea --- /dev/null +++ b/AlexeySinyuk/src/Blog/MainClass.java @@ -0,0 +1,23 @@ +package Blog; + +/** + * Created by asinuk on 16/02/2015. + */ +public abstract class MainClass { + + public static void main(String[] args) { + + System.out.println("Hello!"); + User user1 = new User ("Alexey", "Sinyuk"); + Post post1 = new Post ("Post1", user1, "coolstory psto"); + post1.addComment(user1, "Perviy ololo!"); + post1.addComment(user1, "Vtoroy!"); + post1.Print(); + + post1.getComment(2).PrintComment(); + post1.getComment(1).Delete(); + post1.Print(); + + } + +} diff --git a/AlexeySinyuk/src/Blog/Post.java b/AlexeySinyuk/src/Blog/Post.java new file mode 100644 index 0000000..53f35a3 --- /dev/null +++ b/AlexeySinyuk/src/Blog/Post.java @@ -0,0 +1,120 @@ +package Blog; + +/** + * Created by asinuk on 16/02/2015. + */ +public class Post { + + private String Title; + protected User Poster; + protected String Text; + protected String Imgurl; + + private Post prevComment; + private Post nextComment; + + public Post (String Title, User Poster, String Text){ + this.Title = Title; + this.Poster = Poster; + this.Text = Text; + + Poster.incPosts(); + } + + public Post (String Title, User Poster, String Text, String Imgurl){ + this(Title, Poster, Text); + this.Imgurl = Imgurl; + + Poster.incPosts(); + } + + private Post (Post prevComment, User Poster, String Text){ + this("", Poster, Text); + this.prevComment = prevComment; + } + + private Post (Post prevComment, User Poster, String Text, String Imgurl){ + this("", Poster, Text, Imgurl); + this.prevComment = prevComment; + } + + public String getTitle (){ + return Title; + } + + public User getPoster (){ + return Poster; + } + + public String getText (){ + return Text; + } + + public String getImgurl () { + return Imgurl; + } + + public void setText (String Text){ + this.Text = Text; + } + + public void setImgurl (String Imgurl) { + this.Imgurl = Imgurl; + } + + public void addComment (User Poster, String Text){ + if (nextComment == null) { + nextComment = new Post (this, Poster, Text); + } else { + nextComment.addComment(Poster, Text); + } + } + + public void addComment (User Poster, String Text, String Imgurl){ + if (nextComment == null) { + nextComment = new Post (this, Poster, Text, Imgurl); + } else { + nextComment.addComment(Poster, Text, Imgurl); + } + } + + public Post getComment (int id){ + //TODO exceptions + if (nextComment != null) { + return nextComment.getComment(id, 1); + } else { + return null; + } + } + + private Post getComment (int id, int depth){ + if (id == depth) { + return this; + } else { + if (nextComment != null) { + return nextComment.getComment(id, depth + 1); + } else { + return null; + } + } + } + + public void Delete (){ + //TODO exceptions + prevComment.nextComment = nextComment; + nextComment.prevComment = prevComment; + } + + public void Print (){ + if (prevComment == null){ + System.out.println(Text); + } else { + System.out.println(" " + Text); + } + if (nextComment != null) nextComment.Print(); + } + + public void PrintComment (){ + System.out.println(Text); + } +} diff --git a/AlexeySinyuk/src/Blog/User.java b/AlexeySinyuk/src/Blog/User.java new file mode 100644 index 0000000..cec8303 --- /dev/null +++ b/AlexeySinyuk/src/Blog/User.java @@ -0,0 +1,41 @@ +package Blog; + +import javafx.geometry.Pos; + +/** + * Created by asinuk on 16/02/2015. + */ +public class User { + + private String Name; + private String Surname; + private int Posts = 0; + + public User (String Name, String Surname){ + this.Name = Name; + this.Surname = Surname; + } + + public String getName(){ + return Name; + } + + public String getSurname(){ + return Surname; + } + + public int getPosts (){ + return Posts; + } + + int incPosts (){ + Posts++; + return Posts; + } + + int decPosts (){ + Posts--; + return Posts; + } + +} From 71ab343dadbe528a34c1aa0bbe4ab7bd6c1f56c7 Mon Sep 17 00:00:00 2001 From: Alexey Sinyuk Date: Mon, 16 Feb 2015 14:44:22 +0200 Subject: [PATCH 2/3] Changed Post.Print() --- AlexeySinyuk/src/Blog/MainClass.java | 6 +++--- AlexeySinyuk/src/Blog/Post.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AlexeySinyuk/src/Blog/MainClass.java b/AlexeySinyuk/src/Blog/MainClass.java index 0d3bcea..63ed81a 100644 --- a/AlexeySinyuk/src/Blog/MainClass.java +++ b/AlexeySinyuk/src/Blog/MainClass.java @@ -7,10 +7,10 @@ public abstract class MainClass { public static void main(String[] args) { - System.out.println("Hello!"); - User user1 = new User ("Alexey", "Sinyuk"); + User user1 = new User ("Ivan", "Ivanov"); + User user2 = new User ("Petro", "Petrov"); Post post1 = new Post ("Post1", user1, "coolstory psto"); - post1.addComment(user1, "Perviy ololo!"); + post1.addComment(user2, "Perviy ololo!"); post1.addComment(user1, "Vtoroy!"); post1.Print(); diff --git a/AlexeySinyuk/src/Blog/Post.java b/AlexeySinyuk/src/Blog/Post.java index 53f35a3..c14d9c7 100644 --- a/AlexeySinyuk/src/Blog/Post.java +++ b/AlexeySinyuk/src/Blog/Post.java @@ -107,14 +107,14 @@ public void Delete (){ public void Print (){ if (prevComment == null){ - System.out.println(Text); + System.out.println(Poster.getName() + " " + Poster.getSurname() + " : " + Text); } else { - System.out.println(" " + Text); + System.out.println(" " + Poster.getName() + " " + Poster.getSurname() + " : " + Text); } if (nextComment != null) nextComment.Print(); } public void PrintComment (){ - System.out.println(Text); + System.out.println(Poster.getName() + " " + Poster.getSurname() + " : " + Text); } } From 3e1ee52264f46126bd4ac9ebdf99a2718aab8872 Mon Sep 17 00:00:00 2001 From: Alexey Sinyuk Date: Thu, 19 Mar 2015 16:15:49 +0200 Subject: [PATCH 3/3] Changed case for method names. --- AlexeySinyuk/src/Blog/MainClass.java | 15 +---- AlexeySinyuk/src/Blog/Post.java | 98 +++++++--------------------- AlexeySinyuk/src/Blog/User.java | 34 +++++----- 3 files changed, 42 insertions(+), 105 deletions(-) diff --git a/AlexeySinyuk/src/Blog/MainClass.java b/AlexeySinyuk/src/Blog/MainClass.java index 63ed81a..26c9c14 100644 --- a/AlexeySinyuk/src/Blog/MainClass.java +++ b/AlexeySinyuk/src/Blog/MainClass.java @@ -1,23 +1,10 @@ package Blog; -/** - * Created by asinuk on 16/02/2015. - */ + public abstract class MainClass { public static void main(String[] args) { - User user1 = new User ("Ivan", "Ivanov"); - User user2 = new User ("Petro", "Petrov"); - Post post1 = new Post ("Post1", user1, "coolstory psto"); - post1.addComment(user2, "Perviy ololo!"); - post1.addComment(user1, "Vtoroy!"); - post1.Print(); - - post1.getComment(2).PrintComment(); - post1.getComment(1).Delete(); - post1.Print(); - } } diff --git a/AlexeySinyuk/src/Blog/Post.java b/AlexeySinyuk/src/Blog/Post.java index c14d9c7..f359a3a 100644 --- a/AlexeySinyuk/src/Blog/Post.java +++ b/AlexeySinyuk/src/Blog/Post.java @@ -1,120 +1,68 @@ package Blog; -/** - * Created by asinuk on 16/02/2015. - */ + public class Post { - private String Title; - protected User Poster; - protected String Text; - protected String Imgurl; + private String title; + protected User poster; + protected String text; + protected String imgurl; private Post prevComment; private Post nextComment; - public Post (String Title, User Poster, String Text){ - this.Title = Title; - this.Poster = Poster; - this.Text = Text; + public Post (String title, User poster, String text){ + this.title = title; + this.poster = poster; + this.text = text; Poster.incPosts(); } - public Post (String Title, User Poster, String Text, String Imgurl){ - this(Title, Poster, Text); - this.Imgurl = Imgurl; + public Post (String title, User poster, String text, String imgurl){ + this(title, poster, text); + this.imgurl = imgurl; Poster.incPosts(); } - private Post (Post prevComment, User Poster, String Text){ - this("", Poster, Text); - this.prevComment = prevComment; - } - - private Post (Post prevComment, User Poster, String Text, String Imgurl){ - this("", Poster, Text, Imgurl); - this.prevComment = prevComment; - } - public String getTitle (){ - return Title; + return title; } public User getPoster (){ - return Poster; + return poster; } public String getText (){ - return Text; + return text; } public String getImgurl () { - return Imgurl; + return imgurl; } - public void setText (String Text){ - this.Text = Text; + public void setText (String text){ + this.text = text; } - public void setImgurl (String Imgurl) { - this.Imgurl = Imgurl; + public void setImgurl (String imgurl) { + this.imgurl = imgurl; } - public void addComment (User Poster, String Text){ - if (nextComment == null) { - nextComment = new Post (this, Poster, Text); - } else { - nextComment.addComment(Poster, Text); - } - } + public void addComment (User poster, String text){ - public void addComment (User Poster, String Text, String Imgurl){ - if (nextComment == null) { - nextComment = new Post (this, Poster, Text, Imgurl); - } else { - nextComment.addComment(Poster, Text, Imgurl); - } } - public Post getComment (int id){ - //TODO exceptions - if (nextComment != null) { - return nextComment.getComment(id, 1); - } else { - return null; - } - } + public void addComment (User poster, String text, String imgurl){ - private Post getComment (int id, int depth){ - if (id == depth) { - return this; - } else { - if (nextComment != null) { - return nextComment.getComment(id, depth + 1); - } else { - return null; - } - } } public void Delete (){ - //TODO exceptions - prevComment.nextComment = nextComment; - nextComment.prevComment = prevComment; + } public void Print (){ - if (prevComment == null){ - System.out.println(Poster.getName() + " " + Poster.getSurname() + " : " + Text); - } else { - System.out.println(" " + Poster.getName() + " " + Poster.getSurname() + " : " + Text); - } - if (nextComment != null) nextComment.Print(); - } - public void PrintComment (){ - System.out.println(Poster.getName() + " " + Poster.getSurname() + " : " + Text); } } diff --git a/AlexeySinyuk/src/Blog/User.java b/AlexeySinyuk/src/Blog/User.java index cec8303..a25e151 100644 --- a/AlexeySinyuk/src/Blog/User.java +++ b/AlexeySinyuk/src/Blog/User.java @@ -2,40 +2,42 @@ import javafx.geometry.Pos; -/** - * Created by asinuk on 16/02/2015. - */ + public class User { - private String Name; - private String Surname; - private int Posts = 0; + private String name; + private String surname; + private int posts = 0; + private int comments = 0; - public User (String Name, String Surname){ - this.Name = Name; - this.Surname = Surname; + public User (String name, String surname){ + this.name = name; + this.surname = surname; } public String getName(){ - return Name; + return name; } public String getSurname(){ - return Surname; + return surname; } public int getPosts (){ - return Posts; + return posts; } int incPosts (){ - Posts++; - return Posts; + posts++; + return posts; } int decPosts (){ - Posts--; - return Posts; + posts--; + return posts; } + public int getCommentsNum() { + return comments; + } }