Further improved Java Docs 10 missing todos.

This commit is contained in:
Leonardo Brandenberger 2022-04-16 16:23:25 +02:00
parent 048dc36a7c
commit 154b9d435d
5 changed files with 41 additions and 47 deletions

View File

@ -251,7 +251,7 @@ public class ChatWindowController {
} }
/** /**
* //TODO missing * Starts several new Listener for Connection Handler changes by using several observable properties.
*/ */
public void startConnectionHandlerListener() { public void startConnectionHandlerListener() {
@ -285,7 +285,7 @@ public class ChatWindowController {
} }
/** /**
* //TODO * Starts a new Listener for messages by using the observable Boolean.
*/ */
private void messageListener() { private void messageListener() {
messages.getChangedProperty().addListener(new ChangeListener<Boolean>() { messages.getChangedProperty().addListener(new ChangeListener<Boolean>() {

View File

@ -12,7 +12,7 @@ public class Message {
/** /**
* Constructor of Message. Needs all Information about a Message to save them. * Constructor of Message. Needs all Information about a Message to save them.
* *
* @param type Message (if it's a message typed by a user), Error or Information (if it is generated automatically, in this case sender and reciever will be null) * @param type Message (if it's a message typed by a user), Error or Information (if it is generated automatically, in this case sender and receiver will be null)
* @param sender The User who has sent the message. * @param sender The User who has sent the message.
* @param receiver The User who should receive the message. * @param receiver The User who should receive the message.
* @param text The Text of the message. * @param text The Text of the message.

View File

@ -29,7 +29,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link ConnectionHandler#DATA_TYPE_CONNECT} * @return {@link ConnectionHandler#DATA_TYPE_CONNECT}
*/ */
public static String getDataTypeConnect() { public static String getDataTypeConnect() {
@ -37,7 +36,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link ConnectionHandler#DATA_TYPE_CONFIRM} * @return {@link ConnectionHandler#DATA_TYPE_CONFIRM}
*/ */
public static String getDataTypeConfirm() { public static String getDataTypeConfirm() {
@ -45,7 +43,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link ConnectionHandler#DATA_TYPE_DISCONNECT} * @return {@link ConnectionHandler#DATA_TYPE_DISCONNECT}
*/ */
public static String getDataTypeDisconnect() { public static String getDataTypeDisconnect() {
@ -53,7 +50,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link ConnectionHandler#DATA_TYPE_MESSAGE * @return {@link ConnectionHandler#DATA_TYPE_MESSAGE
*/ */
public static String getDataTypeMessage() { public static String getDataTypeMessage() {
@ -61,7 +57,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link ConnectionHandler#DATA_TYPE_ERROR} * @return {@link ConnectionHandler#DATA_TYPE_ERROR}
*/ */
public static String getDataTypeError() { public static String getDataTypeError() {
@ -69,7 +64,6 @@ public abstract class ConnectionHandler {
} }
/** /**
*
* @return {@link NetworkHandler.NetworkConnection} * @return {@link NetworkHandler.NetworkConnection}
*/ */
public NetworkHandler.NetworkConnection<String> getConnection() { public NetworkHandler.NetworkConnection<String> getConnection() {
@ -78,6 +72,7 @@ public abstract class ConnectionHandler {
/** /**
* This method sets the NetworkConnection used for the server <-> client connection * This method sets the NetworkConnection used for the server <-> client connection
*
* @param connection NetworkConnection used for the server <-> client connection * @param connection NetworkConnection used for the server <-> client connection
*/ */
protected void setConnection(NetworkHandler.NetworkConnection<String> connection) { protected void setConnection(NetworkHandler.NetworkConnection<String> connection) {
@ -85,26 +80,24 @@ public abstract class ConnectionHandler {
} }
/** /**
* This method reads the data when a ConnectionHandler recieves it. It tries to read out the sender, reciever, type and payload. * This method reads the data when a ConnectionHandler receives it. It tries to read out the sender, receiver, type and payload.
* If the data does not contain the expected number of lines, it throws a {@link ChatProtocolException} * If the data does not contain the expected number of lines, it throws a {@link ChatProtocolException}
*
* @param scanner to read data * @param scanner to read data
* @param sender of the data * @param sender of the data
* @param reciever for the data * @param receiver for the data
* @param type of data * @param type of data
* @param payload the data sent * @param payload the data sent
* @throws ChatProtocolException if the data does not contain the expected number of lines * @throws ChatProtocolException if the data does not contain the expected number of lines
*/ */
protected void processData(Scanner scanner, StringBuilder sender, StringBuilder reciever, StringBuilder type, StringBuilder payload) throws ChatProtocolException { protected void processData(Scanner scanner, StringBuilder sender, StringBuilder receiver, StringBuilder type, StringBuilder payload) throws ChatProtocolException {
// parse data content // parse data content
if (scanner.hasNextLine()) { if (scanner.hasNextLine()) {
sender.append(scanner.nextLine()); sender.append(scanner.nextLine());
} else if (scanner.hasNextLine()) {
receiver.append(scanner.nextLine());
} else { } else {
throw new ChatProtocolException("No Sender found"); throw new ChatProtocolException("No Receiver found");
}
if (scanner.hasNextLine()) {
reciever.append(scanner.nextLine());
} else {
throw new ChatProtocolException("No Reciever found");
} }
if (scanner.hasNextLine()) { if (scanner.hasNextLine()) {
type.append(scanner.nextLine()); type.append(scanner.nextLine());
@ -118,6 +111,7 @@ public abstract class ConnectionHandler {
/** /**
* This method gets called to send data via the socket defined in the {@link NetworkHandler.NetworkConnection} * This method gets called to send data via the socket defined in the {@link NetworkHandler.NetworkConnection}
*
* @param sender of the data * @param sender of the data
* @param receiver of the data * @param receiver of the data
* @param type of the data * @param type of the data
@ -127,10 +121,10 @@ public abstract class ConnectionHandler {
if (connection.isAvailable()) { if (connection.isAvailable()) {
new StringBuilder(); new StringBuilder();
String data = new StringBuilder() String data = new StringBuilder()
.append(sender+"\n") .append(sender + "\n")
.append(receiver+"\n") .append(receiver + "\n")
.append(type+"\n") .append(type + "\n")
.append(payload+"\n") .append(payload + "\n")
.toString(); .toString();
try { try {
connection.send(data); connection.send(data);
@ -138,7 +132,7 @@ public abstract class ConnectionHandler {
System.err.println("Connection closed: " + e.getMessage()); System.err.println("Connection closed: " + e.getMessage());
} catch (EOFException e) { } catch (EOFException e) {
System.out.println("Connection terminated by remote"); System.out.println("Connection terminated by remote");
} catch(IOException e) { } catch (IOException e) {
System.err.println("Communication error: " + e.getMessage()); System.err.println("Communication error: " + e.getMessage());
} }
} }

View File

@ -25,6 +25,19 @@ public class Server {
// Connection registry // Connection registry
private final Map<String, ServerConnectionHandler> connections = new HashMap<>(); private final Map<String, ServerConnectionHandler> connections = new HashMap<>();
/**
* The Constructor to create a new instance.
*
* @param serverPort to listen for incoming connections.
* @throws IOException thrown if an I/O error occurs when opening the socket.
*/
public Server(int serverPort) throws IOException {
// Open server connection
System.out.println("Create server connection");
networkServer = NetworkHandler.createServer(serverPort);
System.out.println("Listening on " + networkServer.getHostAddress() + ":" + networkServer.getHostPort());
}
/** /**
* @param args * @param args
*/ */
@ -66,19 +79,6 @@ public class Server {
} }
} }
/**
* The Constructor to create a new instance.
*
* @param serverPort to listen for incoming connections.
* @throws IOException thrown if an I/O error occurs when opening the socket.
*/
public Server(int serverPort) throws IOException {
// Open server connection
System.out.println("Create server connection");
networkServer = NetworkHandler.createServer(serverPort);
System.out.println("Listening on " + networkServer.getHostAddress() + ":" + networkServer.getHostPort());
}
/** /**
* With this methode the instance waits for incoming connections. If a client tries to connect to the server. * With this methode the instance waits for incoming connections. If a client tries to connect to the server.
* The connection will be registered in the connection registry if successful. * The connection will be registered in the connection registry if successful.

View File

@ -33,8 +33,8 @@ import java.util.concurrent.locks.ReentrantLock;
* 1. Removing the connection from the {@link ServerConnectionHandler#connectionRegistry} * 1. Removing the connection from the {@link ServerConnectionHandler#connectionRegistry}
* 2. Terminates the socket by calling {@link NetworkHandler.NetworkConnection#close()} * 2. Terminates the socket by calling {@link NetworkHandler.NetworkConnection#close()}
* <p> * <p>
* Processes Messages send from a client by: * Process Messages send from a client by:
* 1. Evaluating the reciever by differentiating between broadcast or unicast. * 1. Evaluating the receiver by differentiating between broadcast or unicast.
* 2. Sending the message accordingly. * 2. Sending the message accordingly.
* <p> * <p>
* To use this class, start a new instance and start it in a thread. * To use this class, start a new instance and start it in a thread.
@ -89,7 +89,7 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab
return this.userName; return this.userName;
} }
/** /** //TODO needed method?
* @return state of the connection. Possible states are see {@link ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State} * @return state of the connection. Possible states are see {@link ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State}
*/ */
public State getState() { public State getState() {
@ -97,7 +97,7 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab
} }
/** /**
* This methods runs in a while-loop as long as the socket between server and client is available * These methods runs in a while-loop as long as the socket between server and client is available
* and the connection State is not ERROR. * and the connection State is not ERROR.
*/ */
private void startReceiving() { private void startReceiving() {