int CompositePortNumber = 0;
int ComponentPortNumber = 0;
Composit composite = null;
Component innerComponent = null;
String ConnectionFailedMessage = "Command could not be executed: " + command + " " + param1 + " " + param2;
if (!param1.equals("") && !param2.equals("")) {
//Első paraméter ellenőrzése és feldolgozása(Kompozit elem ellenőrzése)
//getCompositeData4ConnectIn(CompositeName, CompositePortNumber, composite);
//első paraméter ellenőrzése
if (param1.indexOf(",") != -1 && param1.length() > param1.indexOf(",") + 1) {
CompositeName = param1.substring(0, param1.indexOf(","));
//Ha létezik a megadott nevű kompozit
if (Main.Components.containsKey(CompositeName)) {
//Kompozitra kasztoljuk, biztos, hogy nem fog hibátdobni
if (Main.Components.get(CompositeName).isComposite()) {
composite = (Composit) Main.Components.get(CompositeName);
} else {
System.out.println("The specified component(" + CompositeName + ") is not a Composit:");
output += "The specified component(" + CompositeName + ") is not a Composit:\n";
}
//ellenőrizzük a felhasználó által megadott portszám formátumát, csak szám lehet 0-9999
String regularExp = "\\d{1,4}";
CharSequence charSeq = param1.substring(param1.indexOf(",") + 1, param1.length());
if (Pattern.matches(regularExp, charSeq)) {
//Ha van annyi bemenő portja amennyit a felhasználó megadott
int SuppliedPortNumber = Integer.parseInt(param1.substring(param1.indexOf(",") + 1, param1.length()));
if ((composite.getInPorts().length - 1) >= SuppliedPortNumber) {
CompositePortNumber = SuppliedPortNumber;
} else {
int inPortCount = composite.getInPorts().length;
System.out.println(CompositeName + " has only " + inPortCount + " inPorts. (0-" + (inPortCount - 1) + ")");
output += CompositeName + " has only " + inPortCount + " inPorts. (0-" + (inPortCount - 1) + ")\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println("Bad inPortNumber format. Use number between 0-9999");
output += "Bad inPortNumber format. Use number between 0-9999\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println(CompositeName + " does not exists");
output += CompositeName + " does not exists\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
System.out.println("Bad first parameter. , is missing");
output += "Bad first parameter. , is missing\n";
} //Második paraméter ellenőrzése és feldolgozása( elem ellenőrzése)
if (param2.indexOf(",") != -1 && param2.length() > param2.indexOf(",") + 1) {
ComponentName = param2.substring(0, param2.indexOf(","));
//Ha létezik a megadott nevű komponens
if (Main.Components.containsKey(ComponentName)) {
innerComponent = Main.Components.get(ComponentName);
if (innerComponent.GetComposit() == composite) {
//ellenőrizzük a felhasználó által megadott portszám formátumát, csak szám lehet 0-9999
String regularExp = "\\d{1,4}";
CharSequence charSeq = param2.substring(param2.indexOf(",") + 1, param2.length());
if (Pattern.matches(regularExp, charSeq)) {
int SuppliedPortNumber = Integer.parseInt(param2.substring(param2.indexOf(",") + 1, param2.length()));
//Ha van annyi bemenő portja amennyit a felhasználó megadott
if ((innerComponent.getInPorts().length - 1) >= SuppliedPortNumber) {
ComponentPortNumber = SuppliedPortNumber;
} else {
int inPortCount = innerComponent.getInPorts().length;
System.out.println(ComponentName + " has only " + inPortCount + " inPorts. (0-" + (inPortCount - 1) + ") Command could not be executed: " + command + " " + param1 + " " + param2);
output += ComponentName + " has only " + inPortCount + " inPorts. (0-" + (inPortCount - 1) + ") Command could not be executed: " + command + " " + param1 + " " + param2 + "\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println("Bad inPortNumber format. Use number between 0-9999");
output += "Bad inPortNumber format. Use number between 0-9999\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println(ComponentName + " is not added to " + CompositeName + ". First you have to add it by using command: add <CompositeName> <VomponentName>.");
output += ComponentName + " is not added to " + CompositeName + ". First you have to add it by using command: add <CompositeName> <VomponentName>.\n";
}
} else {
System.out.println(ComponentName + " does not exists");
output += ComponentName + " does not exists\n";
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
return;
}
} else {
System.out.println(ConnectionFailedMessage);
output += ConnectionFailedMessage + "\n";
System.out.println("Bad second parameter. , is missing");
output += "Bad second parameter. , is missing\n";
}
//Létrehozzuk a kapcsolatot
composite.GetCInPorts()[CompositePortNumber].Connect(innerComponent.getInPorts()[ComponentPortNumber]);
int cindex = composite.GetComponents().indexOf(innerComponent);
composite.addConnectin(CompositePortNumber, cindex, ComponentPortNumber);
// A kompozittal kapcsolatos parancsot elmentjük
String[] sArray = new String[2];
sArray[0] = command + " " + param1 + " " + param2;
sArray[1] = CompositeName;
CompositeCommands.add(sArray);