// $Header$
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/

 package org.apache.jmeter.testelement.property;

import org.apache.jmeter.testelement.TestElement;

/**
 * @version $Revision$
 */
public class TestElementProperty extends MultiProperty
{
    TestElement value;
    TestElement savedValue = null;

    public TestElementProperty(String name, TestElement value)
    {
        super(name);
        this.value = value;
    }

    public TestElementProperty()
    {
        super();
    }

    public boolean equals(Object o)
    {
        if (o instanceof TestElementProperty)
        {
            if (value != null)
            {
                return value.equals(((JMeterProperty) o).getObjectValue());
            }
        }
        return false;
    }
    public int hashCode()
	{
    	return value == null ? 0 : hashCode();
    }

    /* (non-Javadoc)
     * #getStringValue()
     */
    public String getStringValue()
    {
        return value.toString();
    }

    public void setObjectValue(Object v)
    {
        if (v instanceof TestElement)
        {
            value = (TestElement) v;
        }
    }

    /* (non-Javadoc)
     * #getObjectValue()
     */
    public Object getObjectValue()
    {
        return value;
    }

    public TestElement getElement()
    {
        return value;
    }

    public void setElement(TestElement el)
    {
        value = el;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#clone()
     */
    public Object clone()
    {
        TestElementProperty prop = (TestElementProperty) super.clone();
        prop.value = (TestElement) value.clone();
        return prop;
    }

    /* (non-Javadoc)
     * #mergeIn(JMeterProperty)
     */
    public void mergeIn(JMeterProperty prop)
    {
        if (isEqualType(prop))
        {
            value.addTestElement((TestElement) prop.getObjectValue());
        }
    }

    /* (non-Javadoc)
     * #recoverRunningVersion(TestElement)
     */
    public void recoverRunningVersion(TestElement owner)
    {
        if (savedValue != null)
        {
            value = savedValue;
        }
        value.recoverRunningVersion();
    }

    /* (non-Javadoc)
     * #setRunningVersion(boolean)
     */
    public void setRunningVersion(boolean runningVersion)
    {
        super.setRunningVersion(runningVersion);
        value.setRunningVersion(runningVersion);
        if(runningVersion)
        {
            savedValue = value;
        }
        else
        {
            savedValue = null;
        }
    }

    /* (non-Javadoc)
     * @see MultiProperty#addProperty(JMeterProperty)
     */
    public void addProperty(JMeterProperty prop)
    {
        value.setProperty(prop);
    }

    /* (non-Javadoc)
     * @see MultiProperty#clear()
     */
    public void clear()
    {
        value.clear();

    }

    /* (non-Javadoc)
     * @see MultiProperty#iterator()
     */
    public PropertyIterator iterator()
    {
        return value.propertyIterator();
    }
}

@@ -1055,32 +1055,241 @@
 super();%0A    %7D%0A%0A
+    /**%0A     * Determines if two test elements are equal.%0A     * %0A     * @return true if the value is not null and equals the other Objects value;%0A     * false otherwise (even if both values are null)%0A     */%0A
     public boole
@@ -1308,16 +1308,16 @@
 ject o)%0A
-
     %7B%0A  
@@ -1362,32 +1362,69 @@
 erty)%0A        %7B%0A
+        %09if (this == o) return true;%0A
             if (
@@ -1609,16 +1609,16 @@
 de()%0A%09%7B%0A
-
     %09ret
@@ -1641,16 +1641,22 @@
 l ? 0 : 
+value.
 hashCode

Fix bug (recursive call in hashCode()) introduced just now and document equals method