Skip to content

Commit

Permalink
Merge pull request #2719 from owncloud/feature/sortBySizeMix
Browse files Browse the repository at this point in the history
Sort by size mixing files and folders
  • Loading branch information
davigonz authored Nov 26, 2019
2 parents 9d123cc + d846908 commit 1aecc17
Showing 1 changed file with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

/**
Expand Down Expand Up @@ -242,14 +241,12 @@ public static Vector<OCFile> sortByDate(Vector<OCFile> files, boolean isAscendin
val = -1;
}

Collections.sort(files, new Comparator<OCFile>() {
public int compare(OCFile o1, OCFile o2) {
if (o1.getModificationTimestamp() == 0 || o2.getModificationTimestamp() == 0) {
return 0;
} else {
Long obj1 = o1.getModificationTimestamp();
return val * obj1.compareTo(o2.getModificationTimestamp());
}
Collections.sort(files, (ocFile1, ocFile2) -> {
if (ocFile1.getModificationTimestamp() == 0 || ocFile2.getModificationTimestamp() == 0) {
return 0;
} else {
Long obj1 = ocFile1.getModificationTimestamp();
return val * obj1.compareTo(ocFile2.getModificationTimestamp());
}
});

Expand All @@ -267,21 +264,12 @@ public static Vector<OCFile> sortBySize(Vector<OCFile> files, boolean isAscendin
val = -1;
}

Collections.sort(files, new Comparator<OCFile>() {
public int compare(OCFile o1, OCFile o2) {
if (o1.isFolder() && o2.isFolder()) {
Long obj1 = o1.getFileLength();
return val * obj1.compareTo(o2.getFileLength());
} else if (o1.isFolder()) {
return -1;
} else if (o2.isFolder()) {
return 1;
} else if (o1.getFileLength() == 0 || o2.getFileLength() == 0) {
return 0;
} else {
Long obj1 = o1.getFileLength();
return val * obj1.compareTo(o2.getFileLength());
}
Collections.sort(files, (ocFile1, ocFile2) -> {
if (ocFile1.getFileLength() == 0 || ocFile2.getFileLength() == 0) {
return 0;
} else {
Long obj1 = ocFile1.getFileLength();
return val * obj1.compareTo(ocFile2.getFileLength());
}
});

Expand All @@ -301,17 +289,15 @@ public static Vector<OCFile> sortByName(Vector<OCFile> files, boolean isAscendin
val = -1;
}

Collections.sort(files, new Comparator<OCFile>() {
public int compare(OCFile o1, OCFile o2) {
if (o1.isFolder() && o2.isFolder()) {
return val * new AlphanumComparator().compare(o1, o2);
} else if (o1.isFolder()) {
return -1;
} else if (o2.isFolder()) {
return 1;
}
return val * new AlphanumComparator().compare(o1, o2);
Collections.sort(files, (ocFile1, ocFile2) -> {
if (ocFile1.isFolder() && ocFile2.isFolder()) {
return val * new AlphanumComparator().compare(ocFile1, ocFile2);
} else if (ocFile1.isFolder()) {
return -1;
} else if (ocFile2.isFolder()) {
return 1;
}
return val * new AlphanumComparator().compare(ocFile1, ocFile2);
});

return files;
Expand Down

0 comments on commit 1aecc17

Please sign in to comment.