⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contact.java

📁 moblie syncml mail javame
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                setNickName(value);

            } 
            else if ("FN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:".equals(name)) {
                try {
                    String decoded = QuotedPrintable.decode(value.getBytes("UTF-8"), "UTF-8");
                    setNickName(decoded);
                } catch (UnsupportedEncodingException uee) {
                    uee.printStackTrace();
                    Log.error("[Contact] Parser Failure encoding UTF-8 QP");
                }
                
            }
            
            else if ("N:".equals(name)) {                     // Name
                String[] names = StringUtil.split(value, ";");
                //We set only the first given name.
                //The others are ignored in input and will not be
                //overridden on the server in output.
                setFirstName(names[1]);
                setLastName(names[0]);

            } else if ("N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:".equals(name)) {
                try {
                    String decoded = QuotedPrintable.decode(value.getBytes("UTF-8"), "UTF-8");
                    String[] names = StringUtil.split(decoded, ";");
                    //We set only the first given name.
                    //The others are ignored in input and will not be
                    //overridden on the server in output.
                    setFirstName(names[1]);
                    setLastName(names[0]);
                } catch (UnsupportedEncodingException uee) {
                    uee.printStackTrace();
                    Log.error("[Contact] Parser Failure encoding UTF-8 QP");
                }
                
            }
            
            else if ("EMAIL;INTERNET:".equals(name)) {        // Email
                if (checkEmail(value)) {
                    setDefaultEmail(value);
                }

            } else if ("EMAIL;INTERNET;HOME:".equals(name)) {   // 2nd Email
                if (checkEmail(value)) {
                    setEmail_2(value);
                }
            } else if ("EMAIL;INTERNET;WORK:".equals(name)) {   // 3rd Email
                if (checkEmail(value)) {
                    setEmail_3(value);
                }
            } else if ("TEL;VOICE;WORK:".equals(name)) {        // work phone
                setJobPhone(value);

            } else if ("TEL;VOICE;HOME:".equals(name)) {        // home phone
                setHomePhone(value);

            } else if ("TEL;CELL:".equals(name)) {              // cell phone
                setMobilePhone(value);
            } 
        }
    }
    
    
    public  boolean  checkEmail(String email) {
        
        return ( email != null && !"".equals(email) && email.indexOf("@")!=-1) ;
        
    }
    
    public void setNickName(String newNickName) {
        this.nickName = newNickName;
    }
    
    public String getNickName() {
        return this.nickName;
    }
    
    public String getVisibleName() {
        if (!StringUtil.isNullOrEmpty(this.nickName)) {
            return this.nickName;
        }
        if (!StringUtil.isNullOrEmpty(this.firstName)) {
            if (!StringUtil.isNullOrEmpty(this.lastName)) {
                return (this.firstName + " " + this.lastName).trim();
            }
            return firstName;
        } else if (!StringUtil.isNullOrEmpty(this.lastName)&&
                    StringUtil.isNullOrEmpty(this.firstName)) {
            return this.lastName;
        }
        return this.defaultEmail;
    }
    
    public void setContactId(int newContactId) {
        this.contactId = newContactId;
    }
    
    public int getContactId() {
        return this.contactId;
    }
    
    public String getFirstName(){
        return this.firstName;
    }
    
    public void setFirstName(String name){
        this.firstName = name;
    }
    
    public String getLastName(){
        return this.lastName;
    }
    
    public void setLastName(String name){
        this.lastName = name;
    }
    
    public String getDefaultEmail(){
        return this.defaultEmail;
    }
    
    public void setDefaultEmail(String email) throws ContactManagerException {
        if (StringUtil.isNullOrEmpty(email)) {
            throw new ContactManagerException("Empty email");
        } else {
            this.defaultEmail = email;
        }
    }
    
    public String getEmail_2(){
        return this.email_2;
    }
    
    public void setEmail_2(String email){
        this.email_2 = email;
    }
    
    public String getEmail_3(){
        return this.email_3;
    }
    
    public void setEmail_3(String email){
        this.email_3 = email;
    }
    
    public String getHomePhone(){
        return this.homePhone;
    }
    
    public void setHomePhone(String phone){
        this.homePhone = phone;
    }
    
    public String getMobilePhone(){
        return this.mobilePhone;
    }
    
    public void setMobilePhone(String mobile){
        this.mobilePhone = mobile;
    }
    
    public String getJobPhone(){
        return this.jobPhone;
    }
    
    public void setJobPhone(String job){
        this.jobPhone = job;
    }
    
    public Address getAddress(int type) throws MailException {
        return getAddress(type, DEFAULT_EMAIL);
    }
    
    
    /**
     *
     * @return an address with given type and email index
     *
     * @param type one of Address.TO, Address.CC, Address.BCC, Address.FROM
     * Address.REPLYTO
     * @param emailType one of DEFAULT_EMAIL, SECONDARY_EMAIL, TERTIARY_EMAIL;
     */
    public Address getAddress(int type, int emailType) throws MailException{
        String email;
        switch (emailType) {
            case DEFAULT_EMAIL:
                email = this.getDefaultEmail();
                break;
            case SECONDARY_EMAIL:
                email = this.getEmail_2();
                break;
            case TERTIARY_EMAIL:
                email = this.getEmail_3();
                break;
            default:
                email = this.getDefaultEmail();
                break;
        }
        return new Address(type, this.getVisibleName(), email);
        
    }
    
    /**
     * @return String representation of a contact
     */
    public String toString() {
        String out = "\n" + this.contactId + "\n" +
                this.getVisibleName() + "\n" +
                this.nickName + "\n" +
                this.firstName + "\n" +
                this.lastName + "\n" +
                this.defaultEmail + "\n" +
                this.email_2 + "\n" +
                this.email_3 + "\n" +
                this.homePhone + "\n" +
                this.jobPhone + "\n" +
                this.mobilePhone + "\n";
        return out;
    }
    
    /**
     * Returns equality between two contacts
     * @param c is the contact to be compared
     * @return true if all c1 contacts fields are equal to c2 fields
     */
    public boolean equals(Contact c) {
        return (this.getVisibleName().equals(c.getVisibleName())&&
            this.getFirstName().equals(c.getFirstName())&&
            this.getLastName().equals(c.getLastName())&&
            this.getNickName().equals(c.getNickName())&&
            this.getDefaultEmail().equals(c.getDefaultEmail())&&
            this.getEmail_2().equals(c.getEmail_2())&&
            this.getEmail_3().equals(c.getEmail_3())&&
            this.getHomePhone().equals(c.getHomePhone())&&
            this.getJobPhone().equals(c.getJobPhone())&&
            this.getMobilePhone().equals(c.getMobilePhone())
        );
    }    
    
    /**
     * Append the field to the StringBuffer out if not null.
     */
    private void appendField(StringBuffer out, String name, String val) {
        if (val != null) {
            out.append(name).append(val).append(NL);
        }
    }

    /**
     * Format null field as "";
     */
    private String nullFieldFormatter(String s) {
        if (s==null) {
            return "";
        } else {
            return s;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -