3
Guys is the following, I have a model class with attributes that store data returned from the database. For example:
public class RelacaoTransformacao {
/** ID do registro no banco de dados. */
private long id;
/** Indica se o teste já foi concluído. */
private boolean concluido;
/** O valor do teste. */
private double valor;
// ...O restante do código.
}
Taking the code below as an example:
// Percorre o cursor obtendo todos os dados e criando um objeto com os dados retornados.
while ( result.moveToNext() ) {
long id = result.getLong( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_ID.texto ) );
boolean concluido = result.getInt( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_CONCLUIDO.texto ) ) > 0 ;
double valor = result.getDouble( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_VALOR.texto ) );
int polaridade = result.getInt( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_POLARIDADE.texto ) );
String observacao = result.getString( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_OBSERVACAO.texto ) );
long idPrimario = result.getLong( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_FK_ENROLAMENTO_TCTP_ID1.texto ) );
long idSecundario = result.getLong( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.RelacaoTransformacao.COLUNA_FK_ENROLAMENTO_TCTP_ID2.texto ) );
String primario = result.getString( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.EnrolamentoTcTp.COLUNA_ENROLAMENTO.texto ) );
primario += String.valueOf( result.getInt( result.getColumnIndex( br.com.bhdnet.softencal.app.database.enums.EnrolamentoTcTp.COLUNA_NUMERO_ENROLAMENTO.texto ) ) );
RelacaoTransformacao relacaoTransformacao = new RelacaoTransformacao( id, concluido, valor, polaridade, observacao, idPrimario, idSecundario, primario, null );
// Adiciona o objeto enrolamento a lista de enrolamentos
listRelacaoTransformacao.add( relacaoTransformacao );
}
I will always have two repeated objects on my list by the ID attribute, this due to my database search (I don’t need to explain this search, just understand that I really need to return two repeated records, because in a repeat record column the value will be different and I need to get this value). How do I get one of these objects repeated by ID and then remove it from the list?
Which criteria you use to know which of the objects you will remove?
– Math
Reframing the @Math question (which can be interpreted as asking about the duplication criterion, which is two objects having the same ID): assuming there are two objects with the same ID, which of the two should be removed? Anyone?
– Piovezan
It cannot be anyone. What must be removed must be the second object. Only before I remove I’ll take a certain attribute from it, and set on the first object, then after that I can remove it.
– Lucas Santos