You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dj...@apache.org on 2016/03/17 18:13:17 UTC

[02/10] incubator-quarks git commit: Simplify command handling

Simplify command handling


Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/cc9597b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/cc9597b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/cc9597b4

Branch: refs/heads/master
Commit: cc9597b429a3b10018c091073fc901c33cd6f406
Parents: 27c4f0b
Author: Dan Debrunner <dj...@debrunners.com>
Authored: Mon Mar 14 12:45:08 2016 -0700
Committer: Dan Debrunner <dj...@debrunners.com>
Committed: Wed Mar 16 15:17:22 2016 -0700

----------------------------------------------------------------------
 .../java/quarks/test/apps/iot/EchoIotDevice.java | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/cc9597b4/apps/iot/src/test/java/quarks/test/apps/iot/EchoIotDevice.java
----------------------------------------------------------------------
diff --git a/apps/iot/src/test/java/quarks/test/apps/iot/EchoIotDevice.java b/apps/iot/src/test/java/quarks/test/apps/iot/EchoIotDevice.java
index 00bc0aa..648f633 100644
--- a/apps/iot/src/test/java/quarks/test/apps/iot/EchoIotDevice.java
+++ b/apps/iot/src/test/java/quarks/test/apps/iot/EchoIotDevice.java
@@ -19,7 +19,6 @@ under the License.
 
 package quarks.test.apps.iot;
 
-import static quarks.function.Functions.alwaysTrue;
 import static quarks.function.Functions.discard;
 
 import java.util.HashSet;
@@ -109,20 +108,10 @@ public class EchoIotDevice implements IotDevice {
     @Override
     public TStream<JsonObject> commands(String... commands) {
         if (commands.length == 0)
-            return echoCmds.filter(alwaysTrue());
-
-        TStream<JsonObject> cmd0 = echoCmds
-                .filter(j -> j.getAsJsonPrimitive(CMD_ID).getAsString().equals(commands[0]));
-
-        if (commands.length == 1)
-            return cmd0;
+            return echoCmds;
 
         Set<TStream<JsonObject>> cmds = new HashSet<>();
-        for (int i = 1; i < commands.length; i++) {
-            final int idx = i;
-            cmds.add(echoCmds.filter(j -> j.getAsJsonPrimitive(CMD_ID).getAsString().equals(commands[idx])));
-        }
-
-        return cmd0.union(cmds);
+        return echoCmds.filter(cmd -> cmds.contains(cmd.getAsJsonPrimitive(CMD_ID).getAsString()));
     }
-}
\ No newline at end of file
+}
+