@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Birthday birthday = new Birthday(); String gender = reader.getAttribute("gender"); if (gender != null) { if (gender.length() > 0) { if (gender.startsWith("f")) { birthday.setGenderFemale(); } else if (gender.startsWith("m")) { birthday.setGenderMale(); } else { throw new ConversionException("Invalid gender value: " + gender); } } else { throw new ConversionException("Empty string is invalid gender value"); } } while (reader.hasMoreChildren()) { reader.moveDown(); if ("person".equals(reader.getNodeName())) { Person person = (Person) context.convertAnother(birthday, Person.class); birthday.setPerson(person); } else if ("birth".equals(reader.getNodeName())) { Calendar date = (Calendar) context.convertAnother(birthday, Calendar.class); birthday.setDate(date); } reader.moveUp(); } return birthday; }
private static Birthday toBirthday(final ResultSet rs, final int rowNum) throws SQLException { final Birthday birthday = new Birthday(); birthday.setId(rs.getString("MIG_ID").trim()); birthday.setName(String.join(" ", rs.getString("MIG_VORNAME"), rs.getString("MIG_NACHNAME"))); final LocalDate birthdate = asLocalDate(rs.getDate("MIG_GEB_DAT")); if (birthdate != null) { birthday.setDateOfBirth(birthdate.toString()); birthday.setMonth(birthdate.getMonth().getValue()); birthday.setDay(birthdate.getDayOfMonth()); birthday.setAge(ageOf(birthdate)); } return birthday; }
@Override public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) { // To change body of implemented methods use File | Settings | File Templates. Birthday birthday = (Birthday) o; if (birthday.getGender() != '\0') { writer.addAttribute("gender", Character.toString(birthday.getGender())); } if (birthday.getPerson() != null) { writer.startNode("person"); context.convertAnother(birthday.getPerson()); writer.endNode(); } if (birthday.getDate() != null) { writer.startNode("birth"); context.convertAnother(birthday.getDate()); writer.endNode(); } }
public String getBirthday() { if (birthday == null) { getLoginState(); } return birthday.getDateString(false); }
/** * Slight optimization. Why do we need to convert idate to year, month, day and put it in a * calendar so that we can take out the year, month, and day data from the calendar again when * checking the birthday? All birthday information is sent in the same format, so just use this as * a common method to reduce redundancy. */ public boolean checkBirthDate(int idate) { if (birthday == null) { getLoginState(); } return birthday.equals(idate); }
/** * Check if the user's real birthday matches with another Birthday object * * @param birthday Birthday that holds the year, month, and day of the values to be compared. * @return */ public boolean equals(Birthday birthday) { return this == birthday || equals(birthday.getYear(), birthday.getMonth(), birthday.getDay()); }