/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
 *    
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    This package contains documentation from OpenGIS specifications.
 *    OpenGIS consortium's work is fully acknowledged here.
 */
package org.geotools.metadata.iso.citation;

import java.util.Collection;
import org.opengis.metadata.citation.Telephone;
import org.geotools.metadata.iso.MetadataEntity;


/**
 * Telephone numbers for contacting the responsible individual or organization.
 *
 * @author Jody Garnett
 * @author Martin Desruisseaux
 *
 * @since 2.1
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/metadata/iso/citation/TelephoneImpl.java $
 */
public class TelephoneImpl extends MetadataEntity implements Telephone {
    /**
     * Serial number for interoperability with different versions.
     */
    private static final long serialVersionUID = 4920157673337669241L;

    /**
     * Telephone numbers by which individuals can speak to the responsible organization or
     * individual.
     */
    private Collection voices;

    /**
     * Telephone numbers of a facsimile machine for the responsible organization or individual.
     */
    private Collection facsimiles;

    /**
     * Constructs a default telephone.
     */
    public TelephoneImpl() {
    }

    /**
     * Constructs a metadata entity initialized with the values from the specified metadata.
     *
     * @since 2.4
     */
    public TelephoneImpl(final Telephone source) {
        super(source);
    }

    /**
     * Returns the telephone number by which individuals can speak to the responsible
     * organization or individual.
     *
     * @deprecated Replaced by {@link #getVoices}.
     */
    public synchronized String getVoice() {
        return voices == null || voices.isEmpty() ? null : (String) voices.iterator().next();
    }

    /**
     * Returns the telephone numbers by which individuals can speak to the responsible
     * organization or individual.
     *
     * @since 2.4
     */
    public synchronized Collection getVoices() {
        return voices = nonNullCollection(voices, String.class);
    }

    /**
     * Set the telephone number by which individuals can speak to the responsible
     * organization or individual.
     *
     * @deprecated Replaced by {@link #setVoices}.
     */
    public void setVoice(final String newValue) {
        setVoices(java.util.Collections.singleton(newValue));
    }

    /**
     * Set the telephone numbers by which individuals can speak to the responsible
     * organization or individual.
     *
     * @since 2.4
     */
    public synchronized void setVoices(final Collection newValues) {
        voices = copyCollection(newValues, voices, String.class);
    }

    /**
     * Returns the telephone number of a facsimile machine for the responsible organization
     * or individual.
     *
     * @deprecated Replaced by {@link #getFacsimiles}.
     */
    public synchronized String getFacsimile() {
        return facsimiles == null || facsimiles.isEmpty() ? null :
            (String) facsimiles.iterator().next();
    }

    /**
     * Returns the telephone numbers of a facsimile machine for the responsible organization
     * or individual.
     *
     * @since 2.4
     */
    public synchronized Collection getFacsimiles() {
        return facsimiles = nonNullCollection(facsimiles, String.class);
    }

    /**
     * Set the telephone number of a facsimile machine for the responsible organization
     * or individual.
     *
     * @deprecated Replaced by {@link #setFacsimiles}.
     */
    public void setFacsimile(final String newValue) {
        setFacsimiles(java.util.Collections.singleton(newValue));
    }

    /**
     * Set the telephone number of a facsimile machine for the responsible organization
     * or individual.
     *
     * @since 2.4
     */
    public synchronized void setFacsimiles(final Collection newValues) {
        facsimiles = copyCollection(newValues, facsimiles, String.class);
    }
}
