gopher.sh: fix mktemp usage (6 'X's instead of 5?)
[gofetch.git] / src / be / nikiroo / gofetch / data / Comment.java
... / ...
CommitLineData
1package be.nikiroo.gofetch.data;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6
7public class Comment implements Iterable<Comment> {
8 private String id;
9 private String author;
10 private String title;
11 private String date;
12 private List<String> lines;
13 private List<Comment> children;
14
15 public Comment(String id, String author, String title, String date,
16 List<String> lines) {
17 this.id = id;
18 this.author = author;
19 this.title = title;
20 this.date = date;
21 this.lines = lines;
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 */
64 public List<String> getContentLines() {
65 return lines;
66 }
67
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
92 public boolean isEmpty() {
93 return children.isEmpty() && lines.isEmpty()
94 && ("" + author + title).isEmpty();
95 }
96
97 @Override
98 public Iterator<Comment> iterator() {
99 return children.iterator();
100 }
101}