I looked over the code and the default comparator uses the default "compare" method of the object. All ints and longs are wrapped in a "Long" before being added to the Frequency table. I suspect that the Long objects being added cannot be compared to the Character objects without throwing an error?

The other thought is that the NaturalComparator is not added to default TreeMap when its created.

Frequency.NaturalComparator
http://jakarta.apache.org/commons/math/xref/org/apache/commons/math/stat/Frequency.html#401

 public int compare(Object o1, Object o2) {
            return ((Comparable)o1).compareTo(o2);
         }



Shing Hing Man wrote:

Deal all,
It would be appreciated if someone could clarify
the following on org.apache.commons.math.stat.univariate.Frequency.


My version of org.apache.commons.math is dated 10
August, 2004.
The following snippet piece of code is from


http://jakarta.apache.org/commons/math/userguide/stat.html#1.3%20Frequency%20distributions


Frequency f = new Frequency();
f.addValue(1);
f.addValue(new Integer(1)); // (*)
f.addValue(new Long(1));
f.addValue(2);
f.addValue(new Integer(-1));
System.out.println(f.getCount(1)); //
displays 3
System.out.println(f.getCumPct(0)); //
displays 0.2
System.out.println(f.getPct(new Integer(1))); // displays 0.6
System.out.println(f.getCumPct(-2)); //
displays 0
System.out.println(f.getCumPct(10)); //
displays 1



When I run it, I got the following exception at line (*).


Exception in thread "main" java.lang.IllegalArgumentException: Value not comparable to existing values.

It looks as though the default comparator can not
compare primitive type int with
Integer object. I thought this piece of code is
supposed to demonstrate the otherwise.

Thanks in advice for your help !

Shing


===== Home page : http://uk.geocities.com/matmsh/index.html


___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com

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





--
Mark R. Diggory
Software Developer
Harvard MIT Data Center
http://www.hmdc.harvard.edu


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



Reply via email to