1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.document;
17
18 import net.sf.eos.Metadata;
19 import net.sf.eos.util.EqualsAndHashUtil;
20
21 import java.io.IOException;
22 import java.io.StringWriter;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33 public final class EosDocument implements Metadata {
34
35
36 @SuppressWarnings("nls")
37 public final static String YEAR_META_KEY = "EosDocument/date";
38
39
40 @SuppressWarnings("nls")
41 public final static String CREATOR_META_KEY = "EosDocument/creator";
42
43
44 @SuppressWarnings("nls")
45 public final static String ID_META_KEY = "EosDocument/id";
46
47 private CharSequence text;
48 private CharSequence title;
49 private Map<String, List<String>> meta =
50 new HashMap<String, List<String>>();
51
52
53
54 public CharSequence getText() {
55 return this.text;
56 }
57
58
59 public CharSequence getTitle() {
60 return this.title;
61 }
62
63
64 public Map<String, List<String>> getMeta() {
65 return this.meta;
66 }
67
68
69 public void setText(@SuppressWarnings("hiding") final CharSequence text) {
70 this.text = text;
71 }
72
73
74 public void setTitle(@SuppressWarnings("hiding") final CharSequence title) {
75 this.title = title;
76 }
77
78
79 public void setMeta(
80 @SuppressWarnings("hiding") final Map<String, List<String>> meta) {
81 this.meta = meta;
82 }
83
84
85
86
87
88
89
90 @Override
91 @SuppressWarnings("nls")
92 public String toString() {
93 final StringWriter writer = new StringWriter();
94 final XmlSerializer serializer = new XmlSerializer();
95 final StringBuffer sb = new StringBuffer("EosDocument[");
96 try {
97 serializer.serialize(this, writer);
98 sb.append(writer.toString());
99 sb.append("]");
100 } catch (final IOException e) {
101 sb.append("throws IOException:");
102 sb.append(e.getMessage());
103 sb.append("]");
104 }
105
106 return sb.toString();
107 }
108
109
110
111
112 @Override
113 public boolean equals(final Object other) {
114 if (other == null) {
115 return false;
116 }
117 if (! (other instanceof EosDocument)) {
118 return false;
119 }
120 final EosDocument doc = (EosDocument) other;
121 return EqualsAndHashUtil.isEqual(this.text, doc.text)
122 && EqualsAndHashUtil.isEqual(this.title, doc.title)
123 && EqualsAndHashUtil.isEqual(this.meta, doc.meta);
124 }
125
126
127
128
129
130 @Override
131 public int hashCode() {
132 int hash = EqualsAndHashUtil.hash(this.text);
133 hash *= EqualsAndHashUtil.hash(this.title);
134 hash *= EqualsAndHashUtil.hash(this.meta);
135 return hash;
136 }
137 }