LanternaKeyboard.java

1
package g0803.bindingofshiba.gui.keyboard;
2
3
import com.googlecode.lanterna.input.InputProvider;
4
import com.googlecode.lanterna.input.KeyStroke;
5
import com.googlecode.lanterna.input.KeyType;
6
import java.io.IOException;
7
8
public class LanternaKeyboard implements Keyboard {
9
10
    private final InputProvider inputProvider;
11
    private boolean isClosed = false;
12
13
    private Key lastKeyPressed = Key.NONE;
14
    private long lastKeyPressStart = System.currentTimeMillis();
15
16
    public LanternaKeyboard(InputProvider inputProvider) {
17
        this.inputProvider = inputProvider;
18
    }
19
20
    @Override
21
    public boolean isKeyPressed(Key key) {
22 2 1. isKeyPressed : negated conditional → KILLED
2. isKeyPressed : replaced boolean return with true for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isKeyPressed → KILLED
        return this.lastKeyPressed == key;
23
    }
24
25
    @Override
26
    public Key getPressedKey() {
27 1 1. getPressedKey : replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getPressedKey → NO_COVERAGE
        return lastKeyPressed;
28
    }
29
30
    @Override
31
    public long getKeyPressDuration() {
32 2 1. getKeyPressDuration : Replaced long subtraction with addition → KILLED
2. getKeyPressDuration : replaced long return with 0 for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getKeyPressDuration → KILLED
        return System.currentTimeMillis() - this.lastKeyPressStart;
33
    }
34
35
    @Override
36
    public boolean isClosed() {
37 2 1. isClosed : replaced boolean return with false for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isClosed → KILLED
2. isClosed : replaced boolean return with true for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isClosed → KILLED
        return isClosed;
38
    }
39
40
    @Override
41
    public void update() throws IOException {
42 1 1. update : negated conditional → KILLED
        if (this.isClosed) return;
43
44
        KeyStroke keyStroke = this.getLastKeyStroke();
45 2 1. update : negated conditional → KILLED
2. update : negated conditional → KILLED
        if (keyStroke != null && keyStroke.getKeyType() == KeyType.EOF) this.isClosed = true;
46
47
        Key currentKey = getCurrentKeyFromKeyStroke(keyStroke);
48 1 1. update : negated conditional → KILLED
        if (this.lastKeyPressed != currentKey) {
49
            this.lastKeyPressStart = System.currentTimeMillis();
50
            this.lastKeyPressed = currentKey;
51
        }
52
    }
53
54
    private KeyStroke getLastKeyStroke() throws IOException {
55
        KeyStroke lastKeyStroke = null;
56
57
        KeyStroke currentKeyStroke;
58 1 1. getLastKeyStroke : negated conditional → KILLED
        while ((currentKeyStroke = this.inputProvider.pollInput()) != null) {
59
            lastKeyStroke = currentKeyStroke;
60 1 1. getLastKeyStroke : negated conditional → KILLED
            if (lastKeyStroke.getKeyType() == KeyType.EOF) break;
61
        }
62
63 1 1. getLastKeyStroke : replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getLastKeyStroke → KILLED
        return lastKeyStroke;
64
    }
65
66
    private Key getCurrentKeyFromKeyStroke(KeyStroke keyStroke) {
67 2 1. getCurrentKeyFromKeyStroke : negated conditional → KILLED
2. getCurrentKeyFromKeyStroke : replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromKeyStroke → KILLED
        if (keyStroke == null) return Key.NONE;
68
69
        KeyType keyType = keyStroke.getKeyType();
70
71 1 1. getCurrentKeyFromKeyStroke : replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromKeyStroke → KILLED
        return switch (keyType) {
72
            case ArrowUp -> Key.ARROW_UP;
73
            case ArrowDown -> Key.ARROW_DOWN;
74
            case ArrowLeft -> Key.ARROW_LEFT;
75
            case ArrowRight -> Key.ARROW_RIGHT;
76
            case Enter -> Key.ENTER;
77
            case Escape -> Key.ESCAPE;
78
            case Character -> this.getCurrentKeyFromCharacter(keyStroke.getCharacter());
79
            default -> Key.NONE;
80
        };
81
    }
82
83
    private Key getCurrentKeyFromCharacter(Character character) {
84 1 1. getCurrentKeyFromCharacter : replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromCharacter → KILLED
        return switch (Character.toUpperCase(character)) {
85
            case 'W' -> Key.W;
86
            case 'A' -> Key.A;
87
            case 'S' -> Key.S;
88
            case 'D' -> Key.D;
89
            case ' ' -> Key.SPACE;
90
            default -> Key.NONE;
91
        };
92
    }
93
}

Mutations

22

1.1
Location : isKeyPressed
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:ignoresUnrecognizedKeyStrokes()]
negated conditional → KILLED

2.2
Location : isKeyPressed
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:ignoresUnrecognizedKeyStrokes()]
replaced boolean return with true for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isKeyPressed → KILLED

27

1.1
Location : getPressedKey
Killed by : none
replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getPressedKey → NO_COVERAGE

32

1.1
Location : getKeyPressDuration
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:getKeyPressDuration()]
Replaced long subtraction with addition → KILLED

2.2
Location : getKeyPressDuration
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:getKeyPressDuration()]
replaced long return with 0 for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getKeyPressDuration → KILLED

37

1.1
Location : isClosed
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:closesAtEOF()]
replaced boolean return with false for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isClosed → KILLED

2.2
Location : isClosed
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:doesNotCloseIfNotEOF()]
replaced boolean return with true for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::isClosed → KILLED

42

1.1
Location : update
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesKeyPress()]
negated conditional → KILLED

45

1.1
Location : update
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:readsUntilNull()]
negated conditional → KILLED

2.2
Location : update
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:readsUntilNull()]
negated conditional → KILLED

48

1.1
Location : update
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesKeyPress()]
negated conditional → KILLED

58

1.1
Location : getLastKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesKeyPress()]
negated conditional → KILLED

60

1.1
Location : getLastKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesLastKeyPress()]
negated conditional → KILLED

63

1.1
Location : getLastKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesKeyPress()]
replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getLastKeyStroke → KILLED

67

1.1
Location : getCurrentKeyFromKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:storesKeyPress()]
negated conditional → KILLED

2.2
Location : getCurrentKeyFromKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:readsUntilNull()]
replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromKeyStroke → KILLED

71

1.1
Location : getCurrentKeyFromKeyStroke
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:ignoresUnrecognizedKeyStrokes()]
replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromKeyStroke → KILLED

84

1.1
Location : getCurrentKeyFromCharacter
Killed by : g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.gui.keyboard.LanternaKeyboardTest]/[method:ignoresUnrecognizedKeyStrokes()]
replaced return value with null for g0803/bindingofshiba/gui/keyboard/LanternaKeyboard::getCurrentKeyFromCharacter → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.0