com.sfs.whichdoctor.beans.PhoneBean.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.whichdoctor.beans.PhoneBean.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.whichdoctor.beans;

import org.apache.commons.lang.StringUtils;

import com.sfs.whichdoctor.formatter.OutputFormatter;

/**
 * The Class PhoneBean.
 *
 * @author David Harrison 30th May 2003 Modified 9th April 2005
 */
public class PhoneBean extends ContactBean {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The number. */
    private String number;

    /** The extension. */
    private String extension;

    /** The area code. */
    private int areaCode;

    /** The country code. */
    private int countryCode;

    /**
     * Sets the number.
     *
     * @param numberVal the new number
     */
    public final void setNumber(final String numberVal) {
        this.number = numberVal;
    }

    /**
     * Gets the number.
     *
     * @return the number
     */
    public final String getNumber() {
        if (this.number == null) {
            this.number = "";
        }
        return this.number;
    }

    /**
     * Sets the extension.
     *
     * @param extensionVal the new extension
     */
    public final void setExtension(final String extensionVal) {
        this.extension = extensionVal;
    }

    /**
     * Gets the extension.
     *
     * @return the extension
     */
    public final String getExtension() {
        if (this.extension == null) {
            this.extension = "";
        }
        return this.extension;
    }

    /**
     * Sets the area code.
     *
     * @param areaCodeVal the new area code
     */
    public final void setAreaCode(final int areaCodeVal) {
        this.areaCode = areaCodeVal;
    }

    /**
     * Gets the area code.
     *
     * @return the area code
     */
    public final int getAreaCode() {
        return this.areaCode;
    }

    /**
     * Sets the country code.
     *
     * @param countryCodeVal the new country code
     */
    public final void setCountryCode(final int countryCodeVal) {
        this.countryCode = countryCodeVal;
    }

    /**
     * Gets the country code.
     *
     * @return the country code
     */
    public final int getCountryCode() {
        return this.countryCode;
    }

    /**
     * Compare the existing phone number with the updated version. If the two
     * are different return true.
     *
     * @param updated the updated
     *
     * @return boolean different
     */
    public final boolean compare(final PhoneBean updated) {
        boolean different = false;

        if (updated == null) {
            different = true;
        } else {
            if (!StringUtils.equals(OutputFormatter.getPhoneNumber(this, true),
                    OutputFormatter.getPhoneNumber(updated, true))) {
                different = true;
            }
            if (this.getPrimary() != updated.getPrimary()) {
                different = true;
            }
            if (!StringUtils.equals(this.getContactType(), updated.getContactType())) {
                different = true;
            }
        }
        return different;
    }
}