/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2002-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.
 */
package org.geotools.styling;

import org.geotools.event.AbstractGTComponent;
import org.geotools.resources.Utilities;
import org.opengis.util.Cloneable;


/**
 *
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/ExtentImpl.java $
 */
public class ExtentImpl extends AbstractGTComponent implements Extent,
    Cloneable {
    private String name;
    private String value;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        String old = this.name;
        this.name = name;

        fireChildChanged("name", this.name, old);
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        String old = this.value;
        this.value = value;

        fireChildChanged("value", this.value, old);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof ExtentImpl) {
            ExtentImpl other = (ExtentImpl) obj;

            return Utilities.equals(this.name, other.name)
            && Utilities.equals(this.value, other.value);
        }

        return false;
    }

    public int hashCode() {
        final int PRIME = 1000003;
        int result = 0;

        if (name != null) {
            result = (PRIME * result) + name.hashCode();
        }

        if (value != null) {
            result = (PRIME * result) + value.hashCode();
        }

        return result;
    }

    public Object clone() {
        try {
            ExtentImpl clone = (ExtentImpl) super.clone();
            clone.setName(name);
            clone.setValue(value);

            return clone;
        } catch (CloneNotSupportedException e) {
            //This will never happen
            throw new RuntimeException("Failed to clone ExtentImpl");
        }
    }
}
