• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oracle / opengrok / #3728

30 Nov 2023 04:39PM UTC coverage: 74.811% (-1.1%) from 75.91%
#3728

push

vladak
update Tomcat to 10.1.16

fixes #4492

43834 of 58593 relevant lines covered (74.81%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.49
/opengrok-indexer/src/main/java/org/opengrok/indexer/history/AnnotationData.java
1
/*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License (the "License").
6
 * You may not use this file except in compliance with the License.
7
 *
8
 * See LICENSE.txt included in this distribution for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing Covered Code, include this CDDL HEADER in each
12
 * file and include the License file at LICENSE.txt.
13
 * If applicable, add the following below this CDDL HEADER, with the
14
 * fields enclosed by brackets "[]" replaced with your own identifying
15
 * information: Portions Copyright [yyyy] [name of copyright owner]
16
 *
17
 * CDDL HEADER END
18
 */
19

20
/*
21
 * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
22
 * Portions Copyright (c) 2023, Ric Harris <harrisric@users.noreply.github.com>.
23
 */
24
package org.opengrok.indexer.history;
25

26
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
27
import org.jetbrains.annotations.TestOnly;
28

29
import java.io.File;
30
import java.io.Serializable;
31
import java.util.ArrayList;
32
import java.util.HashSet;
33
import java.util.List;
34
import java.util.Objects;
35
import java.util.Optional;
36
import java.util.Set;
37
import java.util.stream.Collectors;
38

39
/**
40
 * Holds serializable content for {@link Annotation}.
41
 */
42
@JsonPropertyOrder({"revision", "filename"})
43
public class AnnotationData implements Serializable {
44

45
    private static final long serialVersionUID = -1;
46

47
    // for serialization
48
    public AnnotationData() {
1✔
49
    }
1✔
50

51
    public AnnotationData(String filename) {
1✔
52
        this.filename = filename;
1✔
53
    }
1✔
54

55
    private List<AnnotationLine> annotationLines = new ArrayList<>();
1✔
56
    private int widestRevision;
57
    private int widestAuthor;
58
    private String filename;
59
    /**
60
     * The revision it was generated for is used for staleness check in {@link FileAnnotationCache#get(File, String)}.
61
     * Storing it in the filename would not work well ({@link org.opengrok.indexer.util.TandemPath}
62
     * shortening with very long filenames), on the other hand it is necessary to deserialize the object
63
     * to tell whether it is stale.
64
     */
65
    String revision;
66

67
    public List<AnnotationLine> getLines() {
68
        return annotationLines;
1✔
69
    }
70

71
    public void setLines(List<AnnotationLine> annotationLines) {
72
        this.annotationLines = annotationLines;
1✔
73
    }
1✔
74

75
    // For serialization.
76
    public void setWidestRevision(int widestRevision) {
77
        this.widestRevision = widestRevision;
1✔
78
    }
1✔
79

80
    // For serialization.
81
    public void setWidestAuthor(int widestAuthor) {
82
        this.widestAuthor = widestAuthor;
1✔
83
    }
1✔
84

85
    /**
86
     * Gets the author who last modified the specified line.
87
     *
88
     * @param line line number (counting from 1)
89
     * @return author, or an empty string if there is no information about the
90
     * specified line
91
     */
92
    public String getAuthor(int line) {
93
        try {
94
            return annotationLines.get(line - 1).getAuthor();
1✔
95
        } catch (IndexOutOfBoundsException e) {
1✔
96
            return "";
1✔
97
        }
98
    }
99

100
    /**
101
     * Gets the revision for the last change to the specified line.
102
     *
103
     * @param line line number (counting from 1)
104
     * @return revision string, or an empty string if there is no information
105
     * about the specified line
106
     */
107
    public String getRevision(int line) {
108
        try {
109
            return annotationLines.get(line - 1).getRevision();
1✔
110
        } catch (IndexOutOfBoundsException e) {
1✔
111
            return "";
1✔
112
        }
113
    }
114

115
    /**
116
     * Gets the representation of the revision to be used for display purposes, which may be abbreviated, for the last change to the specified line.
117
     *
118
     * @param line line number (counting from 1)
119
     * @return revision string, or an empty string if there is no information
120
     * about the specified line
121
     */
122
    public String getRevisionForDisplay(int line) {
123
        try {
124
            return annotationLines.get(line - 1).getDisplayRevision();
1✔
125
        } catch (IndexOutOfBoundsException e) {
1✔
126
            return "";
1✔
127
        }
128
    }
129

130

131
    /**
132
     * Gets the enabled state for the last change to the specified line.
133
     *
134
     * @param line line number (counting from 1)
135
     * @return true if the xref for this revision is enabled, false otherwise
136
     */
137
    public boolean isEnabled(int line) {
138
        try {
139
            return annotationLines.get(line - 1).isEnabled();
1✔
140
        } catch (IndexOutOfBoundsException e) {
1✔
141
            return false;
1✔
142
        }
143
    }
144

145
    public void setRevision(String revision) {
146
        this.revision = revision;
1✔
147
    }
1✔
148

149
    /**
150
     * @return revision this annotation was generated for
151
     */
152
    public String getRevision() {
153
        return revision;
1✔
154
    }
155

156
    public void setFilename(String filename) {
157
        this.filename = filename;
1✔
158
    }
1✔
159

160
    public String getFilename() {
161
        return filename;
1✔
162
    }
163

164
    /**
165
     * Returns the size of the file (number of lines).
166
     *
167
     * @return number of lines
168
     */
169
    public int size() {
170
        return annotationLines.size();
1✔
171
    }
172

173
    /**
174
     * Returns the widest revision string in the file (used for pretty
175
     * printing).
176
     *
177
     * @return number of characters in the widest revision string
178
     */
179
    public int getWidestRevision() {
180
        return widestRevision;
1✔
181
    }
182

183
    /**
184
     * Returns the widest author name in the file (used for pretty printing).
185
     *
186
     * @return number of characters in the widest author string
187
     */
188
    public int getWidestAuthor() {
189
        return widestAuthor;
1✔
190
    }
191

192
    /**
193
     * Adds a line to the file.
194
     * @param annotationLine {@link AnnotationLine} instance
195
     */
196
    void addLine(final AnnotationLine annotationLine) {
197
        annotationLines.add(annotationLine);
1✔
198
        widestRevision = Math.max(widestRevision, annotationLine.getDisplayRevision().length());
1✔
199
        widestAuthor = Math.max(widestAuthor, annotationLine.getAuthor().length());
1✔
200
    }
1✔
201

202
    /**
203
     * @param revision revision number
204
     * @param author author name
205
     * @param enabled whether the line is enabled
206
     * @param displayRevision a specialised revision number of display purposes. Can be null in which case the revision number will be used.
207
     * @see #addLine(AnnotationLine)
208
     */
209
    void addLine(String revision, String author, boolean enabled, String displayRevision) {
210
        final AnnotationLine annotationLine = new AnnotationLine(revision, author, enabled, displayRevision);
1✔
211
        addLine(annotationLine);
1✔
212
    }
1✔
213

214
    /**
215
     * Gets all revisions that are in use, first is the lowest one (sorted using natural order).
216
     *
217
     * @return set of all revisions for given file
218
     */
219
    public Set<String> getRevisions() {
220
        Set<String> ret = new HashSet<>();
1✔
221
        for (AnnotationLine ln : annotationLines) {
1✔
222
            ret.add(ln.getRevision());
1✔
223
        }
1✔
224
        return ret;
1✔
225
    }
226

227
    @TestOnly
228
    Set<String> getAuthors() {
229
        return annotationLines.stream().map(AnnotationLine::getAuthor).collect(Collectors.toSet());
×
230
    }
231

232
    @Override
233
    public int hashCode() {
234
        return Objects.hash(annotationLines, filename);
×
235
    }
236

237
    @Override
238
    public boolean equals(Object obj) {
239
        return Optional.ofNullable(obj)
1✔
240
                .filter(other -> getClass() == other.getClass())
1✔
241
                .map(AnnotationData.class::cast)
1✔
242
                .filter(other -> Objects.deepEquals(getLines(), other.getLines()))
1✔
243
                .filter(other -> Objects.equals(getFilename(), other.getFilename()))
1✔
244
                .filter(other -> Objects.equals(getWidestAuthor(), other.getWidestAuthor()))
1✔
245
                .filter(other -> Objects.equals(getWidestRevision(), other.getWidestRevision()))
1✔
246
                .filter(other -> Objects.equals(getRevision(), other.getRevision()))
1✔
247
                .isPresent();
1✔
248
    }
249
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc