Some fields and methods where non-static and I changed them to static.

This commit is contained in:
Sebastian Lenzlinger 2022-03-26 14:46:05 +01:00
parent a244903fbb
commit 15db9e4eb9
4 changed files with 11 additions and 12 deletions

View File

@ -25,13 +25,12 @@ public class NTtBProtocolParser implements ProtocolParser {
throws NoLegalProtocolCommandStringFoundException, EmptyClientInputException {
Scanner sc = new Scanner(msg);
ArrayList<String> input = new ArrayList<>();
String parsedMsg = buildProtocolMsg(input);
String parsedMsg;
while (sc.hasNext()) {
input.add(sc.next());
}
return parsedMsg;
return buildProtocolMsg(input);
}
@ -42,7 +41,7 @@ public class NTtBProtocolParser implements ProtocolParser {
throw new EmptyClientInputException(caller);
}
StringBuilder s = new StringBuilder(); //friendly little helper
s.append(legalCommands.encode(input.get(0)));
s.append(InputToProtocolMap.encode(input.get(0)));
if (containsParameters(input)) {
int size = input.size();
for (int i = 1; i < size; i++) {

View File

@ -49,11 +49,11 @@ public class NightTrainProtocol {
* @param cmd, the string command to be validated
* @return true if <code>cmd</code> is a valid command
*/
public boolean isLegalCmdString(String cmd) {
public static boolean isLegalCmdString(String cmd) {
return legalStrings.contains(cmd);
}
public NTtBCommands getCmdEnumObject(String cmd) throws NoLegalProtocolCommandStringFoundException {
public static NTtBCommands getCmdEnumObject(String cmd) throws NoLegalProtocolCommandStringFoundException {
if(isLegalCmdString(cmd)){
return stringNTtBCommandsHashMap.get(cmd);
} else {

View File

@ -18,9 +18,9 @@ public class ClientHandler implements Runnable {
private ClientMsgDecoder clientMsgDecoder = new ClientMsgDecoder();
/**
* Implements the connecting logik in client-server
* Implements the login logik in client-server
* architecture.
* @param socket
* @param socket the socket on which to make the connection.
*/
public ClientHandler(Socket socket) {
try {
@ -66,7 +66,9 @@ public class ClientHandler implements Runnable {
@Override
/**
* point of contact for client and server.
* The main logik of the client handler.
* Since every client is put on a string this is where
* most interactions between client and server are held..
*/
public void run() {
String msg;

View File

@ -17,8 +17,6 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.protocol.ProtocolDecoder;
public class ClientMsgDecoder implements ProtocolDecoder {
private NightTrainProtocol protocol;
/**
* The point of contact for the ClientHandler who calls this method to convert a String in to
* usable, tokanized format defined by {@link NTtBFormatMsg}.
@ -78,7 +76,7 @@ public class ClientMsgDecoder implements ProtocolDecoder {
*/
private NightTrainProtocol.NTtBCommands getCommandConstant(String stringToken) {
try {
return protocol.getCmdEnumObject(stringToken);
return NightTrainProtocol.getCmdEnumObject(stringToken);
} catch (NoLegalProtocolCommandStringFoundException e) {
return NightTrainProtocol.NTtBCommands.SEROR;
}