From 3def245e5506fead4b35f9d2f1c0b582fb747e0e Mon Sep 17 00:00:00 2001 From: Timo Date: Thu, 23 May 2024 14:38:57 +0200 Subject: [PATCH] added some comments --- .../de/anxietyprime/swajodel/JodelPost.java | 27 +++++++++++++++---- .../java/de/anxietyprime/swajodel/Routes.java | 4 ++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/anxietyprime/swajodel/JodelPost.java b/src/main/java/de/anxietyprime/swajodel/JodelPost.java index af938bc..5bd7367 100644 --- a/src/main/java/de/anxietyprime/swajodel/JodelPost.java +++ b/src/main/java/de/anxietyprime/swajodel/JodelPost.java @@ -5,38 +5,55 @@ import java.util.Optional; import java.util.Vector; public class JodelPost { + // id of the post private Long id; + // id of the author in db private Long authorID; + // anonymized authorID public Long anonymousID; + // title of the post public String title; + // content of the post public String content; + // date of the post public Date date; + // location if the post public Location location; + // list of all comments for the post public Vector comments = new Vector<>(); + // the own reaction (null = none, true = positive, false = negative) public Optional reaction; - public Reaction[] reactions; + // all other reactions + public Reaction reactions; + // anonymize function to recursively anonymize the posts public void anonymize(Optional> idCache) { + // check if this is the first post in this process if (idCache.isEmpty()) { + // create a new Vector as cache idCache = Optional.of(new Vector()); } - System.out.println(idCache); + // get the anonymized id as index in cached authorIDs int i = idCache.get().indexOf(this.authorID); + // if the index is -1 the authorID has not been cached jet if (i == -1) { + // set the current anonymousID as length of the cache (== next index) this.anonymousID = (long) idCache.get().size(); + // push the current authorID to to cache idCache.get().add(this.authorID); } - else { - this.anonymousID = (long) i; - } + // the authorID has been anonymized once before, so we can get it from cache + else this.anonymousID = (long) i; + // recursively apply this algorithm for all comments, but include the idCache for (JodelPost comment : this.comments) { comment.anonymize(idCache); } } + // TODO: create constructor public JodelPost(long id) { this.authorID = id; } diff --git a/src/main/java/de/anxietyprime/swajodel/Routes.java b/src/main/java/de/anxietyprime/swajodel/Routes.java index 0db8ab4..1296363 100644 --- a/src/main/java/de/anxietyprime/swajodel/Routes.java +++ b/src/main/java/de/anxietyprime/swajodel/Routes.java @@ -11,10 +11,12 @@ public class Routes { @GetMapping("") public JodelPost test() { + // TODO: remove dec post JodelPost post = new JodelPost(100); + // calculate anonymous IDs for the post post.anonymize(Optional.empty()); - + // return the post return post; }