svn commit: rev 30905 - in avalon/trunk/runtime/framework/impl/src: java/org/apache/avalon/framework/configuration test/org/apache/avalon/framework/configuration/test
[email protected] 29 Jul 2004 06:38:12 -0000
Newsgroups
gmane.comp.jakarta.avalon.cvs
Message-ID
<[email protected] >
Author: niclas
Date: Wed Jul 28 23:38:11 2004
New Revision: 30905
Modified:
avalon/trunk/runtime/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java
avalon/trunk/runtime/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java
Log:
Configuration equality testcase addded. Note this testcase fails, due to a semantic bug in Framework.
Modified: avalon/trunk/runtime/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java
==============================================================================
--- avalon/trunk/runtime/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java (original)
+++ avalon/trunk/runtime/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java Wed Jul 28 23:38:11 2004
@@ -733,8 +733,10 @@
*/
public boolean equals( Object other )
{
- if( other == null ) return false;
- if( !( other instanceof Configuration ) ) return false;
+ if( other == null )
+ return false;
+ if( !( other instanceof Configuration ) )
+ return false;
return ConfigurationUtil.equals( this, (Configuration) other );
}
@@ -746,17 +748,23 @@
public int hashCode()
{
int hash = m_prefix.hashCode();
- if( m_name != null ) hash ^= m_name.hashCode();
+ if( m_name != null )
+ hash ^= m_name.hashCode();
hash >>>= 7;
- if( m_location != null ) hash ^= m_location.hashCode();
+ if( m_location != null )
+ hash ^= m_location.hashCode();
hash >>>= 7;
- if( m_namespace != null ) hash ^= m_namespace.hashCode();
+ if( m_namespace != null )
+ hash ^= m_namespace.hashCode();
hash >>>= 7;
- if( m_attributes != null ) hash ^= m_attributes.hashCode();
+ if( m_attributes != null )
+ hash ^= m_attributes.hashCode();
hash >>>= 7;
- if( m_children != null ) hash ^= m_children.hashCode();
+ if( m_children != null )
+ hash ^= m_children.hashCode();
hash >>>= 7;
- if( m_value != null ) hash ^= m_value.hashCode();
+ if( m_value != null )
+ hash ^= m_value.hashCode();
hash >>>= 7;
hash ^= ( m_readOnly ) ? 1 : 3;
return hash;
Modified: avalon/trunk/runtime/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java
==============================================================================
--- avalon/trunk/runtime/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java (original)
+++ avalon/trunk/runtime/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java Wed Jul 28 23:38:11 2004
@@ -237,5 +237,35 @@
assertEquals( 1, root.getChildren( "immutable-child" ).length );
assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute( "attr" ) );
}
+
+ public void testEquals()
+ throws Exception
+ {
+ DefaultConfiguration a = createSimple( "1", "2" );
+ DefaultConfiguration b = createSimple( "2", "1" );
+
+ assertEquals( "order test", a, b );
+
+ String value1 = a.getChild( "child" ).getValue();
+ String value2 = b.getChild( "child" ).getValue();
+
+ assertEquals( "value equality", value1, value2 );
+ }
+
+ private DefaultConfiguration createSimple( String value1, String value2 )
+ throws Exception
+ {
+ DefaultConfiguration conf = new DefaultConfiguration( "root", "0:0", "http://root", "root" );
+ DefaultConfiguration child1 = new DefaultConfiguration( "child", "0:1", "http://root/child", "child" );
+ child1.setValue( value1 );
+ conf.addChild( child1 );
+
+ DefaultConfiguration child2 = new DefaultConfiguration( "child", "0:2", "http://root/child", "child" );
+ child2.setValue( value2 );
+ conf.addChild( child2 );
+
+ conf.makeReadOnly();
+ return conf;
+ }
}