Github user gauravgopi123 commented on a diff in the pull request:
https://github.com/apache/incubator-apex-malhar/pull/103#discussion_r45103071
--- Diff:
library/src/main/java/com/datatorrent/lib/appdata/gpo/GPOUtils.java ---
@@ -123,6 +123,54 @@ public static GPOMutable deserialize(FieldsDescriptor
fieldsDescriptor,
}
/**
+ * This method deserializes the fields in the given {@link
FieldsDescriptor} into a map.
+ * @param fieldsDescriptor The {@link FieldsDescriptor} to fetch fields
from.
+ * @param dpou The {@link JSONObject} which contains the fields whose
values need to be fetched.
+ * @return A {@link Map} whose keys are field names, and whose values
are possible values for those fields.
+ */
+ public static Map<String, Set<Object>> deserializeToMap(FieldsDescriptor
fieldsDescriptor,
+ JSONObject dpou)
+ {
+ Map<String, Set<Object>> keyToValues = Maps.newHashMap();
+
+ for (String key : fieldsDescriptor.getFields().getFields()) {
+ if (!dpou.has(key)) {
+ throw new IllegalArgumentException("The given key " + key + " is
not contained in the given JSON");
+ }
+
+ Type type = fieldsDescriptor.getType(key);
+ Set<Object> keyValues = Sets.newHashSet();
--- End diff --
I think you should not initialize it here.
In if (keyValue instanceof JSONArray){} loop , initialized it with length
of the array and in final else loop initialize it with length 1 using
Sets.newHashSetWithExpectedSize().
keyToValues.put(key, keyValues) can be the last step in main for loop
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---