5661 clean up FileGroup class to encapsulate fields

This commit is contained in:
William Schaefer 2019-12-04 15:46:10 -05:00
parent 97e1cb34a2
commit a035308176

View File

@ -52,11 +52,11 @@ class FileGroup implements Comparable<FileGroup> {
* @param file The ResultFile to add to the FileGroup * @param file The ResultFile to add to the FileGroup
*/ */
void addFile(ResultFile file) { void addFile(ResultFile file) {
if (files.contains(file)) { if (getFiles().contains(file)) {
ResultFile existingCopy = files.get(files.indexOf(file)); //get the copy of this which exists in the list ResultFile existingCopy = getFiles().get(getFiles().indexOf(file)); //get the copy of this which exists in the list
existingCopy.addDuplicate(file.getFirstInstance()); existingCopy.addDuplicate(file.getFirstInstance());
} else { } else {
files.add(file); getFiles().add(file);
} }
} }
@ -84,14 +84,14 @@ class FileGroup implements Comparable<FileGroup> {
* @return List of abstract files * @return List of abstract files
*/ */
List<ResultFile> getAbstractFiles() { List<ResultFile> getAbstractFiles() {
return Collections.unmodifiableList(files); return Collections.unmodifiableList(getFiles());
} }
/** /**
* Sort all the files in the group * Sort all the files in the group
*/ */
void sortFiles(FileSorter sorter) { void sortFiles(FileSorter sorter) {
Collections.sort(files, sorter); Collections.sort(getFiles(), sorter);
} }
/** /**
@ -100,7 +100,7 @@ class FileGroup implements Comparable<FileGroup> {
* @return List of ResultFile objects * @return List of ResultFile objects
*/ */
List<ResultFile> getResultFiles() { List<ResultFile> getResultFiles() {
return Collections.unmodifiableList(files); return Collections.unmodifiableList(getFiles());
} }
/** /**
@ -133,7 +133,7 @@ class FileGroup implements Comparable<FileGroup> {
* @return -1 if group1 should be displayed before group2, 1 otherwise * @return -1 if group1 should be displayed before group2, 1 otherwise
*/ */
private static int compareGroupsByGroupKey(FileGroup group1, FileGroup group2) { private static int compareGroupsByGroupKey(FileGroup group1, FileGroup group2) {
return group1.groupKey.compareTo(group2.groupKey); return group1.getGroupKey().compareTo(group2.getGroupKey());
} }
/** /**
@ -146,8 +146,8 @@ class FileGroup implements Comparable<FileGroup> {
* @return -1 if group1 should be displayed before group2, 1 otherwise * @return -1 if group1 should be displayed before group2, 1 otherwise
*/ */
private static int compareGroupsBySize(FileGroup group1, FileGroup group2) { private static int compareGroupsBySize(FileGroup group1, FileGroup group2) {
if (group1.files.size() != group2.files.size()) { if (group1.getFiles().size() != group2.getFiles().size()) {
return -1 * Long.compare(group1.files.size(), group2.files.size()); // High to low return -1 * Long.compare(group1.getFiles().size(), group2.getFiles().size()); // High to low
} else { } else {
// If the groups have the same size, fall through to the BY_GROUP_KEY sorting // If the groups have the same size, fall through to the BY_GROUP_KEY sorting
return compareGroupsByGroupKey(group1, group2); return compareGroupsByGroupKey(group1, group2);
@ -162,4 +162,11 @@ class FileGroup implements Comparable<FileGroup> {
BY_GROUP_KEY // Sort using the group key (for example, if grouping by size sort from largest to smallest value) BY_GROUP_KEY // Sort using the group key (for example, if grouping by size sort from largest to smallest value)
} }
/**
* @return the files
*/
List<ResultFile> getFiles() {
return Collections.unmodifiableList(files);
}
} }