diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Command.java')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Command.java | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Command.java b/app/src/main/java/org/pacien/tincapp/commands/Command.java deleted file mode 100644 index 28ff226..0000000 --- a/app/src/main/java/org/pacien/tincapp/commands/Command.java +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | package org.pacien.tincapp.commands; | ||
2 | |||
3 | import com.annimon.stream.Collectors; | ||
4 | import com.annimon.stream.Optional; | ||
5 | import com.annimon.stream.Stream; | ||
6 | |||
7 | import java.util.Arrays; | ||
8 | import java.util.Collections; | ||
9 | import java.util.LinkedList; | ||
10 | import java.util.List; | ||
11 | |||
12 | /** | ||
13 | * @author pacien | ||
14 | */ | ||
15 | class Command { | ||
16 | |||
17 | static private class Option { | ||
18 | final String key; | ||
19 | final Optional<java.lang.String> val; | ||
20 | |||
21 | Option(String key, String val) { | ||
22 | this.key = key; | ||
23 | this.val = Optional.ofNullable(val); | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public String toString() { | ||
28 | return val.isPresent() ? "--" + key + "=" + val.get() : "--" + key; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | final private String cmd; | ||
33 | final private List<Option> opts; | ||
34 | final private List<String> args; | ||
35 | |||
36 | public Command(String cmd) { | ||
37 | this.cmd = cmd; | ||
38 | this.opts = new LinkedList<>(); | ||
39 | this.args = new LinkedList<>(); | ||
40 | } | ||
41 | |||
42 | public Command withOption(String key, String val) { | ||
43 | this.opts.add(new Option(key, val)); | ||
44 | return this; | ||
45 | } | ||
46 | |||
47 | public Command withOption(String key) { | ||
48 | return this.withOption(key, null); | ||
49 | } | ||
50 | |||
51 | public Command withArguments(String... args) { | ||
52 | this.args.addAll(Arrays.asList(args)); | ||
53 | return this; | ||
54 | } | ||
55 | |||
56 | public List<String> asList() { | ||
57 | return Collections.unmodifiableList( | ||
58 | Stream.concat(Stream.of(Collections.singleton(this.cmd)), | ||
59 | Stream.concat(Stream.of(this.opts).map(Option::toString), Stream.of(this.args))) | ||
60 | .collect(Collectors.toList())); | ||
61 | } | ||
62 | |||
63 | public String[] asArray() { | ||
64 | return this.asList().toArray(new String[0]); | ||
65 | } | ||
66 | |||
67 | } | ||