Better handling of an empty input
This commit is contained in:
parent
93bf3f101c
commit
2d8bf539ae
4 changed files with 740 additions and 728 deletions
|
@ -24,6 +24,9 @@ package de.marcelkapfer.morseconverter.engine;
|
||||||
public class DecodeNormalMorseManager {
|
public class DecodeNormalMorseManager {
|
||||||
|
|
||||||
public static String getDecodedString(String inputMessage) {
|
public static String getDecodedString(String inputMessage) {
|
||||||
|
if(inputMessage.equals("")){
|
||||||
|
return "Please enter at least one character";
|
||||||
|
} else {
|
||||||
StringBuffer message = new StringBuffer(inputMessage);
|
StringBuffer message = new StringBuffer(inputMessage);
|
||||||
if (message.toString().endsWith(" ")) {
|
if (message.toString().endsWith(" ")) {
|
||||||
message = message.deleteCharAt(message.length() - 1);
|
message = message.deleteCharAt(message.length() - 1);
|
||||||
|
@ -32,9 +35,7 @@ public class DecodeNormalMorseManager {
|
||||||
StringBuffer input = new StringBuffer();
|
StringBuffer input = new StringBuffer();
|
||||||
input = input.replace(0, input.length(), message.toString().toUpperCase());
|
input = input.replace(0, input.length(), message.toString().toUpperCase());
|
||||||
StringBuffer output = new StringBuffer();
|
StringBuffer output = new StringBuffer();
|
||||||
if (input.toString().equals("")) {
|
if (input.toString().equals("LETTERSPACE")) {
|
||||||
output.replace(0, output.length(), "Please enter at least one character");
|
|
||||||
} else if (input.toString().equals("LETTERSPACE")) {
|
|
||||||
output.replace(0, output.length(), " ");
|
output.replace(0, output.length(), " ");
|
||||||
} else if (input.toString().equals("END OF WORK")) {
|
} else if (input.toString().equals("END OF WORK")) {
|
||||||
output.replace(0, output.length(), "...-.-");
|
output.replace(0, output.length(), "...-.-");
|
||||||
|
@ -240,4 +241,5 @@ public class DecodeNormalMorseManager {
|
||||||
}
|
}
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,9 @@ package de.marcelkapfer.morseconverter.engine;
|
||||||
public class DecodeWrittenMorseManager {
|
public class DecodeWrittenMorseManager {
|
||||||
|
|
||||||
public static String getDecodedString(String inputMessage) {
|
public static String getDecodedString(String inputMessage) {
|
||||||
|
if(inputMessage.equals("")){
|
||||||
|
return "Please enter at least one character";
|
||||||
|
} else {
|
||||||
StringBuffer message = new StringBuffer(inputMessage);
|
StringBuffer message = new StringBuffer(inputMessage);
|
||||||
if (message.toString().endsWith(" ")) {
|
if (message.toString().endsWith(" ")) {
|
||||||
message = message.deleteCharAt(message.length() - 1);
|
message = message.deleteCharAt(message.length() - 1);
|
||||||
|
@ -32,9 +35,7 @@ public class DecodeWrittenMorseManager {
|
||||||
StringBuffer input = new StringBuffer();
|
StringBuffer input = new StringBuffer();
|
||||||
input = input.replace(0, input.length(), message.toString().toUpperCase());
|
input = input.replace(0, input.length(), message.toString().toUpperCase());
|
||||||
StringBuffer output = new StringBuffer();
|
StringBuffer output = new StringBuffer();
|
||||||
if (input.toString().equals("")) {
|
if (input.toString().equals("LETTERSPACE")) {
|
||||||
output.replace(0, output.length(), "Please enter at least one character");
|
|
||||||
} else if (input.toString().equals("LETTERSPACE")) {
|
|
||||||
output.replace(0, output.length(), "#");
|
output.replace(0, output.length(), "#");
|
||||||
} else if (input.toString().equals("END OF WORK")) {
|
} else if (input.toString().equals("END OF WORK")) {
|
||||||
output.replace(0, output.length(), "000101");
|
output.replace(0, output.length(), "000101");
|
||||||
|
@ -241,4 +242,5 @@ public class DecodeWrittenMorseManager {
|
||||||
}
|
}
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,6 +27,9 @@ package de.marcelkapfer.morseconverter.engine;
|
||||||
public class EncodeNormalMorseManager {
|
public class EncodeNormalMorseManager {
|
||||||
|
|
||||||
public static String getEncodedString(String inputMessage) {
|
public static String getEncodedString(String inputMessage) {
|
||||||
|
if(inputMessage.equals("")){
|
||||||
|
return "Please enter at least one character";
|
||||||
|
} else {
|
||||||
// Converts the input string into a StringBuffer
|
// Converts the input string into a StringBuffer
|
||||||
StringBuffer message = new StringBuffer(inputMessage);
|
StringBuffer message = new StringBuffer(inputMessage);
|
||||||
// Delete the space at the end which is automatically set through some keyboards
|
// Delete the space at the end which is automatically set through some keyboards
|
||||||
|
@ -189,4 +192,5 @@ public class EncodeNormalMorseManager {
|
||||||
}
|
}
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -28,6 +28,9 @@ package de.marcelkapfer.morseconverter.engine;
|
||||||
public class EncodeWrittenMorseManager {
|
public class EncodeWrittenMorseManager {
|
||||||
|
|
||||||
public static String getEncodedString(String inputMessage) {
|
public static String getEncodedString(String inputMessage) {
|
||||||
|
if(inputMessage.equals("")){
|
||||||
|
return "Please enter at least one character";
|
||||||
|
} else {
|
||||||
StringBuffer message = new StringBuffer(inputMessage);
|
StringBuffer message = new StringBuffer(inputMessage);
|
||||||
if (message.toString().endsWith(" ")) {
|
if (message.toString().endsWith(" ")) {
|
||||||
message = message.deleteCharAt(message.length() - 1);
|
message = message.deleteCharAt(message.length() - 1);
|
||||||
|
@ -189,5 +192,6 @@ public class EncodeWrittenMorseManager {
|
||||||
}
|
}
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue