From 9771d397a8bcd9dba8a7b1a03ab86380fd2a46bd Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 8 Dec 2021 22:52:09 +0100 Subject: [PATCH] add javadoc to server.utils and server.listener --- .../game/server/listener/ModelListener.java | 7 +++ .../game/server/listener/package-info.java | 5 ++ .../lnl/game/server/utils/CrashException.java | 3 + .../lnl/game/server/utils/ErrorMessage.java | 8 +++ .../java/fr/lnl/game/server/utils/Maths.java | 27 ++++++++- .../java/fr/lnl/game/server/utils/Pair.java | 12 +++- .../java/fr/lnl/game/server/utils/Point.java | 3 + .../fr/lnl/game/server/utils/Triplet.java | 57 ------------------- .../lnl/game/server/utils/package-info.java | 4 ++ server/src/main/java/module-info.java | 3 + 10 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 server/src/main/java/fr/lnl/game/server/listener/package-info.java delete mode 100644 server/src/main/java/fr/lnl/game/server/utils/Triplet.java create mode 100644 server/src/main/java/fr/lnl/game/server/utils/package-info.java diff --git a/server/src/main/java/fr/lnl/game/server/listener/ModelListener.java b/server/src/main/java/fr/lnl/game/server/listener/ModelListener.java index 6c71cc9..2f98645 100644 --- a/server/src/main/java/fr/lnl/game/server/listener/ModelListener.java +++ b/server/src/main/java/fr/lnl/game/server/listener/ModelListener.java @@ -1,6 +1,13 @@ package fr.lnl.game.server.listener; +/** + * Model implemented by {@link AbstractModelListening} + */ public interface ModelListener { + /** + * this method is call everytime, an action on the view forces a controller to sens an update to model + * @param obj can be used to send data to model + */ void updateModel(Object obj); } diff --git a/server/src/main/java/fr/lnl/game/server/listener/package-info.java b/server/src/main/java/fr/lnl/game/server/listener/package-info.java new file mode 100644 index 0000000..3da2992 --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/listener/package-info.java @@ -0,0 +1,5 @@ +/** + * Package containing model of listener to implement + * Used by listeners in client module + */ +package fr.lnl.game.server.listener; \ No newline at end of file diff --git a/server/src/main/java/fr/lnl/game/server/utils/CrashException.java b/server/src/main/java/fr/lnl/game/server/utils/CrashException.java index a3c9474..90aec38 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/CrashException.java +++ b/server/src/main/java/fr/lnl/game/server/utils/CrashException.java @@ -1,5 +1,8 @@ package fr.lnl.game.server.utils; +/** + * Represent an unrecoverable error in the program, force program to stop + */ public class CrashException extends RuntimeException { public CrashException(String message, Throwable cause) { diff --git a/server/src/main/java/fr/lnl/game/server/utils/ErrorMessage.java b/server/src/main/java/fr/lnl/game/server/utils/ErrorMessage.java index e9a4929..88c7668 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/ErrorMessage.java +++ b/server/src/main/java/fr/lnl/game/server/utils/ErrorMessage.java @@ -1,6 +1,14 @@ package fr.lnl.game.server.utils; +/** + * Contain everything related to error messages, theirs errors are the fault of the end-user (like we demand an integer + * and user give us a floating point number + * Theirs error doesn't cause the program to stop, it'll demand a correct value + */ public class ErrorMessage { + /** + * Error given to end-user when it give us a non integer or float value + */ public static final String Entry_Error_Message = "\033[0;31mErreur de saisie\033[0m : "; } diff --git a/server/src/main/java/fr/lnl/game/server/utils/Maths.java b/server/src/main/java/fr/lnl/game/server/utils/Maths.java index 6bfe792..78f1f0d 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/Maths.java +++ b/server/src/main/java/fr/lnl/game/server/utils/Maths.java @@ -4,14 +4,28 @@ import java.util.Scanner; public class Maths { + /** + * Convert entry to an integer + * @param entry given parameter + * @param scanner standard input, used if entry isn't correct + * @param error error message to display if entry isn't an Integer + * @return an Integer if entry is valid or when it'll valid + */ public static int testInteger(String entry, Scanner scanner, String error) { - while (!isNumeric(entry)) { + while (!isInteger(entry)) { System.out.println(ErrorMessage.Entry_Error_Message + error); entry = scanner.next(); } return Integer.parseInt(entry); } + /** + * Convert entry to a float + * @param entry given parameter + * @param scanner standard input, used if entry isn't correct + * @param error error message to display if entry isn't a float + * @return a float if entry is a valid or when it'll valid + */ public static float testFloat(String entry, Scanner scanner, String error) { while (!isFloat(entry)) { System.out.println(ErrorMessage.Entry_Error_Message + error); @@ -20,6 +34,11 @@ public class Maths { return Integer.parseInt(entry); } + /** + * @param strNum entry + * @return true if {@code strNum} is a float, false otherwise + * @see Maths#testFloat(String, Scanner, String) + */ public static boolean isFloat(String strNum) { try { float d = Float.parseFloat(strNum); @@ -29,7 +48,11 @@ public class Maths { return true; } - public static boolean isNumeric(String strNum) { + /** + * @param strNum entry + * @return true if {@code strNum} is an Integer, false otherwise + */ + public static boolean isInteger(String strNum) { try { int d = Integer.parseInt(strNum); } catch (NumberFormatException | NullPointerException nfe) { diff --git a/server/src/main/java/fr/lnl/game/server/utils/Pair.java b/server/src/main/java/fr/lnl/game/server/utils/Pair.java index 9052001..b575217 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/Pair.java +++ b/server/src/main/java/fr/lnl/game/server/utils/Pair.java @@ -2,7 +2,13 @@ package fr.lnl.game.server.utils; import java.util.Objects; -public class Pair { +/** + * Tuple associating storing two value of undefined type.
+ * Unlike Python, value in this Tuple can be modified (but the type of its new value need to be the same) + * @param first element of the tuple + * @param second element of the tuple + */ +public class Pair { private A a; private B b; @@ -37,6 +43,10 @@ public class Pair { return Objects.equals(a, point.a) && Objects.equals(b, point.b); } + /** + * Absolut useful when using HashMap or HashSet (or everything using hashCode to compare Objects + * @return object hash + */ @Override public int hashCode() { return Objects.hash(a, b); diff --git a/server/src/main/java/fr/lnl/game/server/utils/Point.java b/server/src/main/java/fr/lnl/game/server/utils/Point.java index 1c2be78..cb567e7 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/Point.java +++ b/server/src/main/java/fr/lnl/game/server/utils/Point.java @@ -1,5 +1,8 @@ package fr.lnl.game.server.utils; +/** + * Point extends from Pair, basically a simpler ways to use Pair when using grid position + */ public class Point extends Pair { public Point(int a, int b) { diff --git a/server/src/main/java/fr/lnl/game/server/utils/Triplet.java b/server/src/main/java/fr/lnl/game/server/utils/Triplet.java deleted file mode 100644 index 9459156..0000000 --- a/server/src/main/java/fr/lnl/game/server/utils/Triplet.java +++ /dev/null @@ -1,57 +0,0 @@ -package fr.lnl.game.server.utils; - -import java.util.Objects; - -public class Triplet { - - private A a; - private B b; - private C c; - - public Triplet(A a, B b, C c){ - this.a = a; - this.b = b; - this.c = c; - } - - public Triplet(){ - this(null, null, null); - } - - public A getA() { - return a; - } - - public B getB() { - return b; - } - - public C getC() { - return c; - } - - public void setA(A a) { - this.a = a; - } - - public void setB(B b) { - this.b = b; - } - - public void setC(C c) { - this.c = c; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Triplet tuple = (Triplet) o; - return Objects.equals(a, tuple.a) && Objects.equals(b, tuple.b) && Objects.equals(c, tuple.c); - } - - @Override - public int hashCode() { - return Objects.hash(a, b, c); - } -} diff --git a/server/src/main/java/fr/lnl/game/server/utils/package-info.java b/server/src/main/java/fr/lnl/game/server/utils/package-info.java new file mode 100644 index 0000000..867df9b --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/utils/package-info.java @@ -0,0 +1,4 @@ +/** + * Package containing all utility classes + */ +package fr.lnl.game.server.utils; \ No newline at end of file diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 1747951..5164c9c 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -1,3 +1,6 @@ +/** + * Server module, include every model classes + */ module server { exports fr.lnl.game.server; exports fr.lnl.game.server.games;