Thanks for the feedback.  The behavior described below is as designed, modulo the 
problem with getCumPct, getCumFreq, which is a bug.  Of course, given the feedback 
(and pesky bugs that keep showing up ;-)  it could be that the simplifying intention 
in the design is doing more harm than good.  The idea of converting all integral 
values to Longs was so that addValue(1), addValue(new Long(1)), addValue(new 
Integer(1)) would all have the same effect, enabling you to mix integral types when 
adding values and querying counts and percentages.  If we remove this, the 
responsibility goes back to the user to add objects of only one type (and to create 
the instances in the case of primitive values).
 
I can fix the cumXxx bug (for 1.0 final) if others agree that the interface should 
stay as currently designed.  In this case, I will also add a comment to the 
valuesIterator() javadoc indicating that if the values that have been added are 
integral, the Iterator returned contains Longs.  The class javadoc mentions the 
conversion now.
 
Does anyone feel strongly that the interface needs to change (i.e., eliminate the 
integral conversions)?  This was discussed once before, and I thought the conclusion 
was that it should stay as is.
 
Phil

        -----Original Message----- 
        From: Jon Langlois [mailto:[EMAIL PROTECTED] 
        Sent: Tue 9/14/2004 1:12 PM 
        To: [EMAIL PROTECTED] 
        Cc: 
        Subject: [math] Frequency handling of Integer values
        
        

        In using org.apache.commons.math.stat.Frequency, I noticed that it does
        a strange thing when given Integer values.  The following test method
        illustrates the problem:
        
           public void testInteger() {
              Frequency freq = new Frequency();
            
              for (int i=0; i<10; i++) {
                 freq.addValue(new Integer(i));
              }
            
              assertTrue(freq.getCumFreq(new Integer(5)) == 5);
           }
        
        For some reason, the implementation of Frequency.addValue(Integer)
        converts the value into a Long before storing it in the internal
        TreeMap.  Subsequent calls to getCount() and getPct() work okay, but
        valuesIterator() returns an Iterator of Longs and
        getCumPct()/getCumFreq() return 0 (because the internal Comparator is
        throwing ClassCastExceptions).
        
        
        If there isn't a reason to convert everything to Longs, the following
        patch will fix the problem:
        
        --- Frequency.java.orig 2004-09-14 12:46:06.945880000 -0400
        +++ Frequency.java      2004-09-14 12:49:02.878859200 -0400
        @@ -121,7 +121,7 @@
              * @param v the value to add.
              */
             public void addValue(Integer v) {
        -        addValue(new Long(v.longValue()));
        +        addValue((Object) v);
             }
        
             /**
        
        
        - Jon Langlois
        
        
        
        --
        This electronic transmission is strictly confidential to NetIDEAS, Inc. and 
intended solely for the addressee. It may contain information, which is covered by 
legal, professional, or other privilege. If you are not the intended addressee, or 
someone authorized by the intended addressee to receive transmissions on the behalf of 
the addressee, you must not retain, disclose in any form, copy or take any action in 
reliance on this transmission. If you have received this transmission in error, please 
notify us as soon as possible and destroy this message.
        
        
        
        ---------------------------------------------------------------------
        To unsubscribe, e-mail: [EMAIL PROTECTED]
        For additional commands, e-mail: [EMAIL PROTECTED]
        
        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to