Skip to content

Commit 7a3776c

Browse files
committed
优化命令参数
1 parent b647505 commit 7a3776c

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

AndroidExecLibrary/src/main/java/com/excellence/exec/Command.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ protected Executor getResponsePoster() {
5555
return mResponsePoster;
5656
}
5757

58+
/**
59+
* @see CommandTask.Builder#build()
60+
*
61+
* @param command
62+
* @param listener
63+
* @return
64+
*/
5865
@Deprecated
5966
protected CommandTask addTask(List<String> command, IListener listener) {
60-
CommandTask task = new CommandTask.Builder().command(command).build();
67+
CommandTask task = new CommandTask.Builder().commands(command).build();
6168
task.deploy(listener);
6269
return task;
6370
}

AndroidExecLibrary/src/main/java/com/excellence/exec/CommandTask.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.BufferedReader;
44
import java.io.InputStreamReader;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.List;
78
import java.util.concurrent.Executor;
@@ -62,35 +63,46 @@ private CommandTask(Builder builder) {
6263

6364
public static class Builder {
6465

65-
private List<String> mCommand = null;
66+
private List<String> mCommand = new ArrayList<>();
6667
private TimeUnit mTimeUnit = TimeUnit.MILLISECONDS;
6768
private long mTimeOut = 0;
6869
private long mTimeDelay = 0;
6970

7071
/**
71-
* 任务命令:字符串列表形式
72+
* 单个命令参数
7273
*
7374
* @param command
7475
* @return
7576
*/
76-
public Builder command(List<String> command) {
77-
mCommand = command;
77+
public Builder command(String command) {
78+
mCommand.add(command);
79+
return this;
80+
}
81+
82+
/**
83+
* 任务命令:字符串列表形式
84+
*
85+
* @param commands
86+
* @return
87+
*/
88+
public Builder commands(List<String> commands) {
89+
mCommand.addAll(commands);
7890
return this;
7991
}
8092

8193
/**
8294
* 任务命令:字符串、字符串数组形式
8395
*
84-
* @param command
96+
* @param commands
8597
* @return
8698
*/
87-
public Builder command(String[] command) {
88-
return command(Arrays.asList(command));
99+
public Builder commands(String[] commands) {
100+
return commands(Arrays.asList(commands));
89101
}
90102

91-
public Builder command(String command) {
92-
String[] cmd = command.split(" ");
93-
return command(cmd);
103+
public Builder commands(String command) {
104+
String[] commands = command.split(" ");
105+
return commands(commands);
94106
}
95107

96108
/**

AndroidExecLibrary/src/main/java/com/excellence/exec/Commander.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,34 @@ private Commander() {
5151

5252
}
5353

54+
/**
55+
* @see CommandTask.Builder#build()
56+
*
57+
* @param command
58+
* @param listener
59+
* @return
60+
*/
5461
@Deprecated
5562
public static CommandTask addTask(@NonNull List<String> command, IListener listener) {
5663
checkCommander();
5764
return mInstance.mCommand.addTask(command, listener);
5865
}
5966

67+
/**
68+
* @see CommandTask.Builder#build()
69+
*
70+
* @param command
71+
* @param listener
72+
* @return
73+
*/
6074
@Deprecated
6175
public static CommandTask addTask(@NonNull String[] command, IListener listener) {
6276
checkCommander();
6377
return addTask(Arrays.asList(command), listener);
6478
}
6579

6680
/**
81+
* @see CommandTask.Builder#build()
6782
* 字符串命令,参数请以空格分隔
6883
*
6984
* @param command

0 commit comments

Comments
 (0)