1 package com.atlassian.bonnie.search.summary;
2
3 import java.util.ArrayList;
4
5
6
7
8
9
10 public class Summary {
11
12
13 public static class Fragment {
14 private String text;
15
16
17 public Fragment(String text) { this.text = text; }
18
19
20 public String getText() { return text; }
21
22
23 public boolean isHighlight() { return false; }
24
25
26 public boolean isEllipsis() { return false; }
27
28
29 public String toString() { return text; }
30
31 public boolean equals(Object o)
32 {
33 if (this == o) return true;
34 if (o == null || getClass() != o.getClass()) return false;
35
36 final Fragment fragment = (Fragment) o;
37
38 if (!text.equals(fragment.text)) return false;
39 if (isHighlight() != fragment.isHighlight()) return false;
40 if (isEllipsis() != fragment.isEllipsis()) return false;
41
42 return true;
43 }
44
45 public int hashCode()
46 {
47 return text.hashCode();
48 }
49 }
50
51
52 public static class Highlight extends Fragment {
53
54 public Highlight(String text) { super(text); }
55
56
57 public boolean isHighlight() { return true; }
58 }
59
60
61 public static class Ellipsis extends Fragment {
62
63 public Ellipsis() { super(" ... "); }
64
65
66 public boolean isEllipsis() { return true; }
67
68
69 public String toString() { return " ... "; }
70 }
71
72 private ArrayList fragments = new ArrayList();
73
74 private static final Fragment[] FRAGMENT_PROTO = new Fragment[0];
75
76
77 public Summary() {}
78
79
80 public void add(Fragment fragment) { fragments.add(fragment); }
81
82
83 public Fragment[] getFragments() {
84 return (Fragment[])fragments.toArray(FRAGMENT_PROTO);
85 }
86
87
88 public String toString() {
89 StringBuffer buffer = new StringBuffer();
90 for (int i = 0; i < fragments.size(); i++) {
91 buffer.append(fragments.get(i));
92 }
93 return buffer.toString();
94 }
95
96
97 }