/
FileInfo.java
134 lines (107 loc) · 3.49 KB
/
FileInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package reposense.authorship.model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import reposense.model.Author;
import reposense.model.FileType;
import reposense.util.SystemUtil;
/**
* Stores the path to the file, the list of {@code LineInfo} for each line in the file and file size.
*/
public class FileInfo {
private final String path;
private final ArrayList<LineInfo> lines;
private FileType fileType;
private long fileSize;
private boolean exceedsFileLimit = false;
private boolean isFileAnalyzed = true;
public FileInfo(String path) {
if (SystemUtil.isWindows()) {
// Only replace \ to / in Windows paths, so it does not interferes with a correct Unix path
path = path.replace('\\', '/');
}
this.path = path;
lines = new ArrayList<>();
}
/**
* Returns true if none of the {@link Author} in {@code listedAuthors} contributed to this file.
*/
public boolean isAllAuthorsIgnored(List<Author> listedAuthors) {
return lines.stream().noneMatch(line -> listedAuthors.contains(line.getAuthor()));
}
public LineInfo getLine(int num) {
return lines.get(num - 1);
}
public void addLine(LineInfo line) {
lines.add(line);
}
public int getNumOfLines() {
return lines.size();
}
public ArrayList<LineInfo> getLines() {
return lines;
}
public String getPath() {
return path;
}
public FileType getFileType() {
return fileType;
}
public void setFileType(FileType fileType) {
this.fileType = fileType;
}
public long getFileSize() {
return this.fileSize;
}
public void setFileSize(long fileSize) {
this.fileSize = fileSize;
}
public boolean isFileAnalyzed() {
return isFileAnalyzed;
}
public void setFileAnalyzed(boolean isFileAnalyzed) {
this.isFileAnalyzed = isFileAnalyzed;
}
public boolean exceedsFileLimit() {
return exceedsFileLimit;
}
public void setExceedsSizeLimit(boolean exceedsFileLimit) {
this.exceedsFileLimit = exceedsFileLimit;
}
/**
* Sets the {@code author} of the {@link LineInfo} in {@code lineNumber} for this {@link FileInfo}.
*/
public void setLineAuthor(int lineNumber, Author author) {
lines.get(lineNumber).setAuthor(author);
}
/**
* Sets the {@code lastModifiedDate} of the {@link LineInfo} in {@code lineNumber} for this {@link FileInfo}.
*/
public void setLineLastModifiedDate(int lineNumber, LocalDateTime lastModifiedDate) {
lines.get(lineNumber).setLastModifiedDate(lastModifiedDate);
}
/**
* Returns true if the {@link LineInfo} in {@code lineNumber} index is being tracked.
*/
public boolean isFileLineTracked(int lineNumber) {
return getLines().get(lineNumber).isTracked();
}
/**
* Sets whether {@code lineNumber} is fully credited to its {@code author}.
*/
public void setIsFullCredit(int lineNumber, boolean isFullCredit) {
lines.get(lineNumber).setIsFullCredit(isFullCredit);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof FileInfo)) {
return false;
}
FileInfo otherFileInfo = (FileInfo) other;
return path.equals(otherFileInfo.path)
&& lines.equals(otherFileInfo.lines);
}
}