ソースを参照

Changed contract of priorities in MPC, added null-check

See: ab538cd21573de70aa7d100382a8a70c25eeccaf (original commit)
See: 6b6867b826f474e5926afb65c1ce2d3c8a58366d (reverting commit)
JaniruTEC 4 年 前
コミット
58e2ec4742

+ 9 - 4
main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooser.java

@@ -1,5 +1,6 @@
 package org.cryptomator.common.mountpoint;
 
+import com.google.common.base.Preconditions;
 import org.cryptomator.common.vaults.Volume;
 
 import java.nio.file.Path;
@@ -12,8 +13,9 @@ import java.util.SortedSet;
  * <p>All <i>MountPointChoosers (MPCs)</i> need to implement this class and must be added to
  * the pool of possible MPCs by the {@link MountPointChooserModule MountPointChooserModule.}
  * The MountPointChooserModule will sort them according to their {@link #getPriority() priority.}
- * The priority must be defined by the developer to reflect a useful execution order;
- * the order of execution of MPCs with equal priority is undefined.
+ * The priority must be defined by the developer to reflect a useful execution order.<br>
+ * A specific priority <b>must not</b> be assigned to more than one MPC at a time;
+ * the result of having two MPCs with equal priority is undefined.
  *
  * <p>MPCs are executed by a {@link Volume} in ascending order of their priority
  * (smaller priorities are tried first) to find and prepare a suitable mountpoint for the volume.
@@ -138,8 +140,9 @@ public interface MountPointChooser extends Comparable<MountPointChooser> {
 	 * and determine their execution order.
 	 * The priority must be defined by the developer to reflect a useful execution order.
 	 * MPCs with lower priorities will be placed at lower indices in the resulting
-	 * {@link SortedSet} and will be executed with higher probability.
-	 * The order of execution of MPCs with equal priority is undefined.
+	 * {@link SortedSet} and will be executed with higher probability.<br>
+	 * A specific priority <b>must not</b> be assigned to more than one MPC at a time;
+	 * the result of having two MPCs with equal priority is undefined.
 	 *
 	 * @return the priority of this MPC.
 	 */
@@ -158,6 +161,8 @@ public interface MountPointChooser extends Comparable<MountPointChooser> {
 	 */
 	@Override
 	default int compareTo(MountPointChooser other) {
+		Preconditions.checkNotNull(other, "Other must not be null!");
+
 		//Sort by priority (ascending order)
 		return Integer.compare(this.getPriority(), other.getPriority());
 	}