Modified addValue(Object) to convert Integers to Longs, completing (hopefully ;-) fix of problem with integral type conversions reported to commons-dev by Jon Langlois.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e11c64e6b5
commit
355e29867d
|
@ -35,7 +35,7 @@ import java.util.TreeMap;
|
||||||
* The values are ordered using the default (natural order), unless a
|
* The values are ordered using the default (natural order), unless a
|
||||||
* <code>Comparator</code> is supplied in the constructor.
|
* <code>Comparator</code> is supplied in the constructor.
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.28 $ $Date: 2004/09/19 22:47:27 $
|
* @version $Revision: 1.29 $ $Date: 2004/09/21 03:02:34 $
|
||||||
*/
|
*/
|
||||||
public class Frequency implements Serializable {
|
public class Frequency implements Serializable {
|
||||||
|
|
||||||
|
@ -93,12 +93,16 @@ public class Frequency implements Serializable {
|
||||||
* @throws IllegalArgumentException if <code>v</code> is not comparable.
|
* @throws IllegalArgumentException if <code>v</code> is not comparable.
|
||||||
*/
|
*/
|
||||||
public void addValue(Object v) {
|
public void addValue(Object v) {
|
||||||
|
Object obj = v;
|
||||||
|
if (v instanceof Integer) {
|
||||||
|
obj = new Long(((Integer) v).longValue());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Long count = (Long) freqTable.get(v);
|
Long count = (Long) freqTable.get(obj);
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
freqTable.put(v, new Long(1));
|
freqTable.put(obj, new Long(1));
|
||||||
} else {
|
} else {
|
||||||
freqTable.put(v, new Long(count.longValue() + 1));
|
freqTable.put(obj, new Long(count.longValue() + 1));
|
||||||
}
|
}
|
||||||
} catch (ClassCastException ex) {
|
} catch (ClassCastException ex) {
|
||||||
//TreeMap will throw ClassCastException if v is not comparable
|
//TreeMap will throw ClassCastException if v is not comparable
|
||||||
|
|
Loading…
Reference in New Issue