{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments/48715636","id":48715636,"diff_hunk":"@@ -0,0 +1,456 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package com.datatorrent.contrib.parser;\n+\n+import java.util.Map;\n+\n+import org.supercsv.cellprocessor.Optional;\n+import org.supercsv.cellprocessor.ParseBool;\n+import org.supercsv.cellprocessor.ParseChar;\n+import org.supercsv.cellprocessor.ParseDate;\n+import org.supercsv.cellprocessor.ParseDouble;\n+import org.supercsv.cellprocessor.ParseInt;\n+import org.supercsv.cellprocessor.ParseLong;\n+import org.supercsv.cellprocessor.constraint.DMinMax;\n+import org.supercsv.cellprocessor.constraint.Equals;\n+import org.supercsv.cellprocessor.constraint.LMinMax;\n+import org.supercsv.cellprocessor.constraint.StrMinMax;\n+import org.supercsv.cellprocessor.constraint.StrRegEx;\n+import org.supercsv.cellprocessor.constraint.Strlen;\n+import org.supercsv.cellprocessor.ift.CellProcessor;\n+import org.supercsv.cellprocessor.ift.DoubleCellProcessor;\n+import org.supercsv.cellprocessor.ift.LongCellProcessor;\n+import org.supercsv.util.CsvContext;\n+\n+import org.apache.commons.lang3.StringUtils;\n+\n+import com.datatorrent.contrib.parser.DelimitedSchema.FIELD_TYPE;\n+\n+/**\n+ * Helper class with methods to generate CellProcessor objects. Cell processors\n+ * are an integral part of reading and writing with Super CSV - they automate\n+ * the data type conversions, and enforce constraints. They implement the chain\n+ * of responsibility design pattern - each processor has a single, well-defined\n+ * purpose and can be chained together with other processors to fully automate\n+ * all of the required conversions and constraint validation for a single\n+ * delimited record.\n+ * \n+ */\n+public class CellProcessorBuilder\n+{\n+\n+  /**\n+   * Method to get cell processors for given field type and constraints\n+   * \n+   * @param fieldType\n+   *          data type of the field\n+   * @param constraints\n+   *          a map of constraints\n+   * @return\n+   */\n+  public static CellProcessor getCellProcessor(FIELD_TYPE fieldType, Map<String, Object> constraints)\n+  {\n+    switch (fieldType) {\n+      case STRING:\n+        return getStringCellProcessor(constraints);\n+      case INTEGER:\n+        return getIntegerCellProcessor(constraints);\n+      case LONG:\n+        return getLongCellProcessor(constraints);\n+      case FLOAT:\n+      case DOUBLE:\n+        return getDoubleCellProcessor(constraints);\n+      case CHARACTER:\n+        return getCharCellProcessor(constraints);\n+      case BOOLEAN:\n+        return getBooleanCellProcessor(constraints);\n+      case DATE:\n+        return getDateCellProcessor(constraints);\n+      default:\n+        return null;\n+    }\n+  }\n+\n+  /**\n+   * Method to get cellprocessor for String with constraints. These constraints\n+   * are evaluated against the String field for which this cellprocessor is\n+   * defined.\n+   * \n+   * @param constraints\n+   *          map of constraints applicable to String\n+   * @return CellProcessor\n+   */\n+  private static CellProcessor getStringCellProcessor(Map<String, Object> constraints)\n+  {\n+    Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean\n+        .parseBoolean((String)constraints.get(DelimitedSchema.REQUIRED));","path":"contrib/src/main/java/com/datatorrent/contrib/parser/CellProcessorBuilder.java","position":102,"original_position":102,"commit_id":"fba6612bb7647d4274eacb13ae90bd46069c5e66","original_commit_id":"fba6612bb7647d4274eacb13ae90bd46069c5e66","user":{"login":"shubham-pathak22","id":3529753,"avatar_url":"https://avatars.githubusercontent.com/u/3529753?v=3","gravatar_id":"","url":"https://api.github.com/users/shubham-pathak22","html_url":"https://github.com/shubham-pathak22","followers_url":"https://api.github.com/users/shubham-pathak22/followers","following_url":"https://api.github.com/users/shubham-pathak22/following{/other_user}","gists_url":"https://api.github.com/users/shubham-pathak22/gists{/gist_id}","starred_url":"https://api.github.com/users/shubham-pathak22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shubham-pathak22/subscriptions","organizations_url":"https://api.github.com/users/shubham-pathak22/orgs","repos_url":"https://api.github.com/users/shubham-pathak22/repos","events_url":"https://api.github.com/users/shubham-pathak22/events{/privacy}","received_events_url":"https://api.github.com/users/shubham-pathak22/received_events","type":"User","site_admin":false},"body":"Why not have a map ? It is  a Map<String, Object> \r\nAnd methods will have to convert the values to the required types.","created_at":"2016-01-04T09:46:00Z","updated_at":"2016-01-04T09:46:00Z","html_url":"https://github.com/apache/incubator-apex-malhar/pull/154#discussion_r48715636","pull_request_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments/48715636"},"html":{"href":"https://github.com/apache/incubator-apex-malhar/pull/154#discussion_r48715636"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154","id":54849955,"html_url":"https://github.com/apache/incubator-apex-malhar/pull/154","diff_url":"https://github.com/apache/incubator-apex-malhar/pull/154.diff","patch_url":"https://github.com/apache/incubator-apex-malhar/pull/154.patch","issue_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/154","number":154,"state":"open","locked":false,"title":"MLHR-1961 enhanced existing csv parser to take in schema for validations","user":{"login":"shubham-pathak22","id":3529753,"avatar_url":"https://avatars.githubusercontent.com/u/3529753?v=3","gravatar_id":"","url":"https://api.github.com/users/shubham-pathak22","html_url":"https://github.com/shubham-pathak22","followers_url":"https://api.github.com/users/shubham-pathak22/followers","following_url":"https://api.github.com/users/shubham-pathak22/following{/other_user}","gists_url":"https://api.github.com/users/shubham-pathak22/gists{/gist_id}","starred_url":"https://api.github.com/users/shubham-pathak22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shubham-pathak22/subscriptions","organizations_url":"https://api.github.com/users/shubham-pathak22/orgs","repos_url":"https://api.github.com/users/shubham-pathak22/repos","events_url":"https://api.github.com/users/shubham-pathak22/events{/privacy}","received_events_url":"https://api.github.com/users/shubham-pathak22/received_events","type":"User","site_admin":false},"body":"enhanced existing csv parser to take in schema for validations\r\n@gauravgopi123 could you please review.","created_at":"2015-12-31T06:42:40Z","updated_at":"2016-01-04T09:46:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7de74ded2f3899dbd9ad13ec16c38fd911641622","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/154/comments","statuses_url":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/fba6612bb7647d4274eacb13ae90bd46069c5e66","head":{"label":"shubham-pathak22:MLHR-1961","ref":"MLHR-1961","sha":"fba6612bb7647d4274eacb13ae90bd46069c5e66","user":{"login":"shubham-pathak22","id":3529753,"avatar_url":"https://avatars.githubusercontent.com/u/3529753?v=3","gravatar_id":"","url":"https://api.github.com/users/shubham-pathak22","html_url":"https://github.com/shubham-pathak22","followers_url":"https://api.github.com/users/shubham-pathak22/followers","following_url":"https://api.github.com/users/shubham-pathak22/following{/other_user}","gists_url":"https://api.github.com/users/shubham-pathak22/gists{/gist_id}","starred_url":"https://api.github.com/users/shubham-pathak22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shubham-pathak22/subscriptions","organizations_url":"https://api.github.com/users/shubham-pathak22/orgs","repos_url":"https://api.github.com/users/shubham-pathak22/repos","events_url":"https://api.github.com/users/shubham-pathak22/events{/privacy}","received_events_url":"https://api.github.com/users/shubham-pathak22/received_events","type":"User","site_admin":false},"repo":{"id":42044083,"name":"incubator-apex-malhar","full_name":"shubham-pathak22/incubator-apex-malhar","owner":{"login":"shubham-pathak22","id":3529753,"avatar_url":"https://avatars.githubusercontent.com/u/3529753?v=3","gravatar_id":"","url":"https://api.github.com/users/shubham-pathak22","html_url":"https://github.com/shubham-pathak22","followers_url":"https://api.github.com/users/shubham-pathak22/followers","following_url":"https://api.github.com/users/shubham-pathak22/following{/other_user}","gists_url":"https://api.github.com/users/shubham-pathak22/gists{/gist_id}","starred_url":"https://api.github.com/users/shubham-pathak22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shubham-pathak22/subscriptions","organizations_url":"https://api.github.com/users/shubham-pathak22/orgs","repos_url":"https://api.github.com/users/shubham-pathak22/repos","events_url":"https://api.github.com/users/shubham-pathak22/events{/privacy}","received_events_url":"https://api.github.com/users/shubham-pathak22/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shubham-pathak22/incubator-apex-malhar","description":"Mirror of Apache Apex malhar (Incubating)","fork":true,"url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar","forks_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/forks","keys_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/teams","hooks_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/hooks","issue_events_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/issues/events{/number}","events_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/events","assignees_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/assignees{/user}","branches_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/branches{/branch}","tags_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/tags","blobs_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/git/refs{/sha}","trees_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/statuses/{sha}","languages_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/languages","stargazers_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/stargazers","contributors_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/contributors","subscribers_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/subscribers","subscription_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/subscription","commits_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/commits{/sha}","git_commits_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/git/commits{/sha}","comments_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/comments{/number}","issue_comment_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/issues/comments{/number}","contents_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/contents/{+path}","compare_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/merges","archive_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/downloads","issues_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/issues{/number}","pulls_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/pulls{/number}","milestones_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/milestones{/number}","notifications_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/labels{/name}","releases_url":"https://api.github.com/repos/shubham-pathak22/incubator-apex-malhar/releases{/id}","created_at":"2015-09-07T09:31:00Z","updated_at":"2015-09-07T09:31:04Z","pushed_at":"2015-12-31T06:41:07Z","git_url":"git://github.com/shubham-pathak22/incubator-apex-malhar.git","ssh_url":"git@github.com:shubham-pathak22/incubator-apex-malhar.git","clone_url":"https://github.com/shubham-pathak22/incubator-apex-malhar.git","svn_url":"https://github.com/shubham-pathak22/incubator-apex-malhar","homepage":null,"size":83616,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:devel-3","ref":"devel-3","sha":"216c56aa2b604f14cf8a6773c67978166a5a5991","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":41348334,"name":"incubator-apex-malhar","full_name":"apache/incubator-apex-malhar","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-apex-malhar","description":"Mirror of Apache Apex malhar (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-apex-malhar","forks_url":"https://api.github.com/repos/apache/incubator-apex-malhar/forks","keys_url":"https://api.github.com/repos/apache/incubator-apex-malhar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-apex-malhar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-apex-malhar/teams","hooks_url":"https://api.github.com/repos/apache/incubator-apex-malhar/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-apex-malhar/events","assignees_url":"https://api.github.com/repos/apache/incubator-apex-malhar/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-apex-malhar/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-apex-malhar/tags","blobs_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-apex-malhar/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-apex-malhar/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-apex-malhar/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-apex-malhar/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-apex-malhar/subscription","commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-apex-malhar/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-apex-malhar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-apex-malhar/merges","archive_url":"https://api.github.com/repos/apache/incubator-apex-malhar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-apex-malhar/downloads","issues_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-apex-malhar/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-apex-malhar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-apex-malhar/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-apex-malhar/releases{/id}","created_at":"2015-08-25T07:00:05Z","updated_at":"2015-12-29T23:30:13Z","pushed_at":"2016-01-04T09:05:27Z","git_url":"git://github.com/apache/incubator-apex-malhar.git","ssh_url":"git@github.com:apache/incubator-apex-malhar.git","clone_url":"https://github.com/apache/incubator-apex-malhar.git","svn_url":"https://github.com/apache/incubator-apex-malhar","homepage":null,"size":93902,"stargazers_count":16,"watchers_count":16,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":51,"mirror_url":"git://git.apache.org/incubator-apex-malhar.git","open_issues_count":20,"forks":51,"open_issues":20,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154"},"html":{"href":"https://github.com/apache/incubator-apex-malhar/pull/154"},"issue":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/154"},"comments":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/154/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/154/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/fba6612bb7647d4274eacb13ae90bd46069c5e66"}}}}