import java.util.HashMap;
import java.util.Map;
public final class Main {
public Main() {
map = new HashMap<>();
map.put('h', () -> moveCursorLeft());
map.put('j', () -> moveCursorDown());
map.put('k', () -> moveCursorUp());
map.put('l', () -> moveCursorRight());
}
public void handleKeyInput() {
var c = getPressedKey();
var action = map.get(c);
// Since 'action' can be null, the next statement may throw
// a NullPointerException.
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 moveCursorLeft() {}
private void moveCursorDown() {}
private void moveCursorUp() {}
private void moveCursorRight() {}
public static void main
(String[] args
) { var m = new Main();
m.handleKeyInput();
}
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKCnB1YmxpYyBmaW5hbCBjbGFzcyBNYWluIHsKCiAgICBwcml2YXRlIGZpbmFsIE1hcDxDaGFyYWN0ZXIsIFJ1bm5hYmxlPiBtYXA7CgogICAgcHVibGljIE1haW4oKSB7CiAgICAgICAgbWFwID0gbmV3IEhhc2hNYXA8PigpOwogICAgICAgIG1hcC5wdXQoJ2gnLCAoKSAtPiBtb3ZlQ3Vyc29yTGVmdCgpKTsKICAgICAgICBtYXAucHV0KCdqJywgKCkgLT4gbW92ZUN1cnNvckRvd24oKSk7CiAgICAgICAgbWFwLnB1dCgnaycsICgpIC0+IG1vdmVDdXJzb3JVcCgpKTsKICAgICAgICBtYXAucHV0KCdsJywgKCkgLT4gbW92ZUN1cnNvclJpZ2h0KCkpOwogICAgfQoKICAgIHB1YmxpYyB2b2lkIGhhbmRsZUtleUlucHV0KCkgewogICAgICAgIHZhciBjID0gZ2V0UHJlc3NlZEtleSgpOwogICAgICAgIHZhciBhY3Rpb24gPSBtYXAuZ2V0KGMpOwogICAgICAgIC8vIFNpbmNlICdhY3Rpb24nIGNhbiBiZSBudWxsLCB0aGUgbmV4dCBzdGF0ZW1lbnQgbWF5IHRocm93CiAgICAgICAgLy8gY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