extract add command code to method addToCommandList()

This commit is contained in:
Nazar 2019-07-09 18:43:48 +03:00
parent b8db6f6e19
commit a5e1dc6d76
2 changed files with 7 additions and 10 deletions

View file

@ -67,8 +67,13 @@ public class CommandBuilder {
}
private CommandBuilder addCommand(String name, Object... args){
addToCommandList(name, args);
Struct struct = prepareStruct(name, args);
listStruct.add(struct);
return this;
}
protected void addToCommandList(String name, Object... args) {
listCommands.add(name);
for(Object o : args) {
if(o != null) {
@ -77,7 +82,6 @@ public class CommandBuilder {
listCommands.add("");
}
}
return this;
}
public List<String> getListCommands() {

View file

@ -55,15 +55,8 @@ public class JSCommandBuilder extends CommandBuilder {
}
private JSCommandBuilder addCommand(String name, Object... args){
listCommands.add(name);
for(Object o : args) {
if(o != null) {
listCommands.add(o.toString());
} else {
listCommands.add("");
}
}
Object obj = jsScope.get(name);
addToCommandList(name, args);
Object obj = jsScope.get(name);
if (obj instanceof Function) {
Function jsFunction = (Function) obj;
Object jsResult = jsFunction.call(jsContext, jsScope, jsScope, args);