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.common.collect.Iterables; 18 : import java.sql.Timestamp; 19 : import java.time.Instant; 20 : import java.util.Collection; 21 : import java.util.Objects; 22 : 23 : /** Represent {@link com.google.gerrit.entities.ChangeMessage} in the REST API. */ 24 : public class ChangeMessageInfo { 25 : public String id; 26 : public String tag; 27 : public AccountInfo author; 28 : public AccountInfo realAuthor; 29 : 30 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 31 : // Instant 32 : public Timestamp date; 33 : 34 : public String message; 35 : public Collection<AccountInfo> accountsInMessage; 36 : public Integer _revisionNumber; 37 : 38 103 : public ChangeMessageInfo() {} 39 : 40 1 : public ChangeMessageInfo(String message) { 41 1 : this.message = message; 42 1 : } 43 : 44 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 45 : // Instant 46 : @SuppressWarnings("JdkObsolete") 47 : public void setDate(Instant when) { 48 102 : date = Timestamp.from(when); 49 102 : } 50 : 51 : @Override 52 : public boolean equals(Object o) { 53 2 : if (o instanceof ChangeMessageInfo) { 54 2 : ChangeMessageInfo cmi = (ChangeMessageInfo) o; 55 2 : return Objects.equals(id, cmi.id) 56 2 : && Objects.equals(tag, cmi.tag) 57 2 : && Objects.equals(author, cmi.author) 58 2 : && Objects.equals(realAuthor, cmi.realAuthor) 59 2 : && Objects.equals(date, cmi.date) 60 2 : && Objects.equals(message, cmi.message) 61 : && ((accountsInMessage == null && cmi.accountsInMessage == null) 62 : || (accountsInMessage != null 63 : && cmi.accountsInMessage != null 64 2 : && Iterables.elementsEqual(accountsInMessage, cmi.accountsInMessage))) 65 2 : && Objects.equals(_revisionNumber, cmi._revisionNumber); 66 : } 67 0 : return false; 68 : } 69 : 70 : @Override 71 : public int hashCode() { 72 1 : return Objects.hash( 73 : id, tag, author, realAuthor, date, message, accountsInMessage, _revisionNumber); 74 : } 75 : 76 : @Override 77 : public String toString() { 78 0 : return "ChangeMessageInfo{" 79 : + "id=" 80 : + id 81 : + ", tag=" 82 : + tag 83 : + ", author=" 84 : + author 85 : + ", realAuthor=" 86 : + realAuthor 87 : + ", date=" 88 : + date 89 : + ", _revisionNumber" 90 : + _revisionNumber 91 : + ", message=[" 92 : + message 93 : + "], accountsForTemplate=" 94 : + accountsInMessage 95 : + "}"; 96 : } 97 : }