You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/07/11 01:01:34 UTC

cvs commit: avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/data CategoriesDirective.java CategoryDirective.java

mcconnell    2003/07/10 16:01:34

  Modified:    merlin/meta-spi/src/java/org/apache/avalon/meta/data
                        CategoriesDirective.java CategoryDirective.java
  Log:
  Update equality testing to deal with null values.
  
  Revision  Changes    Path
  1.3       +38 -3     avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/data/CategoriesDirective.java
  
  Index: CategoriesDirective.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/data/CategoriesDirective.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CategoriesDirective.java	10 Jul 2003 19:41:21 -0000	1.2
  +++ CategoriesDirective.java	10 Jul 2003 23:01:34 -0000	1.3
  @@ -84,11 +84,12 @@
        *
        * @param name the base category name
        */
  -    public CategoriesDirective( final Type type )
  +    public CategoriesDirective( CategoryDirective[] categories )
       {
  -        this( type.getInfo().getName(), null, null, new CategoryDirective[ 0 ] );
  +        this( "", null, null, categories );
       }
   
  +
       /**
        * Create a CategoriesDirective instance.
        *
  @@ -141,5 +142,39 @@
           }
           return null;
       }
  +
  +    public boolean equals( Object other )
  +    {
  +        boolean isEqual = other instanceof CategoriesDirective;
  +        if ( isEqual ) isEqual = super.equals( other );
  +
  +        if ( isEqual )
  +        {
  +            CategoriesDirective oLog = (CategoriesDirective) other;
  +            if ( isEqual ) isEqual = m_categories.length == oLog.m_categories.length;
  +            if ( isEqual )
  +            {
  +                for ( int i = 0; i < m_categories.length && isEqual; i++ )
  +                {
  +                    isEqual = m_categories[i].equals( oLog.m_categories[i] );
  +                }
  +            }
  +        }
  +
  +        return isEqual;
  +    }
  +
  +    public int hashCode()
  +    {
  +        int hash = super.hashCode();
  +        for ( int i = 0; i < m_categories.length; i++ )
  +        {
  +            hash >>>= 1;
  +            hash ^= m_categories[i].hashCode();
  +        }
  +
  +        return hash;
  +    }
  +
   
   }
  
  
  
  1.3       +55 -11    avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/data/CategoryDirective.java
  
  Index: CategoryDirective.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/data/CategoryDirective.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CategoryDirective.java	10 Jul 2003 19:41:21 -0000	1.2
  +++ CategoryDirective.java	10 Jul 2003 23:01:34 -0000	1.3
  @@ -189,27 +189,71 @@
   
       public boolean equals(Object other)
       {
  -        boolean isEqual = other instanceof CategoryDirective;
  +        if( null == other )
  +        {
  +            return false;
  +        }
  +
  +        if( ! ( other instanceof CategoryDirective ) )
  +        {
  +            return false;
  +        }
  +
  +        CategoryDirective test = (CategoryDirective) other;
  +        return ( equalName( test.getName() ) 
  +              && equalPriority( test.getPriority() ) 
  +              && equalTarget( test.getTarget() ) );
  +    }
  +
  +    private boolean equalName( String other )
  +    {
  +        if( m_name == null )
  +        {
  +            return other == null;
  +        }
  +        else
  +        {
  +            return m_name.equals( other );
  +        }
  +    }
   
  -        if ( isEqual )
  +    private boolean equalPriority( String other )
  +    {
  +        if( m_priority == null )
  +        {
  +            return other == null;
  +        }
  +        else
           {
  -            CategoryDirective test = (CategoryDirective) other;
  -            isEqual = m_name.equals(test.m_name);
  -            if (isEqual) isEqual = m_priority.equals(test.m_priority);
  -            if (isEqual) isEqual = m_target.equals(test.m_target);
  +            return m_priority.equals( other );
           }
  +    }
   
  -        return isEqual;
  +    private boolean equalTarget( String other )
  +    {
  +        if( m_target == null )
  +        {
  +            return other == null;
  +        }
  +        else
  +        {
  +            return m_target.equals( other );
  +        }
       }
   
       public int hashCode()
       {
           int hash = m_name.hashCode();
           hash >>>= 13;
  -        hash ^= m_priority.hashCode();
  +        if( m_priority != null )
  +        {
  +            hash ^= m_priority.hashCode();
  +        }
           hash >>>= 5;
  -        hash ^= m_target.hashCode();
  -
  +        if( m_target != null )
  +        {
  +            hash ^= m_target.hashCode();
  +        }
           return hash;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org