From 686342e7f9b599143dc2e1d551cb675147046aed Mon Sep 17 00:00:00 2001 From: domi41 Date: Thu, 17 Jun 2021 10:07:45 +0200 Subject: [PATCH] feat: add custom Exceptions --- .../mj/IncoherentTallyException.java | 26 +++++++++++++++++++ .../mieuxvoter/mj/InvalidTallyException.java | 12 +++++++++ .../mj/UnbalancedTallyException.java | 21 +++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/main/java/fr/mieuxvoter/mj/IncoherentTallyException.java create mode 100644 src/main/java/fr/mieuxvoter/mj/InvalidTallyException.java create mode 100644 src/main/java/fr/mieuxvoter/mj/UnbalancedTallyException.java diff --git a/src/main/java/fr/mieuxvoter/mj/IncoherentTallyException.java b/src/main/java/fr/mieuxvoter/mj/IncoherentTallyException.java new file mode 100644 index 0000000..e89bbd5 --- /dev/null +++ b/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(); + } + + + +} \ No newline at end of file diff --git a/src/main/java/fr/mieuxvoter/mj/InvalidTallyException.java b/src/main/java/fr/mieuxvoter/mj/InvalidTallyException.java new file mode 100644 index 0000000..74ac596 --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/src/main/java/fr/mieuxvoter/mj/UnbalancedTallyException.java b/src/main/java/fr/mieuxvoter/mj/UnbalancedTallyException.java new file mode 100644 index 0000000..da4ee3b --- /dev/null +++ b/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()) + ); + } +} \ No newline at end of file