How do I add a string to a list (it can be in list A or B), my code comes back and starts reading the beginning of the string list
, ie the first string?
I have a list of 20 strings. But it is giving an error because my code adds string
and goes to the next position. He does not come back and starts reading from the beginning. So you have strings that are not added.
How do I add a string after my code returns and starts reading the start (position 0 of the string list), ie the first string?
Can anyone give me an example? I'm breaking my head with it and I'm not leaving.
public int calcFitness(int indv) {
String linha1 = individualID.get(indv);
String[] taskQe = linha1.split(" ");
String linha2 = individualDep.get(indv);
String[] depQe = linha2.split(" ");
String linha3 = individualHour.get(indv);
String[] hourQe = linha3.split(" ");
String linha4 = individualEmpl.get(indv);
String[] emplQe = linha4.split(" ");
int fitness=0;
for (int taskIndex = 0; taskIndex < taskQe.length; taskIndex++) {
String currentTask = taskQe[taskIndex];
String currentDep = depQe[taskIndex];
String currentHour = hourQe[taskIndex];
System.out.println("task: [" + currentTask + "], dep: [" + currentDep + "], hours: [" + currentHour + "]");
int hour = Integer.parseInt(currentHour);
if (currentDep.equals("0")) {
// System.out.println ("axhou 0");
if (Cp1TotalHours <= Cp2TotalHours) {
Cp1.add(currentTask);
Cp1Hour.add(hour);
Cp1Dep.add(currentDep);
Cp1TotalHours += hour;
} else {
Cp2.add(currentTask);
Cp2Hour.add(hour);
Cp2Dep.add(currentDep);
Cp2TotalHours += hour;
}
}
else if (Cp1.contains(currentDep) || Cp2.contains(currentDep)) {
//System.out.println ("achou dep" + currentDep );
for (int i=0; i<=taskIndex; i++) {
if (depQe[i].equals(currentDep)){
System.out.println ("achou dep i and curr" + (taskQe[i]) + currentDep );
if ((Cp1.contains(currentDep)&& (Cp1TotalHours <= Cp2TotalHours))){
Cp1.add(taskQe[i]);
Cp1Hour.add(Integer.parseInt(hourQe[i]));
Cp1Dep.add(depQe[i]);
Cp1TotalHours += (Integer.parseInt(hourQe[i]));
}
else if ((Cp2.contains(currentDep)&& (Cp2TotalHours < Cp1TotalHours))){
Cp2.add(taskQe[i]);
Cp2Hour.add(Integer.parseInt(hourQe[i]));
Cp2Dep.add(depQe[i]);
Cp2TotalHours += (Integer.parseInt(hourQe[i]));
}
else if ((!Cp1.contains(currentDep)&& (Cp1TotalHours <= Cp2TotalHours))){
idle = Math.abs(Cp2TotalHours - Cp1TotalHours );
Cp1TotalHours=+idle;
if (Cp1TotalHours <= Cp2TotalHours){
Cp1.add(taskQe[i]);
Cp1Hour.add(Integer.parseInt(hourQe[i]));
Cp1Dep.add(depQe[i]);
Cp1TotalHours += (Integer.parseInt(hourQe[i]));
}
else{
Cp2.add(taskQe[i]);
Cp2Hour.add(Integer.parseInt(hourQe[i]));
Cp2Dep.add(depQe[i]);
Cp2TotalHours += (Integer.parseInt(hourQe[i]));
}
/* for (int j=0; j<taskQe.length; j++) {
if(depQe[i].equals(taskQe[j]))
idle = Math.abs(Integer.parseInt(hourQe[j]) - (Integer.parseInt(hourQe[i])));
Cp1TotalHours=+idle;
}*/
}
else if ((!Cp2.contains(currentDep)&& (Cp2TotalHours < Cp1TotalHours))){
idle = Math.abs(Cp2TotalHours - Cp1TotalHours );
Cp2TotalHours=+idle;
if (Cp2TotalHours < Cp1TotalHours){
Cp2.add(taskQe[i]);
Cp2Hour.add(Integer.parseInt(hourQe[i]));
Cp2Dep.add(depQe[i]);
Cp2TotalHours += (Integer.parseInt(hourQe[i]));
}
else{
Cp1.add(taskQe[i]);
Cp1Hour.add(Integer.parseInt(hourQe[i]));
Cp1Dep.add(depQe[i]);
Cp1TotalHours += (Integer.parseInt(hourQe[i]));
}
/* for (int j=0; j<taskQe.length; j++) {
if(depQe[i].equals(taskQe[j]))
idle = Math.abs(Integer.parseInt(hourQe[j]) - (Integer.parseInt(hourQe[i])));
Cp2TotalHours=+idle;
}*/
}
}
}
}