1   /*
2    * Copyright 2021 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server.command;
17  
18  import static java.util.Objects.requireNonNull;
19  
20  import java.util.List;
21  
22  import com.google.common.base.MoreObjects;
23  import com.google.common.base.Objects;
24  import com.google.common.collect.ImmutableList;
25  
26  import com.linecorp.centraldogma.common.Change;
27  import com.linecorp.centraldogma.common.Revision;
28  
29  /**
30   * Result of a {@link NormalizingPushCommand} commit.
31   */
32  public final class CommitResult {
33  
34      private final Revision revision;
35      private final List<Change<?>> changes;
36  
37      /**
38       * Returns a {@link CommitResult}.
39       */
40      public static CommitResult of(Revision revision, Iterable<Change<?>> changes) {
41          return new CommitResult(revision, changes);
42      }
43  
44      private CommitResult(Revision revision, Iterable<Change<?>> changes) {
45          this.revision = requireNonNull(revision, "revision");
46          this.changes = ImmutableList.copyOf(requireNonNull(changes, "changes"));
47      }
48  
49      /**
50       * Returns the {@link Revision}.
51       */
52      public Revision revision() {
53          return revision;
54      }
55  
56      /**
57       * Returns the list of {@link Change}s.
58       */
59      public List<Change<?>> changes() {
60          return changes;
61      }
62  
63      @Override
64      public boolean equals(Object o) {
65          if (this == o) {
66              return true;
67          }
68          if (!(o instanceof CommitResult)) {
69              return false;
70          }
71          final CommitResult that = (CommitResult) o;
72          return Objects.equal(revision, that.revision) &&
73                 Objects.equal(changes, that.changes);
74      }
75  
76      @Override
77      public int hashCode() {
78          return Objects.hashCode(revision, changes);
79      }
80  
81      @Override
82      public String toString() {
83          return MoreObjects.toStringHelper(this)
84                            .add("revision", revision)
85                            .add("changes", changes)
86                            .toString();
87      }
88  }