From e52e012e5e7f3f82fae2eb950a277f2337e4f032 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Tue, 22 Aug 2017 17:31:20 +0100 Subject: [PATCH] [android][database] Combine snapshotToMap methods --- .../java/io/invertase/firebase/Utils.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/Utils.java b/android/src/main/java/io/invertase/firebase/Utils.java index 8a781a4c..15f2d670 100644 --- a/android/src/main/java/io/invertase/firebase/Utils.java +++ b/android/src/main/java/io/invertase/firebase/Utils.java @@ -84,26 +84,7 @@ public class Utils { */ public static WritableMap snapshotToMap(DataSnapshot dataSnapshot, @Nullable String previousChildName) { WritableMap result = Arguments.createMap(); - WritableMap snapshot = Arguments.createMap(); - - snapshot.putString("key", dataSnapshot.getKey()); - snapshot.putBoolean("exists", dataSnapshot.exists()); - snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren()); - snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount()); - snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot)); - mapPutValue("priority", dataSnapshot.getPriority(), snapshot); - - if (!dataSnapshot.hasChildren()) { - mapPutValue("value", dataSnapshot.getValue(), snapshot); - } else { - Object value = Utils.castValue(dataSnapshot); - if (value instanceof WritableNativeArray) { - snapshot.putArray("value", (WritableArray) value); - } else { - snapshot.putMap("value", (WritableMap) value); - } - } - + WritableMap snapshot = Utils.snapshotToMap(dataSnapshot); result.putMap("snapshot", snapshot); result.putString("previousChildName", previousChildName); @@ -161,6 +142,8 @@ public class Utils { snapshot.putBoolean("exists", dataSnapshot.exists()); snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren()); snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount()); + snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot)); + mapPutValue("priority", dataSnapshot.getPriority(), snapshot); if (!dataSnapshot.hasChildren()) { mapPutValue("value", dataSnapshot.getValue(), snapshot); @@ -173,9 +156,6 @@ public class Utils { } } - snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot)); - mapPutValue("priority", dataSnapshot.getPriority(), snapshot); - return snapshot; }