1   /*
2    * Copyright 2017 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  
17  package com.linecorp.centraldogma.client;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import com.google.common.base.MoreObjects;
22  
23  import com.linecorp.centraldogma.common.Revision;
24  
25  /**
26   * An immutable holder of repository information.
27   */
28  public final class RepositoryInfo {
29  
30      // TODO(trustin): Add createdAt and creator property once we remove the Thrift API.
31  
32      private final String name;
33      private final Revision headRevision;
34  
35      /**
36       * Creates a new instance with the specified repository name and the latest {@link Revision} of the
37       * repository.
38       */
39      public RepositoryInfo(String name, Revision headRevision) {
40          this.name = requireNonNull(name, "name");
41          this.headRevision = requireNonNull(headRevision, "headRevision");
42      }
43  
44      /**
45       * Returns the name of the repository.
46       */
47      public String name() {
48          return name;
49      }
50  
51      /**
52       * Returns the latest {@link Revision} of the repository.
53       */
54      public Revision headRevision() {
55          return headRevision;
56      }
57  
58      @Override
59      public boolean equals(Object o) {
60          if (this == o) {
61              return true;
62          }
63  
64          if (!(o instanceof RepositoryInfo)) {
65              return false;
66          }
67  
68          final RepositoryInfo that = (RepositoryInfo) o;
69          return name.equals(that.name) && headRevision.equals(that.headRevision);
70      }
71  
72      @Override
73      public int hashCode() {
74          return name.hashCode() * 31 + headRevision.hashCode();
75      }
76  
77      @Override
78      public String toString() {
79          return MoreObjects.toStringHelper(this)
80                            .add("name", name)
81                            .add("headRevision", headRevision)
82                            .toString();
83      }
84  }