How to generate with while or do-while several Iterations in an ArrayList of a dataset?

-2

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 several iterations with this data.

For each iteration, I need to delete the first row of the list and multiply all other rows that have true value by 1.1 and those that have false value by 0.9 the iterations must have the same number of rows from 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; 
 }

}
    
asked by anonymous 05.08.2018 / 02:26

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 DataData class, the method for iterating a list with 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 because it will perform the iteration before of the loop continuation test. In that case we would have to do an additional test at the beginning of the loop to test if we did not reach the end of the list.

As the case may be, it may be more practical to use a for-each (or enchanced for ):

void iterarConjuntoDados(List<ConjuntoDados> lista) {
    for(ConjuntoDados conjuntoDados : lista) {
        // faz o que tiver que ser feito com conjuntoDados
    }
}

for the question (delete first line), I think this is not the case for for-each

Just to complement, from Java 8 you can use Stream and Lambda functions to replace loops (example: lista.stream().filter(...).forEach(...) )

    
05.08.2018 / 10:14