Skip to content

Commit

Permalink
Merge 98e2831 into 988fcb5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan White committed Sep 28, 2018
2 parents 988fcb5 + 98e2831 commit 095ff13
Show file tree
Hide file tree
Showing 7 changed files with 993 additions and 320 deletions.
Expand Up @@ -5,79 +5,83 @@

public class Contact {

Contact(String id){
Contact(String id) {
this.identifier = id;
}
private Contact(){}

private Contact() {
}

String identifier;
String displayName, givenName, middleName, familyName, prefix, suffix, company, jobTitle;
String displayName, givenName, middleName, familyName, prefix, suffix, company, jobTitle, note;
ArrayList<Item> emails = new ArrayList<>();
ArrayList<Item> phones = new ArrayList<>();
ArrayList<PostalAddress> postalAddresses = new ArrayList<>();
byte[] avatar = new byte[0];

HashMap<String,Object> toMap(){
HashMap<String,Object> contactMap = new HashMap<>();
HashMap<String, Object> toMap() {
HashMap<String, Object> contactMap = new HashMap<>();
contactMap.put("identifier", identifier);
contactMap.put("displayName",displayName);
contactMap.put("givenName",givenName);
contactMap.put("middleName",middleName);
contactMap.put("familyName",familyName);
contactMap.put("displayName", displayName);
contactMap.put("givenName", givenName);
contactMap.put("middleName", middleName);
contactMap.put("familyName", familyName);
contactMap.put("prefix", prefix);
contactMap.put("suffix", suffix);
contactMap.put("company",company);
contactMap.put("jobTitle",jobTitle);
contactMap.put("avatar",avatar);
contactMap.put("company", company);
contactMap.put("jobTitle", jobTitle);
contactMap.put("avatar", avatar);
contactMap.put("note", note);

ArrayList<HashMap<String,String>> emailsMap = new ArrayList<>();
for(Item email : emails){
ArrayList<HashMap<String, String>> emailsMap = new ArrayList<>();
for (Item email : emails) {
emailsMap.add(email.toMap());
}
contactMap.put("emails",emailsMap);
contactMap.put("emails", emailsMap);

ArrayList<HashMap<String,String>> phonesMap = new ArrayList<>();
for(Item phone : phones){
ArrayList<HashMap<String, String>> phonesMap = new ArrayList<>();
for (Item phone : phones) {
phonesMap.add(phone.toMap());
}
contactMap.put("phones",phonesMap);
contactMap.put("phones", phonesMap);

ArrayList<HashMap<String,String>> addressesMap = new ArrayList<>();
for(PostalAddress address : postalAddresses){
ArrayList<HashMap<String, String>> addressesMap = new ArrayList<>();
for (PostalAddress address : postalAddresses) {
addressesMap.add(address.map);
}
contactMap.put("postalAddresses",addressesMap);
contactMap.put("postalAddresses", addressesMap);

return contactMap;
}

@SuppressWarnings("unchecked")
static Contact fromMap(HashMap map){
static Contact fromMap(HashMap map) {
Contact contact = new Contact();
contact.identifier = (String)map.get("identifier");
contact.givenName = (String)map.get("givenName");
contact.middleName = (String)map.get("middleName");
contact.familyName = (String)map.get("familyName");
contact.prefix = (String)map.get("prefix");
contact.suffix = (String)map.get("suffix");
contact.company = (String)map.get("company");
contact.jobTitle = (String)map.get("jobTitle");
contact.identifier = (String) map.get("identifier");
contact.givenName = (String) map.get("givenName");
contact.middleName = (String) map.get("middleName");
contact.familyName = (String) map.get("familyName");
contact.prefix = (String) map.get("prefix");
contact.suffix = (String) map.get("suffix");
contact.company = (String) map.get("company");
contact.jobTitle = (String) map.get("jobTitle");
contact.avatar = (byte[]) map.get("avatar");
contact.note = (String) map.get("note");

ArrayList<HashMap> emails = (ArrayList<HashMap>) map.get("emails");
if(emails != null){
for(HashMap email : emails){
if (emails != null) {
for (HashMap email : emails) {
contact.emails.add(Item.fromMap(email));
}
}
ArrayList<HashMap> phones = (ArrayList<HashMap>) map.get("phones");
if(phones != null) {
if (phones != null) {
for (HashMap phone : phones) {
contact.phones.add(Item.fromMap(phone));
}
}
ArrayList<HashMap> postalAddresses = (ArrayList<HashMap>) map.get("postalAddresses");
if(postalAddresses != null) {
if (postalAddresses != null) {
for (HashMap postalAddress : postalAddresses) {
contact.postalAddresses.add(PostalAddress.fromMap(postalAddress));
}
Expand Down

0 comments on commit 095ff13

Please sign in to comment.