Line data Source code
1 : // Copyright (C) 2016 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.entities;
16 :
17 : import java.time.Instant;
18 : import java.util.List;
19 : import java.util.Map;
20 : import java.util.Objects;
21 :
22 : public final class RobotComment extends Comment {
23 : public String robotId;
24 : public String robotRunId;
25 : public String url;
26 : public Map<String, String> properties;
27 : public List<FixSuggestion> fixSuggestions;
28 :
29 : public RobotComment(
30 : Key key,
31 : Account.Id author,
32 : Instant writtenOn,
33 : short side,
34 : String message,
35 : String serverId,
36 : String robotId,
37 : String robotRunId) {
38 9 : super(key, author, writtenOn, side, message, serverId);
39 9 : this.robotId = robotId;
40 9 : this.robotRunId = robotRunId;
41 9 : }
42 :
43 : @Override
44 : public int getApproximateSize() {
45 8 : int approximateSize =
46 8 : super.getCommentFieldApproximateSize() + nullableLength(robotId, robotRunId, url);
47 8 : approximateSize +=
48 8 : properties != null
49 3 : ? properties.entrySet().stream()
50 3 : .mapToInt(entry -> nullableLength(entry.getKey(), entry.getValue()))
51 3 : .sum()
52 8 : : 0;
53 8 : approximateSize +=
54 8 : fixSuggestions != null
55 7 : ? fixSuggestions.stream().mapToInt(FixSuggestion::getApproximateSize).sum()
56 8 : : 0;
57 8 : return approximateSize;
58 : }
59 :
60 : @Override
61 : public String toString() {
62 0 : return toStringHelper()
63 0 : .add("robotId", robotId)
64 0 : .add("robotRunId", robotRunId)
65 0 : .add("url", url)
66 0 : .add("properties", Objects.toString(properties, ""))
67 0 : .add("fixSuggestions", Objects.toString(fixSuggestions, ""))
68 0 : .toString();
69 : }
70 :
71 : @Override
72 : public boolean equals(Object o) {
73 1 : if (!(o instanceof RobotComment)) {
74 0 : return false;
75 : }
76 1 : RobotComment c = (RobotComment) o;
77 1 : return super.equals(o)
78 0 : && Objects.equals(robotId, c.robotId)
79 0 : && Objects.equals(robotRunId, c.robotRunId)
80 0 : && Objects.equals(url, c.url)
81 0 : && Objects.equals(properties, c.properties)
82 1 : && Objects.equals(fixSuggestions, c.fixSuggestions);
83 : }
84 :
85 : @Override
86 : public int hashCode() {
87 9 : return Objects.hash(super.hashCode(), robotId, robotRunId, url, properties, fixSuggestions);
88 : }
89 : }
|