Message.java

1
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
2
// Copyright © 2012 various contributors
3
// This software is released under GNU Lesser General Public License 2.1.
4
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html
5
package fi.helsinki.cs.titokone;
6
7
/**
8
 * This class represents a translatable message to the user. It uses
9
 * the Translator class statically to deal with the actual translation.
10
 */
11
public class Message {
12
    private String messageKey;
13
    private String[] parameters;
14
15
    /**
16
     * This constructor sets up a static message.
17
     *
18
     * @param messageKey The identifying key, possibly equal to the default
19
     *                   English message. The value is used to find the translation.
20
     */
21
    public Message(String messageKey) {
22 1
        this.messageKey = messageKey;
23 1
        parameters = null;
24
    }
25
26
    /**
27
     * This constructor sets up a message with modifiable parts, and sets
28
     * what they will be replaced with.
29
     *
30
     * @param templateKey The identifying key, possibly equal to the default
31
     *                    English message. The value is used to find the translation.
32
     * @param parameter   The value to replace a {0} marker in the template
33
     *                    message.
34
     */
35
    public Message(String templateKey, String parameter) {
36
        this(templateKey);
37 3
        parameters = new String[1];
38 2
        parameters[0] = parameter;
39
    }
40
41
    /**
42
     * This constructor sets up a message with modifiable parts, and sets
43
     * what they will be replaced with.
44
     *
45
     * @param templateKey The identifying key, possibly equal to the default
46
     *                    English message. The value is used to find the translation.
47
     * @param parameters  The values to replace {i} markers in the template
48
     *                    message in order. If there are less strings in the array than there
49
     *                    are markers, the remaining markers will show as such in the
50
     *                    resulting string. If there are more strings in the array than are
51
     *                    needed, the final ones are ignored.
52
     */
53
    public Message(String templateKey, String[] parameters) {
54
        this(templateKey);
55 1
        this.parameters = parameters;
56
    }
57
58
    /**
59
     * This method translates the message and does any necessary
60
     * replacement of parameters into the string itself. The translated
61
     * message is formed over for each time toString() is called;
62
     * if the locale is changed between two calls to the toString() of
63
     * the same instance of Message, the results may be different. See
64
     * Translator for details.
65
     *
66
     * @return The translated string.
67
     */
68
    public String toString() {
69 1
        if (parameters == null) {
70 2
            return Translator.translate(messageKey);
71
        } else {
72 2
            return Translator.translate(messageKey, parameters);
73
        }
74
    }
75
}

Mutations

22

Removed assignment to member variable messageKey : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

23

Removed assignment to member variable parameters : SURVIVED

37

Removed assignment to member variable parameters : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

Substituted 1 with 0 : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

Substituted 1 with 0 : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

38

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

Substituted 0 with 1 : KILLED -> fi.helsinki.cs.titokone.ApplicationTest.testStdInputBuffer(fi.helsinki.cs.titokone.ApplicationTest)

55

Removed assignment to member variable parameters : KILLED -> fi.helsinki.cs.titokone.SettingsTest.testParse(fi.helsinki.cs.titokone.SettingsTest)

69

negated conditional : KILLED -> fi.helsinki.cs.titokone.SettingsTest.testParse(fi.helsinki.cs.titokone.SettingsTest)

70

mutated return of Object value for fi/helsinki/cs/titokone/Message::toString to ( if (x != null) null else throw new RuntimeException ) : KILLED -> fi.helsinki.cs.titokone.BinaryTest.testBinary(fi.helsinki.cs.titokone.BinaryTest)

removed call to fi/helsinki/cs/titokone/Translator::translate : KILLED -> fi.helsinki.cs.titokone.BinaryTest.testBinary(fi.helsinki.cs.titokone.BinaryTest)

72

removed call to fi/helsinki/cs/titokone/Translator::translate : KILLED -> fi.helsinki.cs.titokone.SettingsTest.testParse(fi.helsinki.cs.titokone.SettingsTest)

mutated return of Object value for fi/helsinki/cs/titokone/Message::toString to ( if (x != null) null else throw new RuntimeException ) : KILLED -> fi.helsinki.cs.titokone.SettingsTest.testParse(fi.helsinki.cs.titokone.SettingsTest)

Active mutators

Tests examined


Report generated by PIT 0.27