How to generate with while or do-while multiple Iterations in an Arraylist of a data set?

Asked

Viewed 75 times

-1

I have the following data set in an arraylist.

Conference,Conference,1.0,1.0,1.0,1.0,1.0,1.0,true,1.0, 01,6.0
Reviewer,Reviewer,1.0,1.0,1.0,1.0,1.0,1.0,false,1.0, 01,6.0
Review,Review,1.0,1.0,1.0,1.0,1.0,1.0,true,1.0, 01,6.0
Person,Person,1.0,1.0,1.0,1.0,1.0,1.0,true,1.0, 01,6.0
Paper,Paper,1.0,1.0,1.0,1.0,1.0,1.0,false,1.0, 01,6.0
ProgramCommittee,Program_committee,0.98,0.75,0.81,1.0,1.0,1.0,true,1.0, 01,5.54
ProgramCommitteeMember,Committee_member,0.81,0.62,0.57,1.0,1.0,1.0,false,1.0, 21,5.0
Co-author,Contribution_co-author,0.63,0.62,0.57,1.0,1.0,1.0,true,1.0, 21,4.82
Preference,Review_preference,0.6,0.42,0.58,1.0,1.0,1.0,true,1.0, 21,4.6

I need to generate multiple iterations with this data.

For each iteration, I need to delete the first line from the list and multiply all other lines that have value true by 1.1 and those that have value false by 0.9 iterations must have the same number of rows in the list.

At first, I understood that I should create a Java Class Arraylist below:

public class Candidatas {

public String entidade1;
public String entidade2;
public double m1;
public double m2;
public double m3;
public double m4;
public double m5;
public double m6;
public String tipo;
public double mm;
public String id;
public double mm1;


public String getEntidade1() {
return entidade1;
}

public void setEntidade1(String entidade1) {
this.entidade1 = entidade1;
} 

public String getEntidade2() {
return entidade2;
}

public void setEntidade2(String entidade2) {
this.entidade2 = entidade2;
}

public double getM1() {
return m1;
}

public void setM1(double m1) {
this.m1 = m1;
}

public double getM2() {
return m2;
}

public void setM2(double m2) {
this.m2 = m2;
}

public double getM3() {
return m3;
}

public void setM3(double m3) { 
this.m3 = m3;
} 
public double getM4() {
return m4;
}

public void setM4(double m4) {
this.m4 = m4;
}

public double getM5() {
return m5;
}

public void setM5(double m5) {
this.m5 = m5;
}

public double getM6() {
return m6;
}

public void setM6(double m6) {
this.m6 = m6;
}

public String getTipo() {
return tipo;
}

public void setTipo(String tipo) {
this.tipo = tipo;
} 

public double getMm() {
return mm;
}

public void setMm(double mm) {
this.mm = mm;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public double getMm1() {
return mm1;
}

public void setMm1(double mm1) {
this.mm1 = mm1; 
 }

}
  • Yes, at the end the list will be empty. The number of iterations will be equal to the number of rows in the dataset. But for each iteration, I will have to multiply the values on the lines that have true by 1.1 and those that have false by 0.9.

  • the result will appear in the iterations.

  • Hello! Share with us the code you have tried to do to resolve the problem

1 answer

0

It is difficult to understand the question, here an attempt to answer the question: "how to iterate a List using while or do-while?".

Assuming we have a Conjunctodate class, the method for iterating a list of instances of that class would be:

void iterarConjuntoDados(List<ConjuntoDados> lista) {
    Iterator<ConjuntoDados> iterator = lista.iterator();
    while (iterator.hasNext()) {
        ConjuntoDados conjuntoDados = iterator.next();
        // faz o que tiver que ser feito com conjuntoDados
    }
}

The do-while is not advisable in this case as it will perform the iteration before loop continuation test. In that case we would have to do an additional test at the beginning of the loop to test if we didn’t get to the end of the list.

  • It’s because I need to have as many iterations as the list size. I could only generate one iteration with For.

  • And for each iteration the program must multiply the results of previous iterations by 0.9 if the line is false or by 1.1 if the line is true. It will perform iterations and multiply by 1.1 or 0.9 until the initial list is empty and at the end only all iterations remain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.