added get path

This commit is contained in:
2024-05-24 23:10:46 +02:00
parent 0ac475a7d7
commit 958425feef
2 changed files with 132 additions and 16 deletions

View File

@@ -6,10 +6,9 @@ import java.util.Vector;
public class JodelPost {
// id of the post
private Long id;
public Long id;
// id of the author in db
private Long authorID;
// anonymized authorID
public Long anonymousID;
// title of the post
@@ -53,8 +52,26 @@ public class JodelPost {
}
}
// TODO: create constructor
public JodelPost(long id) {
this.authorID = id;
// add a comment if it is really a comment
public boolean addComment(JodelPost post, long parent) {
// check if the post a direct comment
if (parent == this.id) {
// add the comment
this.comments.add(post);
// return success
return true;
}
// recursively repeat this for all comments
for (JodelPost comment : this.comments) {
// return success if the post is a comment on a child
if (comment.addComment(post, parent)) return true;
}
// return no success
return false;
}
// constructor with private authorID
public JodelPost(long authorID) {
this.authorID = authorID;
}
}