Browse Source

feat: add custom Exceptions

master
Dominique Merle 1 year ago
parent
commit
686342e7f9
  1. 26
      src/main/java/fr/mieuxvoter/mj/IncoherentTallyException.java
  2. 12
      src/main/java/fr/mieuxvoter/mj/InvalidTallyException.java
  3. 21
      src/main/java/fr/mieuxvoter/mj/UnbalancedTallyException.java

26
src/main/java/fr/mieuxvoter/mj/IncoherentTallyException.java

@ -0,0 +1,26 @@
package fr.mieuxvoter.mj;
/**
* Raised when the provided tally holds negative values, or infinity.
*/
class IncoherentTallyException extends InvalidTallyException {
private static final long serialVersionUID = 5858986651601202903L;
@Override
public String getMessage() {
return (
"The provided tally holds negative values, or infinity. "
+
(null == super.getMessage() ? "" : super.getMessage())
);
}
@Override
public String getLocalizedMessage() {
return super.getLocalizedMessage();
}
}

12
src/main/java/fr/mieuxvoter/mj/InvalidTallyException.java

@ -0,0 +1,12 @@
package fr.mieuxvoter.mj;
import java.security.InvalidParameterException;
/**
* Raised when the provided tally is invalid.
*/
class InvalidTallyException extends InvalidParameterException {
private static final long serialVersionUID = 3033391835216704620L;
}

21
src/main/java/fr/mieuxvoter/mj/UnbalancedTallyException.java

@ -0,0 +1,21 @@
package fr.mieuxvoter.mj;
/**
* Raised when the provided tally does not hold the same amount of judgments
* for each proposal, and normalization is required.
*/
class UnbalancedTallyException extends InvalidTallyException {
private static final long serialVersionUID = 5041093000505081735L;
@Override
public String getMessage() {
return (
"The provided tally is unbalanced, " +
"as some proposals received more judgments than others. \n" +
"You need to set a strategy for balancing tallies. To that effect, \n" +
"you may use StaticDefaultTally, MedianDefaultTally, or NormalizedTally instead of Tally. \n" +
(null == super.getMessage() ? "" : super.getMessage())
);
}
}
Loading…
Cancel
Save