{"action":"created","comment":{"url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/comments/44862316","id":44862316,"diff_hunk":"@@ -0,0 +1,137 @@\n+package ru.unn.agile.MergeSort.ViewModel;\n+\n+import ru.unn.agile.MergeSort.Model.MergeSort;\n+\n+import java.util.Arrays;\n+import java.util.Collections;\n+import java.util.Objects;\n+\n+public class MergeSortViewModel {\n+    private boolean sortButtonEnabled;\n+    private String sourceArray;\n+    private String resultArray;\n+    private SortingOrder sortingOrder;\n+    private SortingArrayStatus sortingArrayStatus;\n+\n+    public MergeSortViewModel() {\n+        sortButtonEnabled = false;\n+        sourceArray = \"\";\n+        resultArray = \"\";\n+        sortingOrder = SortingOrder.ASCENDING;\n+        sortingArrayStatus = SortingArrayStatus.EMPTY;\n+    }\n+\n+    public void sort() {\n+        Double[] sortingArray;\n+        sortingArray = parseSourceArrayToSortingArray();\n+\n+        MergeSort.sort(sortingArray);\n+\n+        if (sortingOrder == SortingOrder.DESCENDING) {\n+            Collections.reverse(Arrays.asList(sortingArray));\n+        }\n+\n+        parseSortingArrayToResultArray(sortingArray);\n+    }\n+\n+    public String getSortingArray() {\n+        return resultArray;\n+    }\n+\n+    public void setSortingArray(final String sourceArray) {\n+        if (!canParseSourceArray(sourceArray)) {\n+            return;\n+        }\n+\n+        this.sourceArray = sourceArray;\n+    }\n+\n+    public boolean isSortButtonEnabled() {\n+        return sortButtonEnabled;\n+    }\n+\n+    public SortingOrder getSortingOrder() {\n+        return sortingOrder;\n+    }\n+\n+    public void setSortingOrder(final SortingOrder sortingOrder) {\n+        this.sortingOrder = sortingOrder;\n+    }\n+\n+    public String getSortingArrayStatus() {\n+        return sortingArrayStatus.toString();\n+    }\n+\n+    public enum SortingOrder {\n+        ASCENDING(\"Ascending\"),\n+        DESCENDING(\"Descending\");\n+\n+        SortingOrder(final String order) {\n+            this.order = order;\n+        }\n+\n+        public String toString() {\n+            return order;\n+        }\n+\n+        private final String order;\n+    }\n+\n+    public enum SortingArrayStatus {\n+        EMPTY(\"Please input source array\"),\n+        WRONG_FORMAT(\"Source array has wrong format\"),\n+        VALID_FORMAT(\"Press button to sort\");\n+\n+        SortingArrayStatus(final String status) {\n+            this.status = status;\n+        }\n+\n+        public String toString() {\n+            return status;\n+        }\n+\n+        private final String status;\n+    }\n+\n+    private boolean canParseSourceArray(final String sourceArray) {\n+        String[] elementsArray = sourceArray.split(\" \");\n+\n+        try {\n+            for (String anElementsArray : elementsArray) {\n+                Double.parseDouble(anElementsArray);\n+            }\n+        } catch (Exception e) {\n+            if (Objects.equals(sourceArray, \"\")) {\n+                sortingArrayStatus = SortingArrayStatus.EMPTY;\n+            } else {\n+                sortingArrayStatus = SortingArrayStatus.WRONG_FORMAT;\n+            }\n+            sortButtonEnabled = false;\n+            return false;\n+        }\n+\n+        sortingArrayStatus = SortingArrayStatus.VALID_FORMAT;\n+        sortButtonEnabled = true;\n+        return true;\n+    }\n+\n+    private Double[] parseSourceArrayToSortingArray() {\n+        String[] elementsArray = sourceArray.split(\" \");\n+        Double[] sortingArray = new Double[elementsArray.length];\n+\n+        for (int i = 0; i < elementsArray.length; i++) {\n+            sortingArray[i] = Double.parseDouble(elementsArray[i]);\n+        }\n+\n+        return sortingArray;\n+    }\n+\n+    private void parseSortingArrayToResultArray(final Double[] sortingArray) {\n+        resultArray = \"\";\n+\n+        for (int i = 0; i < sortingArray.length - 1; i++) {\n+            resultArray += sortingArray[i].toString() + \" \";\n+        }\n+        resultArray += sortingArray[sortingArray.length - 1].toString();","path":"code/gorokhov-dmitriy/ViewModel/src/main/java/ru/unn/agile/MergeSort/ViewModel/MergeSortViewModel.java","position":135,"original_position":135,"commit_id":"1eec6fb270e5c19ab30419016a729081144a2b0b","original_commit_id":"1eec6fb270e5c19ab30419016a729081144a2b0b","user":{"login":"vladimir-paramuzov","id":15000976,"avatar_url":"https://avatars.githubusercontent.com/u/15000976?v=3","gravatar_id":"","url":"https://api.github.com/users/vladimir-paramuzov","html_url":"https://github.com/vladimir-paramuzov","followers_url":"https://api.github.com/users/vladimir-paramuzov/followers","following_url":"https://api.github.com/users/vladimir-paramuzov/following{/other_user}","gists_url":"https://api.github.com/users/vladimir-paramuzov/gists{/gist_id}","starred_url":"https://api.github.com/users/vladimir-paramuzov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladimir-paramuzov/subscriptions","organizations_url":"https://api.github.com/users/vladimir-paramuzov/orgs","repos_url":"https://api.github.com/users/vladimir-paramuzov/repos","events_url":"https://api.github.com/users/vladimir-paramuzov/events{/privacy}","received_events_url":"https://api.github.com/users/vladimir-paramuzov/received_events","type":"User","site_admin":false},"body":"Эта строчка только для того, чтобы не ставить пробел в конце строки? Если так, то оно правда нужно?","created_at":"2015-11-14T19:12:56Z","updated_at":"2015-11-14T19:12:56Z","html_url":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119#discussion_r44862316","pull_request_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119","_links":{"self":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/comments/44862316"},"html":{"href":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119#discussion_r44862316"},"pull_request":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119"}}},"pull_request":{"url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119","id":50728610,"html_url":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119","diff_url":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119.diff","patch_url":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119.patch","issue_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/119","number":119,"state":"open","locked":false,"title":"Горохов - Лабораторная работа #2","user":{"login":"gdmit","id":4019831,"avatar_url":"https://avatars.githubusercontent.com/u/4019831?v=3","gravatar_id":"","url":"https://api.github.com/users/gdmit","html_url":"https://github.com/gdmit","followers_url":"https://api.github.com/users/gdmit/followers","following_url":"https://api.github.com/users/gdmit/following{/other_user}","gists_url":"https://api.github.com/users/gdmit/gists{/gist_id}","starred_url":"https://api.github.com/users/gdmit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdmit/subscriptions","organizations_url":"https://api.github.com/users/gdmit/orgs","repos_url":"https://api.github.com/users/gdmit/repos","events_url":"https://api.github.com/users/gdmit/events{/privacy}","received_events_url":"https://api.github.com/users/gdmit/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-14T18:11:09Z","updated_at":"2015-11-14T19:12:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0caafd229f524d08fb8e360bab8ea3bd94cd7fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119/commits","review_comments_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119/comments","review_comment_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/comments{/number}","comments_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/119/comments","statuses_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/statuses/1eec6fb270e5c19ab30419016a729081144a2b0b","head":{"label":"gdmit:lab2-mvvm-mergesort","ref":"lab2-mvvm-mergesort","sha":"1eec6fb270e5c19ab30419016a729081144a2b0b","user":{"login":"gdmit","id":4019831,"avatar_url":"https://avatars.githubusercontent.com/u/4019831?v=3","gravatar_id":"","url":"https://api.github.com/users/gdmit","html_url":"https://github.com/gdmit","followers_url":"https://api.github.com/users/gdmit/followers","following_url":"https://api.github.com/users/gdmit/following{/other_user}","gists_url":"https://api.github.com/users/gdmit/gists{/gist_id}","starred_url":"https://api.github.com/users/gdmit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdmit/subscriptions","organizations_url":"https://api.github.com/users/gdmit/orgs","repos_url":"https://api.github.com/users/gdmit/repos","events_url":"https://api.github.com/users/gdmit/events{/privacy}","received_events_url":"https://api.github.com/users/gdmit/received_events","type":"User","site_admin":false},"repo":{"id":44682962,"name":"agile-course-practice","full_name":"gdmit/agile-course-practice","owner":{"login":"gdmit","id":4019831,"avatar_url":"https://avatars.githubusercontent.com/u/4019831?v=3","gravatar_id":"","url":"https://api.github.com/users/gdmit","html_url":"https://github.com/gdmit","followers_url":"https://api.github.com/users/gdmit/followers","following_url":"https://api.github.com/users/gdmit/following{/other_user}","gists_url":"https://api.github.com/users/gdmit/gists{/gist_id}","starred_url":"https://api.github.com/users/gdmit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdmit/subscriptions","organizations_url":"https://api.github.com/users/gdmit/orgs","repos_url":"https://api.github.com/users/gdmit/repos","events_url":"https://api.github.com/users/gdmit/events{/privacy}","received_events_url":"https://api.github.com/users/gdmit/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gdmit/agile-course-practice","description":"Проект-шаблон для выполнения лабораторных работ по курсу Agile Development","fork":true,"url":"https://api.github.com/repos/gdmit/agile-course-practice","forks_url":"https://api.github.com/repos/gdmit/agile-course-practice/forks","keys_url":"https://api.github.com/repos/gdmit/agile-course-practice/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gdmit/agile-course-practice/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gdmit/agile-course-practice/teams","hooks_url":"https://api.github.com/repos/gdmit/agile-course-practice/hooks","issue_events_url":"https://api.github.com/repos/gdmit/agile-course-practice/issues/events{/number}","events_url":"https://api.github.com/repos/gdmit/agile-course-practice/events","assignees_url":"https://api.github.com/repos/gdmit/agile-course-practice/assignees{/user}","branches_url":"https://api.github.com/repos/gdmit/agile-course-practice/branches{/branch}","tags_url":"https://api.github.com/repos/gdmit/agile-course-practice/tags","blobs_url":"https://api.github.com/repos/gdmit/agile-course-practice/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gdmit/agile-course-practice/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gdmit/agile-course-practice/git/refs{/sha}","trees_url":"https://api.github.com/repos/gdmit/agile-course-practice/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gdmit/agile-course-practice/statuses/{sha}","languages_url":"https://api.github.com/repos/gdmit/agile-course-practice/languages","stargazers_url":"https://api.github.com/repos/gdmit/agile-course-practice/stargazers","contributors_url":"https://api.github.com/repos/gdmit/agile-course-practice/contributors","subscribers_url":"https://api.github.com/repos/gdmit/agile-course-practice/subscribers","subscription_url":"https://api.github.com/repos/gdmit/agile-course-practice/subscription","commits_url":"https://api.github.com/repos/gdmit/agile-course-practice/commits{/sha}","git_commits_url":"https://api.github.com/repos/gdmit/agile-course-practice/git/commits{/sha}","comments_url":"https://api.github.com/repos/gdmit/agile-course-practice/comments{/number}","issue_comment_url":"https://api.github.com/repos/gdmit/agile-course-practice/issues/comments{/number}","contents_url":"https://api.github.com/repos/gdmit/agile-course-practice/contents/{+path}","compare_url":"https://api.github.com/repos/gdmit/agile-course-practice/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gdmit/agile-course-practice/merges","archive_url":"https://api.github.com/repos/gdmit/agile-course-practice/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gdmit/agile-course-practice/downloads","issues_url":"https://api.github.com/repos/gdmit/agile-course-practice/issues{/number}","pulls_url":"https://api.github.com/repos/gdmit/agile-course-practice/pulls{/number}","milestones_url":"https://api.github.com/repos/gdmit/agile-course-practice/milestones{/number}","notifications_url":"https://api.github.com/repos/gdmit/agile-course-practice/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gdmit/agile-course-practice/labels{/name}","releases_url":"https://api.github.com/repos/gdmit/agile-course-practice/releases{/id}","created_at":"2015-10-21T14:44:03Z","updated_at":"2015-10-21T14:44:03Z","pushed_at":"2015-11-14T18:33:50Z","git_url":"git://github.com/gdmit/agile-course-practice.git","ssh_url":"git@github.com:gdmit/agile-course-practice.git","clone_url":"https://github.com/gdmit/agile-course-practice.git","svn_url":"https://github.com/gdmit/agile-course-practice","homepage":"","size":233,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"UNN-VMK-Software:master","ref":"master","sha":"25daf82730f7b8833eb0eefa99dc479e5a7b4b4e","user":{"login":"UNN-VMK-Software","id":5463209,"avatar_url":"https://avatars.githubusercontent.com/u/5463209?v=3","gravatar_id":"","url":"https://api.github.com/users/UNN-VMK-Software","html_url":"https://github.com/UNN-VMK-Software","followers_url":"https://api.github.com/users/UNN-VMK-Software/followers","following_url":"https://api.github.com/users/UNN-VMK-Software/following{/other_user}","gists_url":"https://api.github.com/users/UNN-VMK-Software/gists{/gist_id}","starred_url":"https://api.github.com/users/UNN-VMK-Software/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNN-VMK-Software/subscriptions","organizations_url":"https://api.github.com/users/UNN-VMK-Software/orgs","repos_url":"https://api.github.com/users/UNN-VMK-Software/repos","events_url":"https://api.github.com/users/UNN-VMK-Software/events{/privacy}","received_events_url":"https://api.github.com/users/UNN-VMK-Software/received_events","type":"Organization","site_admin":false},"repo":{"id":44518750,"name":"agile-course-practice","full_name":"UNN-VMK-Software/agile-course-practice","owner":{"login":"UNN-VMK-Software","id":5463209,"avatar_url":"https://avatars.githubusercontent.com/u/5463209?v=3","gravatar_id":"","url":"https://api.github.com/users/UNN-VMK-Software","html_url":"https://github.com/UNN-VMK-Software","followers_url":"https://api.github.com/users/UNN-VMK-Software/followers","following_url":"https://api.github.com/users/UNN-VMK-Software/following{/other_user}","gists_url":"https://api.github.com/users/UNN-VMK-Software/gists{/gist_id}","starred_url":"https://api.github.com/users/UNN-VMK-Software/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UNN-VMK-Software/subscriptions","organizations_url":"https://api.github.com/users/UNN-VMK-Software/orgs","repos_url":"https://api.github.com/users/UNN-VMK-Software/repos","events_url":"https://api.github.com/users/UNN-VMK-Software/events{/privacy}","received_events_url":"https://api.github.com/users/UNN-VMK-Software/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/UNN-VMK-Software/agile-course-practice","description":"Проект-шаблон для выполнения лабораторных работ по курсу Agile Development","fork":false,"url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice","forks_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/forks","keys_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/teams","hooks_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/hooks","issue_events_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/events{/number}","events_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/events","assignees_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/assignees{/user}","branches_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/branches{/branch}","tags_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/tags","blobs_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/git/refs{/sha}","trees_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/statuses/{sha}","languages_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/languages","stargazers_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/stargazers","contributors_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/contributors","subscribers_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/subscribers","subscription_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/subscription","commits_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/commits{/sha}","git_commits_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/git/commits{/sha}","comments_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/comments{/number}","issue_comment_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/comments{/number}","contents_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/contents/{+path}","compare_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/merges","archive_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/downloads","issues_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues{/number}","pulls_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls{/number}","milestones_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/milestones{/number}","notifications_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/labels{/name}","releases_url":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/releases{/id}","created_at":"2015-10-19T07:42:22Z","updated_at":"2015-10-29T19:46:12Z","pushed_at":"2015-11-14T18:33:50Z","git_url":"git://github.com/UNN-VMK-Software/agile-course-practice.git","ssh_url":"git@github.com:UNN-VMK-Software/agile-course-practice.git","clone_url":"https://github.com/UNN-VMK-Software/agile-course-practice.git","svn_url":"https://github.com/UNN-VMK-Software/agile-course-practice","homepage":"","size":3579,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":15,"forks":45,"open_issues":15,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119"},"html":{"href":"https://github.com/UNN-VMK-Software/agile-course-practice/pull/119"},"issue":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/119"},"comments":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/issues/119/comments"},"review_comments":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119/comments"},"review_comment":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/pulls/119/commits"},"statuses":{"href":"https://api.github.com/repos/UNN-VMK-Software/agile-course-practice/statuses/1eec6fb270e5c19ab30419016a729081144a2b0b"}}}}