Created
January 3, 2019 23:24
-
-
Save angeliski/3e1fd2985b44429785ffb884d8421254 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) { | |
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