jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hc...@apache.org
Subject cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/utils/struct SortedPreferentialArray.java
Date Mon, 14 Mar 2005 11:28:11 GMT
hchar       2005/03/14 03:28:11

  Modified:    src/java/org/apache/jcs/utils/struct
                        SortedPreferentialArray.java
  Log:
  1) Fix incorrect debug messages in add() of not taking the equal case into account
  2) Fix add() so that, if the array is full,
  the behavior of adding an object equal to the smallest when preferLarge is true
  is now consistent with the
  behavior of of adding an object equal to the largest when preferLarge is false
  
  Revision  Changes    Path
  1.6       +27 -32    jakarta-turbine-jcs/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java
  
  Index: SortedPreferentialArray.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SortedPreferentialArray.java	14 Mar 2005 11:01:50 -0000	1.5
  +++ SortedPreferentialArray.java	14 Mar 2005 11:28:11 -0000	1.6
  @@ -59,7 +59,6 @@
      * if obj is bigger, or the largest if preferLarge=false and obj is smaller
      * than the largest.
      *
  -   *
      * @param obj Object
      */
     public void add(Comparable obj)
  @@ -72,44 +71,40 @@
       if (curSize < maxSize)
       {
         insert(obj);
  +      return;
       }
  -    else
  +    if (preferLarge)
       {
  -      if (preferLarge)
  +      // insert if obj is larger than the smallest
  +      Comparable sma = getSmallest();
  +      if (obj.compareTo(sma) > 0)
         {
  -        // insert if obj is larger than the smallest
  -        Comparable sma = getSmallest();
  -        if (obj.compareTo(sma) > 0)
  -        {
  -          insert(obj);
  -        }
  -        else
  -        {
  -          if (log.isDebugEnabled())
  -          {
  -            log.debug("New object is smaller than smallest");
  -          }
  -          return;
  -        }
  +        insert(obj);
  +        return;
         }
  -      else
  +      // obj is less than or equal to the smallest.
  +      if (log.isDebugEnabled())
         {
  -        Comparable lar = getLargest();
  -        // insert if obj is smaller than the largest
  -        if (obj.compareTo(lar) > 0)
  -        {
  -          if (log.isDebugEnabled())
  -          {
  -            log.debug("New object is largerer than largest");
  -          }
  -          return;
  -        }
  -        else
  -        {
  -          insert(obj);
  -        }
  +        log.debug("New object is smaller than or equal to the smallest");
         }
  +      return;
       }
  +    // Not preferLarge
  +    Comparable lar = getLargest();
  +    // insert if obj is smaller than the largest
  +    int diff = obj.compareTo(lar);
  +    if (diff > 0 
  +    ||  diff == 0)
  +    {
  +      if (log.isDebugEnabled())
  +      {
  +        log.debug("New object is larger than or equal to the largest");
  +      }
  +      return;
  +    }
  +    // obj is less than the largest.
  +    insert(obj);
  +    return;
     }
   
     /**
  
  
  

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


Mime
View raw message