Skip to content

Commit e4ecc23

Browse files
committed
adding Java Hadouken example :P
1 parent cd49cdc commit e4ecc23

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Mac Files
2+
.DS_Store
3+
4+
5+
# Eclipse files
6+
.classpath
7+
.project
8+
19
# Compiled class file
210
*.class
311

@@ -21,3 +29,4 @@
2129

2230
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2331
hs_err_pid*
32+
/bin/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cc.code;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class ValidationHadouken {
7+
8+
Pessoa p = new Pessoa();
9+
10+
public List<String> validaPessoa(Pessoa pessoa) {
11+
12+
List<String> constraints = new ArrayList<String>();
13+
if (pessoa != null) {
14+
if (pessoa.cpf != null) {
15+
if (pessoa.name != null) {
16+
if (pessoa.telefonesFixos != null) {
17+
for (String telefone : pessoa.telefonesFixos) {
18+
if (telefone != null) {
19+
if (telefone.isEmpty()) {
20+
constraints.add("Erro - Telefone inválido");
21+
return constraints;
22+
} else {
23+
if(telefone.length() < 7){
24+
constraints.add("Erro - Telefone inválido");
25+
return constraints;
26+
}
27+
}
28+
29+
} else {
30+
constraints.add("Erro - Telefone inválido");
31+
return constraints;
32+
}
33+
}
34+
}
35+
else constraints.add("Erro - deveria ter pelo menos um telefone");
36+
}
37+
else constraints.add("Erro - deveria ter nome definido");
38+
}
39+
else constraints.add("Erro - deveria ter cpf definido");
40+
}
41+
42+
return constraints;
43+
}
44+
45+
class Pessoa {
46+
public List<String> telefonesFixos;
47+
public String name;
48+
public String cpf;
49+
}
50+
51+
public static void main(String[] args) {
52+
ValidationHadouken vh = new ValidationHadouken();
53+
vh.p.cpf = "111";
54+
vh.p.name = "name";
55+
vh.p.telefonesFixos = null;
56+
57+
List<String> retorno = vh.validaPessoa(vh.p);
58+
System.out.println(retorno.toString());
59+
60+
}
61+
62+
}
63+

0 commit comments

Comments
 (0)