added some comments
This commit is contained in:
@@ -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<JodelPost> comments = new Vector<>();
|
||||
// the own reaction (null = none, true = positive, false = negative)
|
||||
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) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user