added some comments
This commit is contained in:
@@ -5,38 +5,55 @@ import java.util.Optional;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class JodelPost {
|
public class JodelPost {
|
||||||
|
// id of the post
|
||||||
private Long id;
|
private Long id;
|
||||||
|
// id of the author in db
|
||||||
private Long authorID;
|
private Long authorID;
|
||||||
|
|
||||||
|
// anonymized authorID
|
||||||
public Long anonymousID;
|
public Long anonymousID;
|
||||||
|
// title of the post
|
||||||
public String title;
|
public String title;
|
||||||
|
// content of the post
|
||||||
public String content;
|
public String content;
|
||||||
|
// date of the post
|
||||||
public Date date;
|
public Date date;
|
||||||
|
// location if the post
|
||||||
public Location location;
|
public Location location;
|
||||||
|
// list of all comments for the post
|
||||||
public Vector<JodelPost> comments = new Vector<>();
|
public Vector<JodelPost> comments = new Vector<>();
|
||||||
|
// the own reaction (null = none, true = positive, false = negative)
|
||||||
public Optional<Boolean> reaction;
|
public Optional<Boolean> reaction;
|
||||||
public Reaction[] reactions;
|
// all other reactions
|
||||||
|
public Reaction reactions;
|
||||||
|
|
||||||
|
// anonymize function to recursively anonymize the posts
|
||||||
public void anonymize(Optional<Vector<Long>> idCache) {
|
public void anonymize(Optional<Vector<Long>> idCache) {
|
||||||
|
// check if this is the first post in this process
|
||||||
if (idCache.isEmpty()) {
|
if (idCache.isEmpty()) {
|
||||||
|
// create a new Vector as cache
|
||||||
idCache = Optional.of(new Vector());
|
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);
|
int i = idCache.get().indexOf(this.authorID);
|
||||||
|
// if the index is -1 the authorID has not been cached jet
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
|
// set the current anonymousID as length of the cache (== next index)
|
||||||
this.anonymousID = (long) idCache.get().size();
|
this.anonymousID = (long) idCache.get().size();
|
||||||
|
// push the current authorID to to cache
|
||||||
idCache.get().add(this.authorID);
|
idCache.get().add(this.authorID);
|
||||||
}
|
}
|
||||||
else {
|
// the authorID has been anonymized once before, so we can get it from cache
|
||||||
this.anonymousID = (long) i;
|
else this.anonymousID = (long) i;
|
||||||
}
|
|
||||||
|
|
||||||
|
// recursively apply this algorithm for all comments, but include the idCache
|
||||||
for (JodelPost comment : this.comments) {
|
for (JodelPost comment : this.comments) {
|
||||||
comment.anonymize(idCache);
|
comment.anonymize(idCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: create constructor
|
||||||
public JodelPost(long id) {
|
public JodelPost(long id) {
|
||||||
this.authorID = id;
|
this.authorID = id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ public class Routes {
|
|||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public JodelPost test() {
|
public JodelPost test() {
|
||||||
|
// TODO: remove dec post
|
||||||
JodelPost post = new JodelPost(100);
|
JodelPost post = new JodelPost(100);
|
||||||
|
|
||||||
|
// calculate anonymous IDs for the post
|
||||||
post.anonymize(Optional.empty());
|
post.anonymize(Optional.empty());
|
||||||
|
// return the post
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user