mirror of
https://github.com/anthonyraymond/joal.git
synced 2024-09-20 07:16:26 +08:00
Fix #89.
Using `.sorted((o1, o2) -> ThreadLocalRandom.current().nextInt(-1, 2))` on a stream causes *java.lang.IllegalArgumentException: Comparison method violates its general contract!*. Because the ordering is not determinist.
This commit is contained in:
parent
e05d419195
commit
a039ffac23
|
@ -16,7 +16,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static java.util.Optional.ofNullable;
|
import static java.util.Optional.ofNullable;
|
||||||
|
@ -120,7 +120,10 @@ public class TorrentFileProvider extends FileAlterationListenerAdaptor {
|
||||||
|
|
||||||
return this.torrentFiles.values().stream()
|
return this.torrentFiles.values().stream()
|
||||||
.filter(torrent -> !unwantedTorrents.contains(torrent.getTorrentInfoHash()))
|
.filter(torrent -> !unwantedTorrents.contains(torrent.getTorrentInfoHash()))
|
||||||
.sorted((o1, o2) -> ThreadLocalRandom.current().nextInt(-1, 2))
|
.collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
|
||||||
|
Collections.shuffle(collected);
|
||||||
|
return collected.stream();
|
||||||
|
}))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseThrow(() -> new NoMoreTorrentsFileAvailableException("No more torrent file available."));
|
.orElseThrow(() -> new NoMoreTorrentsFileAvailableException("No more torrent file available."));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue