import java.util.HashMap;
import java.util.Map;
public final class Main {
public Main() {
map = new HashMap<>();
map.put('h', () -> moveCursorLeft());
map.put('j', () -> moveCursorUp());
map.put('k', () -> moveCursorDown());
map.put('l', () -> moveCursorRight());
}
public void handleKeyInput() {
var c = getPressedKey();
var action = map.get(c);
if (action == null) {
// Does nothing with keys not associated with actions.
return;
}
action.run();
}
/**
Returns the character of the pressed key.
If no key is pressed, blocks until any key is pressed.
@return
The character of the pressed key.
*/
private char getPressedKey() {
return 'a';
}
private void moveCursorRight() {}
private void moveCursorUp() {}
private void moveCursorDown() {}
private void moveCursorLeft() {}
public static void main
(String[] args
) { var m = new Main();
m.handleKeyInput();
}
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKCnB1YmxpYyBmaW5hbCBjbGFzcyBNYWluIHsKCiAgICBwcml2YXRlIGZpbmFsIE1hcDxDaGFyYWN0ZXIsIFJ1bm5hYmxlPiBtYXA7CgogICAgcHVibGljIE1haW4oKSB7CiAgICAgICAgbWFwID0gbmV3IEhhc2hNYXA8PigpOwogICAgICAgIG1hcC5wdXQoJ2gnLCAoKSAtPiBtb3ZlQ3Vyc29yTGVmdCgpKTsKICAgICAgICBtYXAucHV0KCdqJywgKCkgLT4gbW92ZUN1cnNvclVwKCkpOwogICAgICAgIG1hcC5wdXQoJ2snLCAoKSAtPiBtb3ZlQ3Vyc29yRG93bigpKTsKICAgICAgICBtYXAucHV0KCdsJywgKCkgLT4gbW92ZUN1cnNvclJpZ2h0KCkpOwogICAgfQoKICAgIHB1YmxpYyB2b2lkIGhhbmRsZUtleUlucHV0KCkgewogICAgICAgIHZhciBjID0gZ2V0UHJlc3NlZEtleSgpOwogICAgICAgIHZhciBhY3Rpb24gPSBtYXAuZ2V0KGMpOwogICAgICAgIGlmIChhY3Rpb24gPT0gbnVsbCkgewogICAgICAgICAgICAvLyBEb2VzIG5vdGhpbmcgd2l0aCBrZXlzIG5vdCBhc3NvY2lh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