apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilooner <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: - MLHR-1908 Added helper metho...
Date Tue, 17 Nov 2015 20:16:46 GMT
Github user ilooner commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/103#discussion_r45114310
  
    --- Diff: library/src/main/java/com/datatorrent/lib/appdata/gpo/GPOUtils.java ---
    @@ -304,52 +355,216 @@ else if(type == Type.CHAR) {
                                                + " that is not one character long.");
           }
     
    -      gpo.setField(field, val.charAt(0));
    -    }
    -    else if(type == Type.STRING) {
    +      return val.charAt(0);
    +    } else if (type == Type.STRING) {
           String val;
     
           try {
             val = jo.getString(field);
    -      }
    -      catch(JSONException ex) {
    +      } catch (JSONException ex) {
             throw new IllegalArgumentException("The key "
                                                + field
                                                + " does not have a valid string value.",
                                                ex);
           }
     
    -      gpo.setField(field, val);
    -    }
    -    else if(type == Type.DOUBLE) {
    +      return val;
    +    } else if (type == Type.DOUBLE) {
           Double val;
     
           try {
             val = jo.getDouble(field);
    -      }
    -      catch(JSONException ex) {
    +      } catch (JSONException ex) {
             throw new IllegalArgumentException("The key "
                                                + field
                                                + " does not have a valid double value.",
                                                ex);
           }
     
    -      gpo.setFieldGeneric(field, val);
    -    }
    -    else if(type == Type.FLOAT) {
    +      return val;
    +    } else if (type == Type.FLOAT) {
           Float val;
     
           try {
             val = (float)jo.getDouble(field);
    -      }
    -      catch(JSONException ex) {
    +      } catch (JSONException ex) {
             throw new IllegalArgumentException("The key "
                                                + field
                                                + " does not have a valid double value.",
                                                ex);
           }
     
    -      gpo.setFieldGeneric(field, val);
    +      return val;
    +    } else {
    +      throw new UnsupportedOperationException("The type " + type + " is not supported.");
    +    }
    +  }
    +
    +  /**
    +   * This method gets an object of the given {@link Type} from the given {@link JSONArray}
at the
    +   * given index.
    +   * @param type The {@link Type} of the object to retrieve from the {@link JSONArray}.
    +   * @param ja The {@link JSONArray} to retrieve objects from.
    +   * @param index The index of the object in the {@link JSONArray} to retrieve.
    +   * @return The object retrieved from the {@link JSONArray}.
    +   */
    +  public static Object getFieldFromJSON(Type type, JSONArray ja, int index)
    +  {
    +    if (type == Type.BOOLEAN) {
    +      Boolean val;
    +
    +      try {
    +        val = ja.getBoolean(index);
    --- 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.
---

Mime
View raw message