You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apex.apache.org by ilooner <gi...@git.apache.org> on 2015/11/07 07:53:02 UTC

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

GitHub user ilooner opened a pull request:

    https://github.com/apache/incubator-apex-malhar/pull/91

    - MLHR-1896 #resolve #comment Added utility functions to SchemaUtils.

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ilooner/incubator-apex-malhar MLHR-1896

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-apex-malhar/pull/91.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #91
    
----
commit 4fc5e9f743a71b1cf0d6cfc84e829aa32a0fda89
Author: Timothy Farkas <ti...@datatorrent.com>
Date:   2015-11-07T06:44:00Z

    - MLHR-1896 #resolve #comment Added utility functions to SchemaUtils.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

Posted by brightchen <gi...@git.apache.org>.
Github user brightchen commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/91#discussion_r45138364
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaUtils.java ---
    @@ -490,5 +493,37 @@ public static JSONObject createJSONObject(Map<String, String> map)
         return jo;
       }
     
    +  /**
    +   * This is a helper method which converts the given {@link JSONArray} to a {@link List} of Strings.
    +   *
    +   * @param jsonStringArray The {@link JSONArray} to convert.
    +   * @return The converted {@link List} of Strings.
    +   */
    +  public static List<String> getStringsFromJSONArray(JSONArray jsonStringArray) throws JSONException
    +  {
    +    List<String> stringArray = Lists.newArrayListWithCapacity(jsonStringArray.length());
    +
    +    for (int stringIndex = 0; stringIndex < jsonStringArray.length(); stringIndex++) {
    +      stringArray.add(jsonStringArray.getString(stringIndex));
    +    }
    +
    +    return stringArray;
    +  }
    +
    +  /**
    +   * This is a helper method which retrieves the schema tags from the {@link JSONObject} if they are present.
    +   *
    +   * @param jo The {@link JSONObject} to retrieve schema tags from.
    +   * @return A list containing the retrieved schema tags. The list is empty if there are no schema tags present.
    +   */
    +  public static List<String> getTags(JSONObject jo) throws JSONException
    +  {
    +    if (jo.has(FIELD_TAGS)) {
    +      return getStringsFromJSONArray(jo.getJSONArray(FIELD_TAGS));
    +    } else {
    +      return Lists.newArrayList();
    --- End diff --
    
    what about Collections.emptyList(); which don't need to create new instance


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

Posted by gauravgopi123 <gi...@git.apache.org>.
Github user gauravgopi123 commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/91#discussion_r44212068
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaUtils.java ---
    @@ -490,5 +493,54 @@ public static JSONObject createJSONObject(Map<String, String> map)
         return jo;
       }
     
    +  /**
    +   * This is a helper method which converts the given {@link JSONArray} to a {@link List} of Strings.
    +   *
    +   * @param jsonStringArray The {@link JSONArray} to convert.
    +   * @return The converted {@link List} of Strings.
    +   */
    +  public static List<String> getStringsFromJSONArray(JSONArray jsonStringArray) throws JSONException
    +  {
    +    List<String> stringArray = Lists.newArrayList();
    +
    +    for (int stringIndex = 0; stringIndex < jsonStringArray.length(); stringIndex++) {
    +      stringArray.add(jsonStringArray.getString(stringIndex));
    +    }
    +
    +    return stringArray;
    +  }
    +
    +  /**
    +   * This is a helper method which converts a list of strings to a {@link JSONArray}.
    +   *
    +   * @param stringArray The list of strings to convert to a {@link JSONArray}.
    +   * @return The converted {@link JSONArray}.
    +   */
    +  public static JSONArray getJSONArrayFromStrings(List<String> stringArray)
    +  {
    +    JSONArray ja = new JSONArray();
    --- End diff --
    
    JSONArray(Collection collection) ??


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

Posted by gauravgopi123 <gi...@git.apache.org>.
Github user gauravgopi123 commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/91#discussion_r44212010
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaUtils.java ---
    @@ -490,5 +493,54 @@ public static JSONObject createJSONObject(Map<String, String> map)
         return jo;
       }
     
    +  /**
    +   * This is a helper method which converts the given {@link JSONArray} to a {@link List} of Strings.
    +   *
    +   * @param jsonStringArray The {@link JSONArray} to convert.
    +   * @return The converted {@link List} of Strings.
    +   */
    +  public static List<String> getStringsFromJSONArray(JSONArray jsonStringArray) throws JSONException
    +  {
    +    List<String> stringArray = Lists.newArrayList();
    --- End diff --
    
    Can Lists.newArrayListWithCapacity() not be used since the the length of List is known?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-apex-malhar/pull/91


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-apex-malhar pull request: - MLHR-1896 #resolve #comment ...

Posted by ilooner <gi...@git.apache.org>.
Github user ilooner commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/91#discussion_r45141059
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaUtils.java ---
    @@ -490,5 +493,37 @@ public static JSONObject createJSONObject(Map<String, String> map)
         return jo;
       }
     
    +  /**
    +   * This is a helper method which converts the given {@link JSONArray} to a {@link List} of Strings.
    +   *
    +   * @param jsonStringArray The {@link JSONArray} to convert.
    +   * @return The converted {@link List} of Strings.
    +   */
    +  public static List<String> getStringsFromJSONArray(JSONArray jsonStringArray) throws JSONException
    +  {
    +    List<String> stringArray = Lists.newArrayListWithCapacity(jsonStringArray.length());
    +
    +    for (int stringIndex = 0; stringIndex < jsonStringArray.length(); stringIndex++) {
    +      stringArray.add(jsonStringArray.getString(stringIndex));
    +    }
    +
    +    return stringArray;
    +  }
    +
    +  /**
    +   * This is a helper method which retrieves the schema tags from the {@link JSONObject} if they are present.
    +   *
    +   * @param jo The {@link JSONObject} to retrieve schema tags from.
    +   * @return A list containing the retrieved schema tags. The list is empty if there are no schema tags present.
    +   */
    +  public static List<String> getTags(JSONObject jo) throws JSONException
    +  {
    +    if (jo.has(FIELD_TAGS)) {
    +      return getStringsFromJSONArray(jo.getJSONArray(FIELD_TAGS));
    +    } else {
    +      return Lists.newArrayList();
    --- End diff --
    
    Done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---