Всем привет!
При загрузке кидает исключение. Может есть более простой вариант, как положить дату в файл.
ParseException: Unparseable date: "Tue Jun 11 00:00:00 MSD 1991".
Буду рад любой помощи.
package com.javarush.task.task20.task2002;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class User {
private String firstName;
private String lastName;
private Date birthDate;
private boolean isMale;
private Country country;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(String birthDate) throws ParseException {
// this.birthDate = birthDate;
DateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
this.birthDate = format.parse(birthDate);
}
public boolean isMale() {
return isMale;
}
public void setMale(String male) {
if (male.equals("true")) isMale = true;
else isMale = false;
}
public Country getCountry() {
return country;
}
public void setCountry(String country) {
//this.country = country;
Country inputCountry = Country.valueOf(country);
if (inputCountry == Country.RUSSIA) this.country = Country.RUSSIA;
else if (inputCountry == Country.UKRAINE) this.country = Country.UKRAINE;
else this.country = Country.OTHER;
}
public static enum Country {
UKRAINE("Ukraine"),
RUSSIA("Russia"),
OTHER("Other");
private String name;
private Country(String name) {
this.name = name;
}
public String getDisplayName() {
return this.name;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (isMale != user.isMale) return false;
if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null) return false;
if (lastName != null ? !lastName.equals(user.lastName) : user.lastName != null) return false;
if (birthDate != null ? !birthDate.equals(user.birthDate) : user.birthDate != null) return false;
return country == user.country;
}
@Override
public int hashCode() {
int result = firstName != null ? firstName.hashCode() : 0;
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
result = 31 * result + (birthDate != null ? birthDate.hashCode() : 0);
result = 31 * result + (isMale ? 1 : 0);
result = 31 * result + (country != null ? country.hashCode() : 0);
return result;
}
}