We have two lists one is of type Question and the other of type Tag.
The Question class has those attributes
private String id;
private String header;
private String content;
private List<Tag> tags;
private Long timeStamp;
The Question list has all questions in it and the Tag list has all tags in it. We wanna check if One question contains any tag of the tag list. I want to do this for all questions.
With question.getTags, I get the list of tags.
The Tag class has an attribute called counter.
I will give some pseudocode to actually show you what I wanna do
List<Tag> allTags = ...
List<Question> allQuestions = ...
Map<Tag,Integer> map = new Hashmap<>();
if(one question contains any tag of allTags) {
tag.setCounter(counter+1);
map.put(tag,tag.getCounter);
}
In the end I wanna have a map where the key is the tag and the value the counter of that tag.
How can I actually do this?
EDIT here is my Tag.java
@NoArgsConstructor
@Data
@Getter
@AllArgsConstructor
@Setter
@Document(collection = "tag")
public class Tag {
private String id;
private String name;
private Long timeStamp;
public Tag(String name) {
this.id = UUID.randomUUID().toString();
this.name = name;
this.timeStamp = Instant.now().getEpochSecond()*1000;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tag tag = (Tag) o;
return Objects.equals(getId(), tag.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
}