mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-23 07:52:13 +01:00
Sort files with an upper case letter first
This commit is contained in:
@@ -67,7 +67,7 @@ public interface BrowseCommand
|
||||
default <T> void sort(List<T> entries, Function<T, Boolean> isDirectory, Function<T, String> nameOf) {
|
||||
entries.sort((e1, e2) -> {
|
||||
if (isDirectory.apply(e1).equals(isDirectory.apply(e2))) {
|
||||
return nameOf.apply(e1).toLowerCase(Locale.ENGLISH).compareTo(nameOf.apply(e2).toLowerCase(Locale.ENGLISH));
|
||||
return nameOf.apply(e1).compareTo(nameOf.apply(e2));
|
||||
} else if (isDirectory.apply(e1)) {
|
||||
return -1;
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static sonia.scm.repository.spi.BrowseCommandTest.Entry.d;
|
||||
import static sonia.scm.repository.spi.BrowseCommandTest.Entry.f;
|
||||
|
||||
class BrowseCommandTest implements BrowseCommand {
|
||||
|
||||
@Test
|
||||
void shouldSort() {
|
||||
List<Entry> entries = asList(
|
||||
f("b.txt"),
|
||||
f("a.txt"),
|
||||
f("Dockerfile"),
|
||||
f(".gitignore"),
|
||||
d("src"),
|
||||
f("README")
|
||||
);
|
||||
|
||||
sort(entries, Entry::isDirecotry, Entry::getName);
|
||||
|
||||
assertThat(entries).extracting("name")
|
||||
.containsExactly(
|
||||
"src",
|
||||
".gitignore",
|
||||
"Dockerfile",
|
||||
"README",
|
||||
"a.txt",
|
||||
"b.txt"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
static class Entry {
|
||||
private final String name;
|
||||
private final boolean direcotry;
|
||||
|
||||
static Entry f(String name) {
|
||||
return new Entry(name, false);
|
||||
}
|
||||
|
||||
static Entry d(String name) {
|
||||
return new Entry(name, true);
|
||||
}
|
||||
|
||||
public Entry(String name, boolean direcotry) {
|
||||
this.name = name;
|
||||
this.direcotry = direcotry;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isDirecotry() {
|
||||
return direcotry;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user