001//@formatter:off 002/* 003 * Person - entity in the first subsystem 004 * Code-Beispiel zum Buch Patterns Kompakt, Verlag Springer Vieweg 005 * Copyright 2014 Karl Eilebrecht 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"): 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019//@formatter:on 020package de.calamanari.pk.mapper.firstsys; 021 022import java.text.SimpleDateFormat; 023import java.util.Date; 024 025/** 026 * Person - entity in the first subsystem 027 * 028 * @author <a href="mailto:Karl.Eilebrecht(a/t)calamanari.de">Karl Eilebrecht</a> 029 */ 030public class Person { 031 032 /** 033 * id of person 034 */ 035 private String personId = null; 036 037 /** 038 * last name 039 */ 040 private String lastName = null; 041 042 /** 043 * first name 044 */ 045 private String firstName = null; 046 047 /** 048 * Date of the first order placed by this person 049 */ 050 private Date firstOrderDate = null; 051 052 /** 053 * Creates new person entity 054 * 055 * @param personId identifier 056 * @param firstName person's first name 057 * @param lastName person's last name 058 * @param firstOrderDateISO (yyyy-MM-dd) 059 */ 060 public Person(String personId, String firstName, String lastName, String firstOrderDateISO) { 061 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 062 this.personId = personId; 063 this.lastName = lastName; 064 this.firstName = firstName; 065 try { 066 this.firstOrderDate = firstOrderDateISO == null ? null : sdf.parse(firstOrderDateISO); 067 } 068 catch (Exception ex) { 069 throw new IllegalArgumentException("Unable to parse firstOrderDateISO='" + firstOrderDateISO + "' as date (expected: yyyy-MM-dd)."); 070 } 071 } 072 073 /** 074 * Returns id of person 075 * 076 * @return personId 077 */ 078 public String getPersonId() { 079 return personId; 080 } 081 082 /** 083 * Returns the person's last name 084 * 085 * @return last name of person 086 */ 087 public String getLastName() { 088 return lastName; 089 } 090 091 /** 092 * Sets the last name of person 093 * 094 * @param lastName person's last name 095 */ 096 public void setLastName(String lastName) { 097 this.lastName = lastName; 098 } 099 100 /** 101 * Returns the first name of the person 102 * 103 * @return firstName 104 */ 105 public String getFirstName() { 106 return firstName; 107 } 108 109 /** 110 * Sets the first name of the person 111 * 112 * @param firstName person's first name 113 */ 114 public void setFirstName(String firstName) { 115 this.firstName = firstName; 116 } 117 118 /** 119 * Returns the date of the first order placed by this person 120 * 121 * @return firstOrderDate 122 */ 123 public Date getFirstOrderDate() { 124 return firstOrderDate; 125 } 126 127 @Override 128 public String toString() { 129 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 130 return this.getClass().getSimpleName() + "({personId=" + personId + ", lastName=" + lastName + ", firstName=" + firstName + ", firstOrderDate=" 131 + (firstOrderDate == null ? null : "'" + sdf.format(firstOrderDate) + "'") + "})"; 132 } 133 134}