package com.epam.rd.contactbook;
public class Contact {
public String contactName;
public static int count = 1;
// public static Contact[] info;
public Contact(String contactName) {
this.contactName = contactName;
// info = new Contact[count+1];
// info[count] = this;
// count++;
}
public void rename(String newName) {
if (newName != null && !newName.isEmpty()){
contactName = newName;
}
}
private class NameContactInfo implements ContactInfo{
@Override
public String getTitle() {
return "Name: ";
}
@Override
public String getValue() {
return contactName;
}
}
public static class Email implements ContactInfo{
String email;
String domain;
public Email(String email, String domain) {
this.email = email;
this.domain = domain;
}
@Override
public String getTitle() {
return "Email";
}
@Override
public String getValue() {
return email + "@" + domain;
}
}
public static class Social implements ContactInfo{
String title;
String id;
public Social(String title, String id) {
this.title = title;
this.id = id;
}
@Override
public String getTitle() {
return title;
}
@Override
public String getValue() {
return id;
}
}
public Email addEmail(String localPart, String domain) {
count++;
return new Email(localPart, domain);
}
public Email addEpamEmail(String firstname, String lastname) {
count++;
String fullname = firstname + "_" + lastname;
Email epamEmail = new Email(fullname,"epam.com") {
@Override
public String getTitle() {
return "Epam Email";
}
};
return epamEmail;
}
public ContactInfo addPhoneNumber(int code, String number) {
count++;
ContactInfo phoneNumber = new ContactInfo() {
@Override
public String getTitle() {
return "Tel";
}
@Override
public String getValue() {
return "+" + code + " " + number;
}
};
return phoneNumber;
}
public Social addTwitter(String twitterId) {
count++;
Social twitter = new Social("Twitter", twitterId){
};
return twitter;
}
public Social addInstagram(String instagramId) {
count++;
Social instagram = new Social("Instagram", instagramId){
};
return instagram;
}
public Social addSocialMedia(String title, String id) {
count++;
Social socialMedia = new Social(title, id){
};
return socialMedia;
}
public ContactInfo[] getInfo() {
ContactInfo[] info = new ContactInfo[count];
// info[0] = (ContactInfo) this;
// return (ContactInfo[]) info;
// ContactInfo[] contactInfo = {Contact.NameContactInfo.getValue(), Contact.Email.getValue(), Contact.Social.getValue()};
// return contactInfo;
return info;
}
}