Updated MPCModule to return a SortedSet and switched collector

See: https://github.com/cryptomator/cryptomator/pull/1307#discussion_r474452898
This commit is contained in:
JaniruTEC
2020-09-28 23:34:47 +02:00
parent d5b8996a39
commit 9657a13912
4 changed files with 15 additions and 11 deletions
@@ -1,6 +1,6 @@
package org.cryptomator.common.mountpoint;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
@@ -8,7 +8,9 @@ import dagger.multibindings.IntoSet;
import org.cryptomator.common.vaults.PerVault;
import javax.inject.Named;
import java.util.Comparator;
import java.util.Set;
import java.util.SortedSet;
/**
* Dagger-Module for {@link MountPointChooser MountPointChoosers.}<br>
@@ -42,8 +44,8 @@ public abstract class MountPointChooserModule {
@Provides
@PerVault
@Named("orderedValidMountPointChoosers")
public static Set<MountPointChooser> provideOrderedValidMountPointChoosers(Set<MountPointChooser> choosers) {
//Sorted Set
return choosers.stream().sorted().filter(MountPointChooser::isApplicable).collect(ImmutableSet.toImmutableSet());
public static SortedSet<MountPointChooser> provideOrderedValidMountPointChoosers(Set<MountPointChooser> choosers) {
//The natural order is defined by MountPointChooser#compareTo
return choosers.stream().filter(MountPointChooser::isApplicable).collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder()));
}
}
@@ -7,11 +7,11 @@ import org.cryptomator.common.mountpoint.MountPointChooser;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
public abstract class AbstractVolume implements Volume {
private final Set<MountPointChooser> choosers;
private final SortedSet<MountPointChooser> choosers;
protected Path mountPoint;
@@ -19,7 +19,7 @@ public abstract class AbstractVolume implements Volume {
private boolean cleanupRequired;
private MountPointChooser usedChooser;
public AbstractVolume(Set<MountPointChooser> choosers) {
public AbstractVolume(SortedSet<MountPointChooser> choosers) {
this.choosers = choosers;
}
@@ -34,6 +34,8 @@ public abstract class AbstractVolume implements Volume {
this.usedChooser = chooser;
return chosenPath.get();
}
//SortedSet#stream() should return a sorted stream (that's what it's docs and the docs of #spliterator() say, even if they are not 100% clear for me.)
//We want to keep that order, that's why we use ImmutableSet#toImmutableSet() to collect (even if it doesn't implement SortedSet, it's docs promise use encounter ordering.)
String tried = Joiner.on(", ").join(this.choosers.stream().map((mpc) -> mpc.getClass().getTypeName()).collect(ImmutableSet.toImmutableSet()));
throw new InvalidMountPointException(String.format("No feasible MountPoint found! Tried %s", tried));
}
@@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutorService;
public class DokanyVolume extends AbstractVolume {
@@ -27,7 +27,7 @@ public class DokanyVolume extends AbstractVolume {
private Mount mount;
@Inject
public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService, @Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService, @Named("orderedValidMountPointChoosers") SortedSet<MountPointChooser> choosers) {
super(choosers);
this.vaultSettings = vaultSettings;
this.mountFactory = new MountFactory(executorService);
@@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.nio.file.Path;
import java.util.Set;
import java.util.SortedSet;
public class FuseVolume extends AbstractVolume {
@@ -26,7 +26,7 @@ public class FuseVolume extends AbstractVolume {
private Mount mount;
@Inject
public FuseVolume(@Named("orderedValidMountPointChoosers") Set<MountPointChooser> choosers) {
public FuseVolume(@Named("orderedValidMountPointChoosers") SortedSet<MountPointChooser> choosers) {
super(choosers);
}