Line data Source code
1 : // Copyright (C) 2014 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.extensions.common; 16 : 17 : import com.google.gerrit.extensions.client.ChangeKind; 18 : import java.sql.Timestamp; 19 : import java.time.Instant; 20 : import java.util.Map; 21 : import java.util.Objects; 22 : 23 : public class RevisionInfo { 24 : // ActionJson#copy(List, RevisionInfo) must be adapted if new fields are added that are not 25 : // protected by any ListChangesOption. 26 : public transient boolean isCurrent; 27 : public ChangeKind kind; 28 : public int _number; 29 : 30 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 31 : // Instant 32 : public Timestamp created; 33 : 34 : public AccountInfo uploader; 35 : public String ref; 36 : public Map<String, FetchInfo> fetch; 37 : public CommitInfo commit; 38 : public Map<String, FileInfo> files; 39 : public Map<String, ActionInfo> actions; 40 : public String commitWithFooters; 41 : public PushCertificateInfo pushCertificate; 42 : public String description; 43 : 44 104 : public RevisionInfo() {} 45 : 46 1 : public RevisionInfo(String ref) { 47 1 : this.ref = ref; 48 1 : } 49 : 50 1 : public RevisionInfo(String ref, int number) { 51 1 : this.ref = ref; 52 1 : _number = number; 53 1 : } 54 : 55 1 : public RevisionInfo(AccountInfo uploader) { 56 1 : this.uploader = uploader; 57 1 : } 58 : 59 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 60 : // Instant 61 : @SuppressWarnings("JdkObsolete") 62 : public void setCreated(Instant date) { 63 103 : this.created = Timestamp.from(date); 64 103 : } 65 : 66 : @Override 67 : public boolean equals(Object o) { 68 2 : if (o instanceof RevisionInfo) { 69 1 : RevisionInfo revisionInfo = (RevisionInfo) o; 70 1 : return isCurrent == revisionInfo.isCurrent 71 1 : && Objects.equals(kind, revisionInfo.kind) 72 : && _number == revisionInfo._number 73 1 : && Objects.equals(created, revisionInfo.created) 74 1 : && Objects.equals(uploader, revisionInfo.uploader) 75 1 : && Objects.equals(ref, revisionInfo.ref) 76 1 : && Objects.equals(fetch, revisionInfo.fetch) 77 1 : && Objects.equals(commit, revisionInfo.commit) 78 1 : && Objects.equals(files, revisionInfo.files) 79 1 : && Objects.equals(actions, revisionInfo.actions) 80 1 : && Objects.equals(commitWithFooters, revisionInfo.commitWithFooters) 81 1 : && Objects.equals(pushCertificate, revisionInfo.pushCertificate) 82 1 : && Objects.equals(description, revisionInfo.description); 83 : } 84 1 : return false; 85 : } 86 : 87 : @Override 88 : public int hashCode() { 89 0 : return Objects.hash( 90 0 : isCurrent, 91 : kind, 92 0 : _number, 93 : created, 94 : uploader, 95 : ref, 96 : fetch, 97 : commit, 98 : files, 99 : actions, 100 : commitWithFooters, 101 : pushCertificate, 102 : description); 103 : } 104 : }