2018년 10월 16일 화요일

[watson-developer-cloud/java-sdk] #994


   요약
StringHelper.createFormPartName() 및 test가 추가되었습니다.

   메일
Added StringHelper.createFormPartName and tests

Phil Adams

Summary
The new StringHelper.createFormPartName() function introduced by this PR will be used by generated java code when the "mapified form parameter" feature is used.


Mike Kistler

@mkistler requested changes on this pull request.

I think we can avoid adding this code to the SDK with some small changes to the generator.


> +     * Creates a parameterized part name for a form part based on a template and a key name and value.
+     * Example:
+     *     template: "{classname}_positive_examples"
+     *     keyName:  "classname"
+     *     keyValue: "truck"
+     *     result: "truck_positive_examples"
+     *
+     * @param template the part name template
+     * @param keyName the name of the key within the template
+     * @param keyValue the value of the key to use as a replacement
+     * @return
+     */
+    public static String createFormPartName(String template, String keyName, String keyValue) {
+        String toBeReplaced = "{" + keyName + "}";
+        return template.replace(toBeReplaced, keyValue);
+    }
It seems like we could avoid having this special function if we did just a little more work in the generator.
In particular, I think we could, in the generator, create a "format string" from the template:
"{classname}_positive_examples" -> "%s_positive_examples"
Then in the service method, we change
String partName = StringHelper.createFormPartName("{{partNameTemplate}}", "{{mapKeyName}}", entry.getKey());
to
String partName = String.format("{{partNameFormatString}}", entry.getKey());

Codecov

Codecov Report
Merging #994 into master will decrease coverage by <.01%.
The diff coverage is 100%.
....

Phil Adams

This PR will not be needed afterall...

   번역
StringHelper.createFormPartName 및 tests가 추가되었습니다.

Phil Adams

개요
이 PR로 도입된 새로운 StringHelper.createFormPartName() 함수는 "mapified form parameter" 기능이 사용될 때 생성된 java code에 의해 사용됩니다.

Mike Kistler

@mkistler pull 요청에 대한 변경을 요청했습니다.

생성자에 조금 변경을 가하면 이 코드를 SDK에 추가하는 것을 피할 수 있을 겁니다.


> +     * Creates a parameterized part name for a form part based on a template and a key name and value.
+     * Example:
+     *     template: "{classname}_positive_examples"
+     *     keyName:  "classname"
+     *     keyValue: "truck"
+     *     result: "truck_positive_examples"
+     *
+     * @param template the part name template
+     * @param keyName the name of the key within the template
+     * @param keyValue the value of the key to use as a replacement
+     * @return
+     */
+    public static String createFormPartName(String template, String keyName, String keyValue) {
+        String toBeReplaced = "{" + keyName + "}";
+        return template.replace(toBeReplaced, keyValue);
+    }
생성자에 좀 더 많은 작업을 했다면, 이 특수 function을 사용하지 않아도 될 것 같습니다.
특히 생성자에서 템플릿으로부터 "형식 string"을 만들 수 있다고 생각합니다.
"{classname}_positive_examples" -> "%s_positive_examples"
그런 다음 서비스 method에서 
String partName = StringHelper.createFormPartName("{{partNameTemplate}}", "{{mapKeyName}}", entry.getKey());
String partName = String.format("{{partNameFormatString}}", entry.getKey());

로 변경합니다.

Codecov

Codecov Report
#994를 master에 merge하면 적용범휘가 <.01 % 감소합니다.
변경된 적용범위는 100%입니다.
....

Phil Adams

결국 이 PR은 필요없을 것입니다...

댓글 없음:

댓글 쓰기