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

📄 contactdetails.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
/** * Name, address and telephone number details. *  * @author David J. Barnes and Michael Kolling. * @version 2006.03.30 */public class ContactDetails implements Comparable<ContactDetails>{    private String name;    private String phone;    private String address;    /**     * Set up the contact details. All details are trimmed to remove     * trailing white space.     * @param name The name.     * @param phone The phone number.     * @param address The address.     * @throws IllegalStateException If both name and phone are blank.     */    public ContactDetails(String name, String phone, String address)    {        // Use blank strings if any of the arguments is null.        if(name == null) {            name = "";        }        if(phone == null) {            phone = "";        }        if(address == null) {            address = "";        }        this.name = name.trim();        this.phone = phone.trim();        this.address = address.trim();        if(this.name.length() == 0 && this.phone.length() == 0) {            throw new IllegalStateException(                      "Either the name or phone must not be blank.");        }    }        /**     * @return The name.     */    public String getName()    {        return name;    }    /**     * @return The telephone number.     */    public String getPhone()    {        return phone;    }    /**     * @return The address.     */    public String getAddress()    {        return address;    }        /**     * Test for content equality between two objects.     * @param other The object to compare to this one.     * @return true if the argument object is a set     *              of contact details with matching attributes.     */    public boolean equals(Object other)    {        if(other instanceof ContactDetails) {            ContactDetails otherDetails = (ContactDetails) other;            return name.equals(otherDetails.getName()) &&                    phone.equals(otherDetails.getPhone()) &&                     address.equals(otherDetails.getAddress());        }        else {            return false;        }    }    /**     * @return A multi-line string containing the name, phone, and address.     */    public String toString()    {        return name + "\n" + phone + "\n" + address;    }        /**     * Compare these details against another set, for the purpose     * of sorting. The fields are sorted by name, phone, and address.     * @param otherDetails The details to be compared against.     * @return a negative integer if this comes before the parameter,     *         zero if they are equal and a positive integer if this     *         comes after the second.     */    public int compareTo(ContactDetails otherDetails)    {        int comparison = name.compareTo(otherDetails.getName());        if(comparison != 0){            return comparison;        }        comparison = phone.compareTo(otherDetails.getPhone());        if(comparison != 0){            return comparison;        }        return address.compareTo(otherDetails.getAddress());    }    /**     * Compute a hashcode using the rules to be found in     * "Effective Java", by Joshua Bloch.     * @return A hashcode for ContactDetails.     */    public int hashCode()    {        int code = 17;        code = 37 * code + name.hashCode();        code = 37 * code + phone.hashCode();        code = 37 * code + address.hashCode();        return code;    }}

⌨️ 快捷键说明

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