Skip to content

Instantly share code, notes, and snippets.

@angeliski
Created January 3, 2019 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeliski/3e1fd2985b44429785ffb884d8421254 to your computer and use it in GitHub Desktop.
Save angeliski/3e1fd2985b44429785ffb884d8421254 to your computer and use it in GitHub Desktop.
import java.util.List;
public class BuscaPessoa {
public PessoaFisica buscaPessoaPorCpf(List pessoas, String cpf) {
for (PessoaFisica pessoaFisica : pessoas) {
if (pessoaFisica.cpf.equals(cpf))
return pessoaFisica;
}
return null;
}
class PessoaFisica {
String cpf;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + ((cpf == null) ? 0 : cpf.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PessoaFisica other = (PessoaFisica) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (cpf == null) {
if (other.cpf != null)
return false;
} else if (!cpf.equals(other.cpf))
return false;
return true;
}
private BuscaPessoa getOuterType() {
return BuscaPessoa.this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment