You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/03/29 21:02:33 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/om ComboKey.java

jmcnally    01/03/29 11:02:33

  Modified:    src/java/org/apache/turbine/om ComboKey.java
  Log:
  tightened up the equals method, so that a ComboKey with null parts is not
  considered equal to another ComboKey.  This is in line with the definition of equals in the other Keys.  Added a looseEquals method that will give true when comparing keys with null pieces.
  
  Revision  Changes    Path
  1.10      +35 -5     jakarta-turbine/src/java/org/apache/turbine/om/ComboKey.java
  
  Index: ComboKey.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/om/ComboKey.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ComboKey.java	2001/03/27 18:10:50	1.9
  +++ ComboKey.java	2001/03/29 19:02:32	1.10
  @@ -56,6 +56,7 @@
   
   import java.util.ArrayList;
   import org.apache.turbine.util.TurbineException;
  +import org.apache.turbine.util.ObjectUtils;
   
   /**
    * This class can be used as an ObjectKey to uniquely identify an 
  @@ -249,6 +250,31 @@
       }
   
       /**
  +     * This method will return true if the conditions for a looseEquals
  +     * are met and in addition no parts of the keys are null.
  +     */
  +    public boolean equals(Object keyObj)
  +    {
  +        boolean isEqual = false;
  +
  +        if ( key != null ) 
  +        {
  +            // check that all keys are not null
  +            isEqual = true;
  +            SimpleKey[] keys = (SimpleKey[])key;
  +            for ( int i=0; i<keys.length && isEqual; i++ ) 
  +            {
  +                isEqual &= keys[i] != null && keys[i].getValue() != null;
  +            }
  +
  +            isEqual &= looseEquals(keyObj);
  +        }
  +
  +        return isEqual;
  +    }
  +
  +
  +    /**
        * keyObj is equal to this ComboKey if keyObj is a ComboKey, String, 
        * ObjectKey[], or String[] that contains the same information this key
        * contains. 
  @@ -257,14 +283,18 @@
        * Another example, would be if keyObj is an ComboKey that was 
        * instantiated with a ObjectKey[] and this ComboKey was instantiated with
        * a String[], but the ObjectKeys in the ObjectKey[] were instantiated 
  -     * with Strings that equal the Strings in this KeyObject's String[]. 
  +     * with Strings that equal the Strings in this KeyObject's String[]
  +     * This method is not as strict as the equals method which does not
  +     * allow any null keys parts, while the internal key may not be null
  +     * portions may be, and the two object will be considered equal if
  +     * their null portions match. 
        */
  -    public boolean equals(Object keyObj)
  +    public boolean looseEquals(Object keyObj)
       {
           boolean isEqual = false;
   
           if ( key != null ) 
  -        { 
  +        {
               // Checks  a compound key (ObjectKey[] or String[]
               // based) with the delimited String created by the
               // toString() method.  Slightly expensive, but should be less
  @@ -285,7 +315,7 @@
                   isEqual = keys1.length == keys2.length;
                   for ( int i=0; i<keys1.length && isEqual; i++) 
                   {
  -                    isEqual &= keys1[i].equals(keys2[i]);
  +                    isEqual &= ObjectUtils.equals(keys1[i], keys2[i]);
                   }
               }        
               else if ( keyObj instanceof SimpleKey[] 
  @@ -296,7 +326,7 @@
                   isEqual = keys1.length == keys2.length;
                   for ( int i=0; i<keys1.length && isEqual; i++) 
                   {
  -                    isEqual &= keys1[i].equals(keys2[i]);
  +                    isEqual &= ObjectUtils.equals(keys1[i], keys2[i]);
                   }
               }
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org