*/
public class Command {
byte[] commandBytes;
-
+
Command(String commandString) {
String[] commands = commandString.trim().split("[\t\n ,]+", 100);
commandBytes = new byte[commands.length];
try {
for (int i = 0; i < commands.length; i++) {
- commandBytes[i] = Integer.decode(commands[i]).byteValue();
+ commandBytes[i] = Integer.decode(commands[i]).byteValue();
}
} catch (NumberFormatException e) {
commandBytes = null;
- throw new RuntimeException("Ungültige Zahlen eingegeben" + e.toString());
+ throw new RuntimeException("Ungültige Zahlen eingegeben"
+ + e.toString());
}
}
-
+
Command(byte[] commandBytes) {
if (commandBytes == null)
- throw new IllegalArgumentException("Es muss ein Array mit bytes übergeben werden");
-
+ throw new IllegalArgumentException(
+ "Es muss ein Array mit bytes übergeben werden");
+
this.commandBytes = commandBytes;
}
-
+
public String toString() {
StringBuffer result = new StringBuffer();
for (int i = 0; i < commandBytes.length; i++) {
result.append("0x" + Integer.toHexString(commandBytes[i] & 0xFF));
- if (i < commandBytes.length - 1);
- result.append(", ");
+ if (i < commandBytes.length - 1)
+ ;
+ result.append(", ");
}
return result.toString();
}
-
+
public byte[] getCommandBytes() {
if (commandBytes == null)
throw new RuntimeException("No Command configured yet.");