import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.
util.
Map.
entry;
public final class Main {
private static final Map
<String, Runnable
> COMMAND_MAP
= Map.
ofEntries( entry("help", () -> printHelp()),
entry("quit", () -> exitProgram()),
entry("shutdown", () -> shutdownSystem()));
private static void printHelp() {
System.
out.
println("printHelp"); }
private static void exitProgram() {
System.
out.
println("exitProgram"); }
private static void shutdownSystem() {
System.
out.
println("shutdownSystem"); }
private static List<String> getCommandList() {
return List.
of("help",
"reboot",
"shutdown"); }
private static void fixMe() {
var list = getCommandList().stream()
// Defers disposition of 'null' when 'Map#get(Object)' returns
// 'null'
.map(COMMAND_MAP::get)
// The next statement is equivalent to '.filter(Objects::nonNull)'
.filter(r -> r != null)
.collect(Collectors.toList());
list.forEach(r -> r.run());
}
public static void main
(String[] args
) { fixMe();
}
}
aW1wb3J0IGphdmEudXRpbC5MaXN0OwppbXBvcnQgamF2YS51dGlsLk1hcDsKaW1wb3J0IGphdmEudXRpbC5zdHJlYW0uQ29sbGVjdG9yczsKaW1wb3J0IHN0YXRpYyBqYXZhLnV0aWwuTWFwLmVudHJ5OwoKcHVibGljIGZpbmFsIGNsYXNzIE1haW4gewoKICAgIHByaXZhdGUgc3RhdGljIGZpbmFsIE1hcDxTdHJpbmcsIFJ1bm5hYmxlPiBDT01NQU5EX01BUCA9IE1hcC5vZkVudHJpZXMoCiAgICAgICAgICAgIGVudHJ5KCJoZWxwIiwgKCkgLT4gcHJpbnRIZWxwKCkpLAogICAgICAgICAgICBlbnRyeSgicXVpdCIsICgpIC0+IGV4aXRQcm9ncmFtKCkpLAogICAgICAgICAgICBlbnRyeSgic2h1dGRvd24iLCAoKSAtPiBzaHV0ZG93blN5c3RlbSgpKSk7CgogICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBwcmludEhlbHAoKSB7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJwcmludEhlbHAiKTsKICAgIH0KCiAgICBwcml2YXRlIHN0YXRpYyB2b2lkIGV4aXRQcm9ncmFtKCkgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiZXhpdFByb2dyYW0iKTsKICAgIH0KCiAgICBwcml2YXRlIHN0YXRpYyB2b2lkIHNodXRkb3duU3lzdGVtKCkgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigic2h1dGRvd25TeXN0ZW0iKTsKICAgIH0KCiAgICBwcml2YXRlIHN0YXRpYyBMaXN0PFN0cmluZz4gZ2V0Q29tbWFuZExpc3QoKSB7CiAgICAgICAgcmV0dXJuIExpc3Qub2YoImhlbHAiLCAicmVib290IiwgInNodXRkb3duIik7CiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBmaXhNZSgpIHsKICAgICAgICB2YXIgbGlzdCA9IGdldENvbW1hbmRMaXN0KCkuc3RyZWFtKCkKICAgICAgICAgICAgLy8gRGVmZXJzIGRpc3Bvc2l0aW9uIG9mICdudWxsJyB3aGVuICdNYXAjZ2V0KE9iamVjdCknIHJldHVybnMKICAgICAgICAgICAgLy8gJ251bGwnCiAgICAgICAgICAgIC5tYXAoQ09NTUFORF9NQVA6OmdldCkKICAgICAgICAgICAgLy8gVGhlIG5leHQgc3RhdGVtZW50IGlzIGVxdWl2YWxlbnQgdG8gJy5maWx0ZXIoT2JqZWN0czo6bm9uTnVsbCknCiAgICAgICAgICAgIC5maWx0ZXIociAtPiByICE9IG51bGwpCiAgICAgICAgICAgIC5jb2xsZWN0KENvbGxlY3RvcnMudG9MaXN0KCkpOwogICAgICAgIGxpc3QuZm9yRWFjaChyIC0+IHIucnVuKCkpOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBmaXhNZSgpOwogICAgfQp9Cg==