Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created September 12, 2016 19:25
Show Gist options
  • Save gustavo-depaula/ef4c176b520d949786c7ebb71e20408c to your computer and use it in GitHub Desktop.
Save gustavo-depaula/ef4c176b520d949786c7ebb71e20408c to your computer and use it in GitHub Desktop.
classe Data, com verificação
package next.gustavo.empresa;
import java.util.GregorianCalendar;
import java.util.Objects;
/**
* Created by gustavo-depaula on 05/09/16.
*/
public class Data {
private Integer dia;
private Integer mes;
private Integer ano;
public Data(Integer dia, Integer mes, Integer ano) {
GregorianCalendar date = new GregorianCalendar();
date.setLenient(false);
date.set(ano, mes, dia);
try {
date.getTime();
this.dia = dia;
this.mes = mes;
this.ano = ano;
} catch (Exception e){
System.out.println("Essa data aí num dá não parça");
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Data)) return false;
Data data = (Data) o;
return Objects.equals(dia, data.dia) &&
Objects.equals(mes, data.mes) &&
Objects.equals(ano, data.ano);
}
@Override
public int hashCode() {
return 0;
}
public void mostraData() {
System.out.println(dia + "/" + mes + "/" + ano);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment