feat: add custom Exceptions

pull/14/head^2
Dominique Merle 3 years ago
parent e3c51f3c01
commit 686342e7f9

@ -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();
}
}

@ -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;
}

@ -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