EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.kernel.se.dto.list]

COVERAGE SUMMARY FOR SOURCE FILE [DefaultAtom.java]

nameclass, %method, %block, %line, %
DefaultAtom.java100% (1/1)100% (11/11)100% (122/122)100% (26/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultAtom100% (1/1)100% (11/11)100% (122/122)100% (26/26)
DefaultAtom (String): void 100% (1/1)100% (13/13)100% (5/5)
copy (): Element 100% (1/1)100% (6/6)100% (1/1)
equals (Object): boolean 100% (1/1)100% (12/12)100% (3/3)
getAtom (): Atom 100% (1/1)100% (2/2)100% (1/1)
getList (): ElementList 100% (1/1)100% (26/26)100% (1/1)
getString (): String 100% (1/1)100% (3/3)100% (1/1)
hashCode (): int 100% (1/1)100% (4/4)100% (1/1)
isAtom (): boolean 100% (1/1)100% (2/2)100% (1/1)
isList (): boolean 100% (1/1)100% (2/2)100% (1/1)
replace (Element, Element): Element 100% (1/1)100% (10/10)100% (3/3)
toString (): String 100% (1/1)100% (42/42)100% (8/8)

1/* This file is part of the project "Hilbert II" - http://www.qedeq.org
2 *
3 * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4 *
5 * "Hilbert II" is free software; you can redistribute
6 * it and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 
16package org.qedeq.kernel.se.dto.list;
17 
18import org.qedeq.kernel.se.base.list.Atom;
19import org.qedeq.kernel.se.base.list.Element;
20import org.qedeq.kernel.se.base.list.ElementList;
21 
22 
23/**
24 * An object of this class represents a text string.
25 *
26 * @author  Michael Meyling
27 */
28public final class DefaultAtom implements Atom {
29 
30    /** The plain text. */
31    private final String text;
32 
33    /**
34     * Constructs an <code>Atom</code>.
35     *
36     * @param   text    Atom string.
37     * @throws  IllegalArgumentException    <code>text</code> is a NullPointer.
38     */
39    public DefaultAtom(final String text) {
40        if (text == null) {
41            throw new IllegalArgumentException("a NullPointer is no valid text");
42        }
43        this.text = text;
44    }
45 
46    public final String getString() {
47        return text;
48    }
49 
50    public final boolean isAtom() {
51        return true;
52    }
53 
54    public final Atom getAtom() {
55        return this;
56    }
57 
58    public final boolean isList() {
59        return false;
60    }
61 
62    public final ElementList getList() {
63        throw new ClassCastException("this is no " + ElementList.class.getName()
64            + ", but a " + this.getClass().getName());
65    }
66 
67    public final Element copy() {
68        return new DefaultAtom(text);
69    }
70 
71    public final Element replace(final Element search, final Element replacement) {
72        if (this.equals(search)) {
73            return replacement.copy();
74        }
75        return this.copy();
76    }
77 
78    public final String toString() {
79        StringBuffer result = new StringBuffer();
80        result.append("\"");
81 
82        for (int i = 0; i < text.length(); i++) {
83            if (text.charAt(i) == '\"') {
84                result.append("\"\"");
85            } else {
86                result.append(text.charAt(i));
87            }
88        }
89        result.append('\"');
90        return result.toString();
91 
92    }
93 
94    public final boolean equals(final Object object) {
95        if (object instanceof DefaultAtom) {
96            return ((DefaultAtom) object).text.equals(text);
97        }
98        return false;
99    }
100 
101    public final int hashCode() {
102        return toString().hashCode();
103    }
104 
105}

[all classes][org.qedeq.kernel.se.dto.list]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov