{"action":"created","comment":{"url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/comments/48459054","id":48459054,"diff_hunk":"@@ -0,0 +1,366 @@\n+/*\n+ * Copyright 2015, TeamDev Ltd. All rights reserved.\n+ *\n+ * Redistribution and use in source and/or binary forms, with or without\n+ * modification, must retain the above copyright notice and the following\n+ * disclaimer.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spine3.samples.lobby.registration.seat.availability;\n+\n+import com.google.common.annotations.VisibleForTesting;\n+import com.google.common.collect.ImmutableList;\n+import com.google.protobuf.Message;\n+import org.spine3.base.CommandContext;\n+import org.spine3.samples.lobby.common.ReservationId;\n+import org.spine3.samples.lobby.common.SeatTypeId;\n+import org.spine3.samples.lobby.registration.contracts.SeatQuantity;\n+import org.spine3.server.Assign;\n+import org.spine3.server.aggregate.Aggregate;\n+import org.spine3.server.aggregate.Apply;\n+\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.NoSuchElementException;\n+\n+import static com.google.common.base.Preconditions.checkState;\n+import static com.google.common.collect.Lists.newLinkedList;\n+import static org.spine3.samples.lobby.registration.util.CollectionUtils.findById;\n+import static org.spine3.samples.lobby.registration.util.MessageFactory.newSeatQuantities;\n+import static org.spine3.samples.lobby.registration.util.MessageFactory.newSeatQuantity;\n+import static org.spine3.samples.lobby.registration.util.ValidationUtils.*;\n+\n+/**\n+ * The aggregate which manages the availability of conference seats.\n+ *\n+ * @author Alexander Litus\n+ */\n+@SuppressWarnings({\"TypeMayBeWeakened\"/** \"OrBuilder\" parameters are not applicable*/, \"OverlyCoupledClass\"})\n+public class SeatsAvailabilityAggregate extends Aggregate<SeatsAvailabilityId, SeatsAvailability> {\n+\n+    /**\n+     * Creates a new instance.\n+     *\n+     * @param id the ID for the new instance\n+     * @throws IllegalArgumentException if the ID type is not supported\n+     */\n+    public SeatsAvailabilityAggregate(SeatsAvailabilityId id) {\n+        super(id);\n+    }\n+\n+    @Override\n+    protected SeatsAvailability getDefaultState() {\n+        return SeatsAvailability.getDefaultInstance();\n+    }\n+\n+    @Assign\n+    public SeatsReserved handle(MakeSeatReservation cmd, CommandContext context) {\n+        Validator.validateCommand(cmd);\n+\n+        final MakeSeatReservationCommandHandler handler = new MakeSeatReservationCommandHandler(getState());\n+        handler.handle(cmd);\n+\n+        final SeatsReserved.Builder reserved = SeatsReserved.newBuilder()\n+                .setReservationId(cmd.getReservationId())\n+                .setConferenceId(cmd.getConferenceId())\n+                .addAllReservedSeatUpdated(handler.getReservedSeatsUpdated())\n+                .addAllAvailableSeatUpdated(handler.getAvailableSeatsUpdated());\n+        return reserved.build();\n+    }\n+\n+    @Assign\n+    public SeatsReservationCommitted handle(CommitSeatReservation cmd, CommandContext context) {\n+        Validator.validateCommand(cmd);\n+        Validator.validateState(getState(), cmd);\n+\n+        final SeatsReservationCommitted.Builder event = SeatsReservationCommitted.newBuilder()\n+                .setReservationId(cmd.getReservationId());\n+        return event.build();\n+    }\n+\n+    @Assign\n+    public SeatsReservationCancelled handle(CancelSeatReservation cmd, CommandContext context) {\n+        Validator.validateCommand(cmd);\n+        Validator.validateState(getState(), cmd);","path":"registration/src/main/java/org/spine3/samples/lobby/registration/seat/availability/SeatsAvailabilityAggregate.java","position":97,"original_position":97,"commit_id":"a5a213d1534dd42e988c8a8eb6e3db4be99278eb","original_commit_id":"a5a213d1534dd42e988c8a8eb6e3db4be99278eb","user":{"login":"alexander-yevsyukov","id":3116444,"avatar_url":"https://avatars.githubusercontent.com/u/3116444?v=3","gravatar_id":"","url":"https://api.github.com/users/alexander-yevsyukov","html_url":"https://github.com/alexander-yevsyukov","followers_url":"https://api.github.com/users/alexander-yevsyukov/followers","following_url":"https://api.github.com/users/alexander-yevsyukov/following{/other_user}","gists_url":"https://api.github.com/users/alexander-yevsyukov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexander-yevsyukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexander-yevsyukov/subscriptions","organizations_url":"https://api.github.com/users/alexander-yevsyukov/orgs","repos_url":"https://api.github.com/users/alexander-yevsyukov/repos","events_url":"https://api.github.com/users/alexander-yevsyukov/events{/privacy}","received_events_url":"https://api.github.com/users/alexander-yevsyukov/received_events","type":"User","site_admin":false},"body":"Extract state into local var.","created_at":"2015-12-27T22:50:42Z","updated_at":"2015-12-27T22:50:42Z","html_url":"https://github.com/SpineEventEngine/Lobby/pull/10#discussion_r48459054","pull_request_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/comments/48459054"},"html":{"href":"https://github.com/SpineEventEngine/Lobby/pull/10#discussion_r48459054"},"pull_request":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10","id":54589356,"html_url":"https://github.com/SpineEventEngine/Lobby/pull/10","diff_url":"https://github.com/SpineEventEngine/Lobby/pull/10.diff","patch_url":"https://github.com/SpineEventEngine/Lobby/pull/10.patch","issue_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/10","number":10,"state":"open","locked":false,"title":"Define state-neutral events","user":{"login":"AlexanderLitus","id":8298183,"avatar_url":"https://avatars.githubusercontent.com/u/8298183?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexanderLitus","html_url":"https://github.com/AlexanderLitus","followers_url":"https://api.github.com/users/AlexanderLitus/followers","following_url":"https://api.github.com/users/AlexanderLitus/following{/other_user}","gists_url":"https://api.github.com/users/AlexanderLitus/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexanderLitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexanderLitus/subscriptions","organizations_url":"https://api.github.com/users/AlexanderLitus/orgs","repos_url":"https://api.github.com/users/AlexanderLitus/repos","events_url":"https://api.github.com/users/AlexanderLitus/events{/privacy}","received_events_url":"https://api.github.com/users/AlexanderLitus/received_events","type":"User","site_admin":false},"body":"Depends on PR #9.","created_at":"2015-12-25T15:23:20Z","updated_at":"2015-12-27T22:50:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db42ea987249b3d22efeed207f7a39f58587331d","assignee":{"login":"alexander-yevsyukov","id":3116444,"avatar_url":"https://avatars.githubusercontent.com/u/3116444?v=3","gravatar_id":"","url":"https://api.github.com/users/alexander-yevsyukov","html_url":"https://github.com/alexander-yevsyukov","followers_url":"https://api.github.com/users/alexander-yevsyukov/followers","following_url":"https://api.github.com/users/alexander-yevsyukov/following{/other_user}","gists_url":"https://api.github.com/users/alexander-yevsyukov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexander-yevsyukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexander-yevsyukov/subscriptions","organizations_url":"https://api.github.com/users/alexander-yevsyukov/orgs","repos_url":"https://api.github.com/users/alexander-yevsyukov/repos","events_url":"https://api.github.com/users/alexander-yevsyukov/events{/privacy}","received_events_url":"https://api.github.com/users/alexander-yevsyukov/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10/commits","review_comments_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10/comments","review_comment_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/10/comments","statuses_url":"https://api.github.com/repos/SpineEventEngine/Lobby/statuses/a5a213d1534dd42e988c8a8eb6e3db4be99278eb","head":{"label":"SpineEventEngine:state-neutral-events","ref":"state-neutral-events","sha":"a5a213d1534dd42e988c8a8eb6e3db4be99278eb","user":{"login":"SpineEventEngine","id":12821626,"avatar_url":"https://avatars.githubusercontent.com/u/12821626?v=3","gravatar_id":"","url":"https://api.github.com/users/SpineEventEngine","html_url":"https://github.com/SpineEventEngine","followers_url":"https://api.github.com/users/SpineEventEngine/followers","following_url":"https://api.github.com/users/SpineEventEngine/following{/other_user}","gists_url":"https://api.github.com/users/SpineEventEngine/gists{/gist_id}","starred_url":"https://api.github.com/users/SpineEventEngine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpineEventEngine/subscriptions","organizations_url":"https://api.github.com/users/SpineEventEngine/orgs","repos_url":"https://api.github.com/users/SpineEventEngine/repos","events_url":"https://api.github.com/users/SpineEventEngine/events{/privacy}","received_events_url":"https://api.github.com/users/SpineEventEngine/received_events","type":"Organization","site_admin":false},"repo":{"id":45702464,"name":"Lobby","full_name":"SpineEventEngine/Lobby","owner":{"login":"SpineEventEngine","id":12821626,"avatar_url":"https://avatars.githubusercontent.com/u/12821626?v=3","gravatar_id":"","url":"https://api.github.com/users/SpineEventEngine","html_url":"https://github.com/SpineEventEngine","followers_url":"https://api.github.com/users/SpineEventEngine/followers","following_url":"https://api.github.com/users/SpineEventEngine/following{/other_user}","gists_url":"https://api.github.com/users/SpineEventEngine/gists{/gist_id}","starred_url":"https://api.github.com/users/SpineEventEngine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpineEventEngine/subscriptions","organizations_url":"https://api.github.com/users/SpineEventEngine/orgs","repos_url":"https://api.github.com/users/SpineEventEngine/repos","events_url":"https://api.github.com/users/SpineEventEngine/events{/privacy}","received_events_url":"https://api.github.com/users/SpineEventEngine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SpineEventEngine/Lobby","description":"A sample conference management application","fork":false,"url":"https://api.github.com/repos/SpineEventEngine/Lobby","forks_url":"https://api.github.com/repos/SpineEventEngine/Lobby/forks","keys_url":"https://api.github.com/repos/SpineEventEngine/Lobby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SpineEventEngine/Lobby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SpineEventEngine/Lobby/teams","hooks_url":"https://api.github.com/repos/SpineEventEngine/Lobby/hooks","issue_events_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/events{/number}","events_url":"https://api.github.com/repos/SpineEventEngine/Lobby/events","assignees_url":"https://api.github.com/repos/SpineEventEngine/Lobby/assignees{/user}","branches_url":"https://api.github.com/repos/SpineEventEngine/Lobby/branches{/branch}","tags_url":"https://api.github.com/repos/SpineEventEngine/Lobby/tags","blobs_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/refs{/sha}","trees_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SpineEventEngine/Lobby/statuses/{sha}","languages_url":"https://api.github.com/repos/SpineEventEngine/Lobby/languages","stargazers_url":"https://api.github.com/repos/SpineEventEngine/Lobby/stargazers","contributors_url":"https://api.github.com/repos/SpineEventEngine/Lobby/contributors","subscribers_url":"https://api.github.com/repos/SpineEventEngine/Lobby/subscribers","subscription_url":"https://api.github.com/repos/SpineEventEngine/Lobby/subscription","commits_url":"https://api.github.com/repos/SpineEventEngine/Lobby/commits{/sha}","git_commits_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/commits{/sha}","comments_url":"https://api.github.com/repos/SpineEventEngine/Lobby/comments{/number}","issue_comment_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/comments{/number}","contents_url":"https://api.github.com/repos/SpineEventEngine/Lobby/contents/{+path}","compare_url":"https://api.github.com/repos/SpineEventEngine/Lobby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SpineEventEngine/Lobby/merges","archive_url":"https://api.github.com/repos/SpineEventEngine/Lobby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SpineEventEngine/Lobby/downloads","issues_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues{/number}","pulls_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls{/number}","milestones_url":"https://api.github.com/repos/SpineEventEngine/Lobby/milestones{/number}","notifications_url":"https://api.github.com/repos/SpineEventEngine/Lobby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SpineEventEngine/Lobby/labels{/name}","releases_url":"https://api.github.com/repos/SpineEventEngine/Lobby/releases{/id}","created_at":"2015-11-06T19:23:38Z","updated_at":"2015-12-15T15:37:15Z","pushed_at":"2015-12-25T17:04:51Z","git_url":"git://github.com/SpineEventEngine/Lobby.git","ssh_url":"git@github.com:SpineEventEngine/Lobby.git","clone_url":"https://github.com/SpineEventEngine/Lobby.git","svn_url":"https://github.com/SpineEventEngine/Lobby","homepage":null,"size":376,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"SpineEventEngine:master","ref":"master","sha":"41d8fd738306b9f14ee3830853aa77816cf58617","user":{"login":"SpineEventEngine","id":12821626,"avatar_url":"https://avatars.githubusercontent.com/u/12821626?v=3","gravatar_id":"","url":"https://api.github.com/users/SpineEventEngine","html_url":"https://github.com/SpineEventEngine","followers_url":"https://api.github.com/users/SpineEventEngine/followers","following_url":"https://api.github.com/users/SpineEventEngine/following{/other_user}","gists_url":"https://api.github.com/users/SpineEventEngine/gists{/gist_id}","starred_url":"https://api.github.com/users/SpineEventEngine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpineEventEngine/subscriptions","organizations_url":"https://api.github.com/users/SpineEventEngine/orgs","repos_url":"https://api.github.com/users/SpineEventEngine/repos","events_url":"https://api.github.com/users/SpineEventEngine/events{/privacy}","received_events_url":"https://api.github.com/users/SpineEventEngine/received_events","type":"Organization","site_admin":false},"repo":{"id":45702464,"name":"Lobby","full_name":"SpineEventEngine/Lobby","owner":{"login":"SpineEventEngine","id":12821626,"avatar_url":"https://avatars.githubusercontent.com/u/12821626?v=3","gravatar_id":"","url":"https://api.github.com/users/SpineEventEngine","html_url":"https://github.com/SpineEventEngine","followers_url":"https://api.github.com/users/SpineEventEngine/followers","following_url":"https://api.github.com/users/SpineEventEngine/following{/other_user}","gists_url":"https://api.github.com/users/SpineEventEngine/gists{/gist_id}","starred_url":"https://api.github.com/users/SpineEventEngine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpineEventEngine/subscriptions","organizations_url":"https://api.github.com/users/SpineEventEngine/orgs","repos_url":"https://api.github.com/users/SpineEventEngine/repos","events_url":"https://api.github.com/users/SpineEventEngine/events{/privacy}","received_events_url":"https://api.github.com/users/SpineEventEngine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SpineEventEngine/Lobby","description":"A sample conference management application","fork":false,"url":"https://api.github.com/repos/SpineEventEngine/Lobby","forks_url":"https://api.github.com/repos/SpineEventEngine/Lobby/forks","keys_url":"https://api.github.com/repos/SpineEventEngine/Lobby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SpineEventEngine/Lobby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SpineEventEngine/Lobby/teams","hooks_url":"https://api.github.com/repos/SpineEventEngine/Lobby/hooks","issue_events_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/events{/number}","events_url":"https://api.github.com/repos/SpineEventEngine/Lobby/events","assignees_url":"https://api.github.com/repos/SpineEventEngine/Lobby/assignees{/user}","branches_url":"https://api.github.com/repos/SpineEventEngine/Lobby/branches{/branch}","tags_url":"https://api.github.com/repos/SpineEventEngine/Lobby/tags","blobs_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/refs{/sha}","trees_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SpineEventEngine/Lobby/statuses/{sha}","languages_url":"https://api.github.com/repos/SpineEventEngine/Lobby/languages","stargazers_url":"https://api.github.com/repos/SpineEventEngine/Lobby/stargazers","contributors_url":"https://api.github.com/repos/SpineEventEngine/Lobby/contributors","subscribers_url":"https://api.github.com/repos/SpineEventEngine/Lobby/subscribers","subscription_url":"https://api.github.com/repos/SpineEventEngine/Lobby/subscription","commits_url":"https://api.github.com/repos/SpineEventEngine/Lobby/commits{/sha}","git_commits_url":"https://api.github.com/repos/SpineEventEngine/Lobby/git/commits{/sha}","comments_url":"https://api.github.com/repos/SpineEventEngine/Lobby/comments{/number}","issue_comment_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/comments{/number}","contents_url":"https://api.github.com/repos/SpineEventEngine/Lobby/contents/{+path}","compare_url":"https://api.github.com/repos/SpineEventEngine/Lobby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SpineEventEngine/Lobby/merges","archive_url":"https://api.github.com/repos/SpineEventEngine/Lobby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SpineEventEngine/Lobby/downloads","issues_url":"https://api.github.com/repos/SpineEventEngine/Lobby/issues{/number}","pulls_url":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls{/number}","milestones_url":"https://api.github.com/repos/SpineEventEngine/Lobby/milestones{/number}","notifications_url":"https://api.github.com/repos/SpineEventEngine/Lobby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SpineEventEngine/Lobby/labels{/name}","releases_url":"https://api.github.com/repos/SpineEventEngine/Lobby/releases{/id}","created_at":"2015-11-06T19:23:38Z","updated_at":"2015-12-15T15:37:15Z","pushed_at":"2015-12-25T17:04:51Z","git_url":"git://github.com/SpineEventEngine/Lobby.git","ssh_url":"git@github.com:SpineEventEngine/Lobby.git","clone_url":"https://github.com/SpineEventEngine/Lobby.git","svn_url":"https://github.com/SpineEventEngine/Lobby","homepage":null,"size":376,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10"},"html":{"href":"https://github.com/SpineEventEngine/Lobby/pull/10"},"issue":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/10"},"comments":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/SpineEventEngine/Lobby/statuses/a5a213d1534dd42e988c8a8eb6e3db4be99278eb"}}}}