package server.awk;

import server.adt.NetworkToken;
import utils.buffer.OutputBuffer;

public class AWK implements Runnable{
	
	private final OutputBuffer<NetworkToken> buffer;
	private boolean isStopped = false;
	public AWK(OutputBuffer<NetworkToken> buffer){
		this.buffer = buffer;
	}
	@Override
	public void run() {
		while(!isStopped){
			NetworkToken token = buffer.getMessageFromInput();
			
			buffer.addMessageIntoOutput(new NetworkToken("Acc", token.getClientID(), token.getClientIP()));
		}
		
	}
	
	public void stop(){
		
	}
	
	
	
	
	private String convertToLowercase(String text){
		String str = "hallo";
		return str;
	}

}

@@ -207,16 +207,21 @@
  false;%0A
+%09%0A%0A%09%0A
 %09public 
@@ -287,16 +287,20 @@
 fer;%0A%09%7D%0A
+%09%0A%09%0A
 %09@Overri
@@ -398,16 +398,144 @@
 nput();%0A
+%09%09%09String inputMessage = token.getMessage();%0A%09%09%09%0A%09%09%09/* execute command */%0A%09%09%09String outputMessage = convertImput(inputMessage);%0A
 %09%09%09%0A%09%09%09b
@@ -582,13 +582,21 @@
 ken(
-%22Acc%22
+outputMessage
 , to
@@ -641,19 +641,16 @@
 ));%0A%09%09%7D%0A
-%09%09%0A
 %09%7D%0A%09%0A%09pu
@@ -682,97 +682,1175 @@
 %0A%09%0A%09
-%0A%09%0A%09private String convertToLowercase(String text)%7B%0A%09%09String str = %22hallo%22;%0A%09%09return str;
+private String convertImput(String input)%7B%0A%09%09String returnMessage;%0A%09%09%0A%09%09/* split inputMessage into two parts,%0A%09%09 * firstpart: command %0A%09%09 * second: message  */%0A%09%09String%5B%5D splitString = input.split(%22 %22, 2);%0A%09%09%0A%09%09String command = splitString%5B0%5D;%0A%09%09%0A%09%09if(command.equals(%22BYE%22))%7B%0A%09%09%09/* do what you have to do here */%0A%09%09%7D%0A%09%09else if (splitString.length %3C 2)%7B%0A%09%09%09return returnMessage = %22ERROR SYNTAX ERROR: MESSAGE OR PASSWORD IS MISSING%22;%0A%09%09%7D%0A%09%09%0A%09%09String message = splitString%5B1%5D;%0A%09%09%0A%09%09switch (command)%7B%09%09%09%09%0A%09%09%09case %22LOWERCASE%22:%09returnMessage = convertToLowercase(message);%0A%09%09%09%09%09%09%09%09break;%0A%09%09%09case %22UPPERCASE%22: %09returnMessage = convertToUppercase(message);%0A%09%09%09%09%09%09%09%09break;%0A%09%09%09case %22REVERSE%22:%09%09returnMessage = convertToReverseString(message);%0A%09%09%09%09%09%09%09%09break;%0A%09%09%09case %22SHUTDOWN%22:%09%09%09%09%09%09%0A%09%09%09default: %09%09%09returnMessage = %22ERROR UNKNOWN COMMAND%22;%0A%09%09%09%09%09%09%09%09break;%0A%09%09%7D%0A%09%09%0A%09%09return returnMessage;%0A%09%09%0A%09%7D%0A%09%0A%09%0A%09%0A%09private String convertToLowercase(String text)%7B%0A%09%09return text.toLowerCase();%0A%09%7D%0A%09%0A%09%0A%09private String convertToUppercase(String text)%7B%0A%09%09return text.toUpperCase();%0A%09%7D%0A%09%0A%09private String convertToReverseString(String text)%7B%0A%09%09return new StringBuilder(text).reverse().toString();%0A%09%09
 %0A%09%7D%0A

add commands to awk