|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.dto.list; |
|
19 |
| |
|
20 |
| import org.qedeq.kernel.base.list.Atom; |
|
21 |
| import org.qedeq.kernel.base.list.Element; |
|
22 |
| import org.qedeq.kernel.base.list.ElementList; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public final class AtomImpl implements Atom { |
|
32 |
| |
|
33 |
| |
|
34 |
| private final String text; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
8944
| public AtomImpl(final String text) {
|
|
43 |
8944
| if (text == null) {
|
|
44 |
0
| throw new IllegalArgumentException("a NullPointer is no valid text");
|
|
45 |
| } |
|
46 |
8944
| this.text = text;
|
|
47 |
| } |
|
48 |
| |
|
49 |
19293
| public final String getString() {
|
|
50 |
19293
| return text;
|
|
51 |
| } |
|
52 |
| |
|
53 |
10307
| public final boolean isAtom() {
|
|
54 |
10307
| return true;
|
|
55 |
| } |
|
56 |
| |
|
57 |
14050
| public final Atom getAtom() {
|
|
58 |
14050
| return this;
|
|
59 |
| } |
|
60 |
| |
|
61 |
16982
| public final boolean isList() {
|
|
62 |
16982
| return false;
|
|
63 |
| } |
|
64 |
| |
|
65 |
0
| public final ElementList getList() {
|
|
66 |
0
| throw new ClassCastException("this is no " + ElementList.class.getName()
|
|
67 |
| + ", but a " + this.getClass().getName()); |
|
68 |
| } |
|
69 |
| |
|
70 |
3836
| public final Element copy() {
|
|
71 |
3836
| return new AtomImpl(text);
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| public final Element replace(final Element search, final Element replacement) {
|
|
75 |
0
| if (this.equals(search)) {
|
|
76 |
0
| return replacement.copy();
|
|
77 |
| } |
|
78 |
0
| return this.copy();
|
|
79 |
| } |
|
80 |
| |
|
81 |
42269
| public final String toString() {
|
|
82 |
42269
| StringBuffer result = new StringBuffer();
|
|
83 |
42269
| result.append("\"");
|
|
84 |
| |
|
85 |
42269
| for (int i = 0; i < text.length(); i++) {
|
|
86 |
103621
| if (text.charAt(i) == '\"') {
|
|
87 |
0
| result.append("\"\"");
|
|
88 |
| } else { |
|
89 |
103621
| result.append(text.charAt(i));
|
|
90 |
| } |
|
91 |
| } |
|
92 |
42269
| result.append('\"');
|
|
93 |
42269
| return result.toString();
|
|
94 |
| |
|
95 |
| } |
|
96 |
| |
|
97 |
2236
| public final boolean equals(final Object object) {
|
|
98 |
2236
| if (object instanceof AtomImpl) {
|
|
99 |
2229
| return ((AtomImpl) object).text.equals(text);
|
|
100 |
| } |
|
101 |
7
| return false;
|
|
102 |
| } |
|
103 |
| |
|
104 |
453
| public final int hashCode() {
|
|
105 |
453
| return toString().hashCode();
|
|
106 |
| } |
|
107 |
| |
|
108 |
| } |