001package edu.pdx.cs410J.family; 002 003import java.util.*; 004import java.io.Serializable; 005 006/** 007 * This class represents a marriage between two people. Ain't love 008 * grand? Each marriage consists of a husband, a wife, a date, and a 009 * location. 010 * 011 * @author David Whitlock 012 */ 013public class Marriage implements Serializable { 014 015 private Person husband; 016 private Person wife; 017 private Date date; 018 private String location; 019 020 /** 021 * Creates a marriage between a husband and a wife. It is the 022 * responsibility of the caller to invoke {@link 023 * Person#addMarriage(Marriage)}. 024 * 025 * @throws IllegalArgumentException 026 * The <code>husband</code> is not {@link Person#MALE} or 027 * the <code>wife</code> is not {@link Person#FEMALE}. 028 */ 029 public Marriage(Person husband, Person wife) { 030 if (husband.getGender() != Person.MALE) { 031 String s = "The husband in a Marriage must be MALE"; 032 throw new IllegalArgumentException(s); 033 } 034 035 if (wife.getGender() != Person.FEMALE) { 036 String s = "The wife in a Marriage must be FEMALE"; 037 throw new IllegalArgumentException(s); 038 } 039 040 this.husband = husband; 041 this.wife = wife; 042 } 043 044 /** 045 * Zero-argument constructor used when deserializing 046 */ 047 private Marriage() { 048 049 } 050 051 /** 052 * Returns the husband in this marriage. 053 */ 054 public Person getHusband() { 055 return this.husband; 056 } 057 058 /** 059 * Returns the wife in this marriage. 060 */ 061 public Person getWife() { 062 return this.wife; 063 } 064 065 /** 066 * Returns the date on which the husband and wife were married. 067 */ 068 public Date getDate() { 069 return this.date; 070 } 071 072 /** 073 * Sets the date on which the husband and wife were married. 074 */ 075 public void setDate(Date date) { 076 this.date = date; 077 } 078 079 /** 080 * Returns the location at which the husband and wife were married. 081 */ 082 public String getLocation() { 083 if (this.location == null) { 084 return null; 085 086 } else { 087 return this.location.trim(); 088 } 089 } 090 091 /** 092 * Sets the location at which the husband and wife were married. 093 */ 094 public void setLocation(String location) { 095 this.location = location; 096 } 097 098 /** 099 * Returns a brief description of this marriage. 100 */ 101 public String toString() { 102 StringBuffer sb = new StringBuffer(); 103 sb.append(this.husband.getFullName() + " and " + 104 this.wife.getFullName() + " were married"); 105 106 if (this.date != null) { 107 sb.append(" on " + this.date); 108 } 109 if (this.location != null) { 110 sb.append(" in " + this.location); 111 } 112 113 return sb.toString(); 114 } 115 116}