From a5e1dc6d76068f371a2c0082e17ae516ec27d36b Mon Sep 17 00:00:00 2001 From: Nazar Date: Tue, 9 Jul 2019 18:43:48 +0300 Subject: [PATCH] extract add command code to method addToCommandList() --- OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java | 6 +++++- .../src/net/osmand/plus/voice/JSCommandBuilder.java | 11 ++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index bb2cca52ce..2e7bdaf72a 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -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 getListCommands() { diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index 87e340e8b8..f963eb81e6 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -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);