Commit | Line | Data |
---|---|---|
73785268 NR |
1 | package be.nikiroo.gofetch.data; |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Iterator; | |
5 | import java.util.List; | |
6 | ||
7 | public class Comment implements Iterable<Comment> { | |
8 | private String id; | |
9 | private String author; | |
10 | private String title; | |
11 | private String date; | |
27008a87 | 12 | private List<String> lines; |
73785268 NR |
13 | private List<Comment> children; |
14 | ||
15 | public Comment(String id, String author, String title, String date, | |
27008a87 | 16 | List<String> lines) { |
73785268 NR |
17 | this.id = id; |
18 | this.author = author; | |
19 | this.title = title; | |
20 | this.date = date; | |
27008a87 | 21 | this.lines = lines; |
73785268 NR |
22 | this.children = new ArrayList<Comment>(); |
23 | } | |
24 | ||
25 | public void add(Comment comment) { | |
26 | children.add(comment); | |
27 | } | |
28 | ||
29 | public void addAll(List<Comment> comments) { | |
30 | children.addAll(comments); | |
31 | } | |
32 | ||
33 | /** | |
34 | * @return the id | |
35 | */ | |
36 | public String getId() { | |
37 | return id; | |
38 | } | |
39 | ||
40 | /** | |
41 | * @return the author | |
42 | */ | |
43 | public String getAuthor() { | |
44 | return author; | |
45 | } | |
46 | ||
47 | /** | |
48 | * @return the title | |
49 | */ | |
50 | public String getTitle() { | |
51 | return title; | |
52 | } | |
53 | ||
54 | /** | |
55 | * @return the date | |
56 | */ | |
57 | public String getDate() { | |
58 | return date; | |
59 | } | |
60 | ||
61 | /** | |
62 | * @return the content | |
63 | */ | |
27008a87 NR |
64 | public List<String> getContentLines() { |
65 | return lines; | |
73785268 NR |
66 | } |
67 | ||
72f39832 NR |
68 | /** |
69 | * Find a comment or sub-comment by its id. | |
70 | * | |
71 | * @param id | |
72 | * the id to look for F | |
73 | * @return this if it has the given id, or a child of this if the child have | |
74 | * the given id, or NULL if not | |
75 | */ | |
76 | public Comment getById(String id) { | |
77 | if (id != null) { | |
78 | if (id.equals(this.id)) { | |
79 | return this; | |
80 | } | |
81 | ||
82 | for (Comment subComment : this) { | |
83 | if (id.equals(subComment.getId())) { | |
84 | return subComment; | |
85 | } | |
86 | } | |
87 | } | |
88 | ||
89 | return null; | |
90 | } | |
91 | ||
73785268 | 92 | public boolean isEmpty() { |
27008a87 | 93 | return children.isEmpty() && lines.isEmpty() |
3e62b034 | 94 | && ("" + author + title).isEmpty(); |
73785268 NR |
95 | } |
96 | ||
97 | @Override | |
98 | public Iterator<Comment> iterator() { | |
99 | return children.iterator(); | |
100 | } | |
101 | } |