1   /*
2    * Copyright 2026 LY Corporation
3    *
4    * LY 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.server.storage.repository;
18  
19  import java.util.Objects;
20  
21  import com.google.common.base.MoreObjects;
22  
23  import com.linecorp.centraldogma.common.Revision;
24  
25  final class DefaultHasRevision<T> implements HasRevision<T> {
26  
27      private final T object;
28      private final Revision revision;
29  
30      DefaultHasRevision(T object, Revision revision) {
31          this.object = object;
32          this.revision = revision;
33      }
34  
35      @Override
36      public Revision revision() {
37          return revision;
38      }
39  
40      @Override
41      public T object() {
42          return object;
43      }
44  
45      @Override
46      public boolean equals(Object o) {
47          if (!(o instanceof DefaultHasRevision)) {
48              return false;
49          }
50          final DefaultHasRevision<?> that = (DefaultHasRevision<?>) o;
51          return object.equals(that.object) && revision.equals(that.revision);
52      }
53  
54      @Override
55      public int hashCode() {
56          return Objects.hash(object, revision);
57      }
58  
59      @Override
60      public String toString() {
61          return MoreObjects.toStringHelper(this)
62                            .add("object", object)
63                            .add("revision", revision)
64                            .toString();
65      }
66  }