update projects.
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
reservationsystem
|
||||
*/
|
||||
package edu.addressbook.model;
|
||||
|
||||
public final class Address{
|
||||
|
||||
String street;
|
||||
String city;
|
||||
String state;
|
||||
String zip;
|
||||
|
||||
/** not used
|
||||
*
|
||||
*/
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String street, String city, String state, String zip) {
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((street == null) ? 0 : street.hashCode());
|
||||
result = prime * result + ((city == null) ? 0 : city.hashCode());
|
||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||
result = prime * result + ((zip == null) ? 0 : zip.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Address other = (Address) obj;
|
||||
if (street == null) {
|
||||
if (other.street != null)
|
||||
return false;
|
||||
} else if (!street.equals(other.street))
|
||||
return false;
|
||||
if (city == null) {
|
||||
if (other.city != null)
|
||||
return false;
|
||||
} else if (!city.equals(other.city))
|
||||
return false;
|
||||
if (state == null) {
|
||||
if (other.state != null)
|
||||
return false;
|
||||
} else if (!state.equals(other.state))
|
||||
return false;
|
||||
if (zip == null) {
|
||||
if (other.zip != null)
|
||||
return false;
|
||||
} else if (!zip.equals(other.zip))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{ \"Address\":{");
|
||||
sb.append("\"street\": \"" + street + "\",");
|
||||
sb.append("\"city\": \"" + city + "\",");
|
||||
sb.append("\"state\": \"" + state + "\",");
|
||||
sb.append("\"zip\": \"" + zip + "\"");
|
||||
sb.append("}}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
reservationsystem
|
||||
*/
|
||||
package edu.addressbook.model;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Concrete account data class for account json storage record.
|
||||
* Collects account attributes, and hash instance to enforce uniqueness.
|
||||
*/
|
||||
public class Contact {
|
||||
private Integer contact_id = null;
|
||||
private String phone_number;
|
||||
private Address mailing_address;
|
||||
private EmailAddress email_address;
|
||||
|
||||
public Contact() {
|
||||
|
||||
}
|
||||
|
||||
public Contact(
|
||||
String phone_number,
|
||||
Address mailing_address,
|
||||
EmailAddress email_address) {
|
||||
this.phone_number = phone_number;
|
||||
this.mailing_address = mailing_address;
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
public Contact(Address mailing_address, EmailAddress email_address)
|
||||
throws IllegalArgumentException {
|
||||
if (phone_number == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number",
|
||||
mailing_address.toString()));
|
||||
}
|
||||
if (mailing_address == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires mailing address",
|
||||
phone_number.substring(phone_number.length() - 4)));
|
||||
}
|
||||
if (email_address == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number",
|
||||
mailing_address.toString()));
|
||||
}
|
||||
|
||||
this.phone_number = phone_number;
|
||||
this.mailing_address = mailing_address;
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{ \"Account\":{");
|
||||
sb.append("\"account_number\": \"").append(contact_id).append("\",");
|
||||
sb.append("\"phone_number\": \"").append(phone_number).append("\",");
|
||||
sb.append("\"mailing_address\": ").append(mailing_address).append(",");
|
||||
sb.append("\"email_address\": ").append(email_address).append(",");
|
||||
sb.append("}}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void Write(Contact acct) throws IOException {
|
||||
}
|
||||
|
||||
public String getPhone_number() {
|
||||
return phone_number;
|
||||
}
|
||||
|
||||
public void setPhone_number(String phone_number) {
|
||||
this.phone_number = phone_number;
|
||||
}
|
||||
|
||||
public Address getMailing_address() {
|
||||
return mailing_address;
|
||||
}
|
||||
|
||||
public void setMailing_address(Address mailing_address) {
|
||||
this.mailing_address = mailing_address;
|
||||
}
|
||||
|
||||
public EmailAddress getEmail_address() {
|
||||
return email_address;
|
||||
}
|
||||
|
||||
public void setEmail_address(EmailAddress email_address) {
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((contact_id == null) ? 0 : contact_id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Contact other = (Contact) obj;
|
||||
if (contact_id == null) {
|
||||
if (other.contact_id != null)
|
||||
return false;
|
||||
} else if (!contact_id.equals(other.contact_id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
if (email_address == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, email_address %s", this.contact_id));
|
||||
}
|
||||
if (phone_number == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, phone_number: %s", this.contact_id));
|
||||
}
|
||||
if (getMailing_address() == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, mailing_address: %s", this.contact_id));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void update(Contact acct) {
|
||||
this.setEmail_address(acct.email_address);
|
||||
this.setPhone_number(acct.phone_number);
|
||||
this.setMailing_address(acct.mailing_address);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
reservationsystem
|
||||
*/
|
||||
package edu.addressbook.model;
|
||||
|
||||
public class EmailAddress{
|
||||
String email_address;
|
||||
|
||||
public EmailAddress(String email_address) {
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
public String getEmail_address() {
|
||||
return email_address;
|
||||
}
|
||||
|
||||
public void setEmail_address(String email_address) {
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((email_address == null) ? 0 : email_address.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
EmailAddress other = (EmailAddress) obj;
|
||||
if (email_address == null) {
|
||||
if (other.email_address != null)
|
||||
return false;
|
||||
} else if (!email_address.equals(other.email_address))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{ \"EmailAddress\":{");
|
||||
sb.append("\"email\": \"" + email_address + "\"");
|
||||
sb.append("}}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
module edu.addressbook {
|
||||
|
||||
exports edu.addressbook;
|
||||
}
|
||||
Reference in New Issue
Block a user