Created
January 3, 2019 23:25
-
-
Save angeliski/f3607074bc3681a33ea729259a666bc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
public class BuscaPessoa { | |
public PessoaFisica buscaPessoaPorCpf(List pessoas, String cpf) { | |
PessoaFisica pessoaFisica = new PessoaFisica(); | |
pessoaFisica.cpf = cpf; | |
int indexOfPessoa = pessoas.indexOf(pessoaFisica); | |
if (indexOfPessoa > 0) { | |
return pessoas.get(indexOfPessoa); | |
} | |
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