add javadoc to server.utils and server.listener

This commit is contained in:
Quentin Legot 2021-12-08 22:52:09 +01:00
parent eaec044950
commit 9771d397a8
10 changed files with 69 additions and 60 deletions

View File

@ -1,6 +1,13 @@
package fr.lnl.game.server.listener; package fr.lnl.game.server.listener;
/**
* Model implemented by {@link AbstractModelListening}
*/
public interface ModelListener { 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); void updateModel(Object obj);
} }

View File

@ -0,0 +1,5 @@
/**
* Package containing model of listener to implement
* Used by listeners in client module
*/
package fr.lnl.game.server.listener;

View File

@ -1,5 +1,8 @@
package fr.lnl.game.server.utils; package fr.lnl.game.server.utils;
/**
* Represent an unrecoverable error in the program, force program to stop
*/
public class CrashException extends RuntimeException { public class CrashException extends RuntimeException {
public CrashException(String message, Throwable cause) { public CrashException(String message, Throwable cause) {

View File

@ -1,6 +1,14 @@
package fr.lnl.game.server.utils; 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 { 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 : "; public static final String Entry_Error_Message = "\033[0;31mErreur de saisie\033[0m : ";
} }

View File

@ -4,14 +4,28 @@ import java.util.Scanner;
public class Maths { 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) { public static int testInteger(String entry, Scanner scanner, String error) {
while (!isNumeric(entry)) { while (!isInteger(entry)) {
System.out.println(ErrorMessage.Entry_Error_Message + error); System.out.println(ErrorMessage.Entry_Error_Message + error);
entry = scanner.next(); entry = scanner.next();
} }
return Integer.parseInt(entry); 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) { public static float testFloat(String entry, Scanner scanner, String error) {
while (!isFloat(entry)) { while (!isFloat(entry)) {
System.out.println(ErrorMessage.Entry_Error_Message + error); System.out.println(ErrorMessage.Entry_Error_Message + error);
@ -20,6 +34,11 @@ public class Maths {
return Integer.parseInt(entry); 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) { public static boolean isFloat(String strNum) {
try { try {
float d = Float.parseFloat(strNum); float d = Float.parseFloat(strNum);
@ -29,7 +48,11 @@ public class Maths {
return true; 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 { try {
int d = Integer.parseInt(strNum); int d = Integer.parseInt(strNum);
} catch (NumberFormatException | NullPointerException nfe) { } catch (NumberFormatException | NullPointerException nfe) {

View File

@ -2,6 +2,12 @@ package fr.lnl.game.server.utils;
import java.util.Objects; import java.util.Objects;
/**
* Tuple associating storing two value of undefined type.<br>
* Unlike Python, value in this Tuple can be modified (but the type of its new value need to be the same)
* @param <A> first element of the tuple
* @param <B> second element of the tuple
*/
public class Pair<A, B> { public class Pair<A, B> {
private A a; private A a;
@ -37,6 +43,10 @@ public class Pair<A,B> {
return Objects.equals(a, point.a) && Objects.equals(b, point.b); 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 @Override
public int hashCode() { public int hashCode() {
return Objects.hash(a, b); return Objects.hash(a, b);

View File

@ -1,5 +1,8 @@
package fr.lnl.game.server.utils; 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<Integer, Integer> { public class Point extends Pair<Integer, Integer> {
public Point(int a, int b) { public Point(int a, int b) {

View File

@ -1,57 +0,0 @@
package fr.lnl.game.server.utils;
import java.util.Objects;
public class Triplet<A,B,C> {
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);
}
}

View File

@ -0,0 +1,4 @@
/**
* Package containing all utility classes
*/
package fr.lnl.game.server.utils;

View File

@ -1,3 +1,6 @@
/**
* Server module, include every model classes
*/
module server { module server {
exports fr.lnl.game.server; exports fr.lnl.game.server;
exports fr.lnl.game.server.games; exports fr.lnl.game.server.games;