On line 272 of DefaultCategoryDataset, you make the call:
int categoryIndex = Arrays.binarySearch(categories, category);
The javadocs for Arrays.binarySearch(Object[] a, Object key) state:
"The array must be sorted into ascending order according to the natural ordering of its elements (as by Sort(Object[]), above) prior to making this call. If it is not sorted, the results are undefined."
If categories is an array of Strings and category is a String, if categories is not in alphabetic order, a negative index is returned, even if category is present in categories.
A better solution would be (and the one I am using to get this to work):
int categoryIndex = findCategoryIndex(categories, category);
where findCategoryIndex is defined as:
private int findCategoryIndex(Object[] categories, Object category) {
for (int i = 0; i < categories.length; i++) {
if (categories.equals(category)) return i;
}
return -1;
}
possible bug in DefaultCategoryDataSet.getValue()
Re: possible bug in DefaultCategoryDataSet.getValue()
Though i forgot to mention it, this is referring to version 0.5.3 of JCommon.
Re: possible bug in DefaultCategoryDataSet.getValue()
Hi Jim,
Thanks for the bug report and the fix. A couple of other people have reported it also...I better fix it before anyone else notices my sloppy coding!
Regards,
DG.
Thanks for the bug report and the fix. A couple of other people have reported it also...I better fix it before anyone else notices my sloppy coding!
Regards,
DG.