One of the "features" of the Oracle database is that, in addition to the "wonderful" PL/SQL language for building stored procedures, you can also write stored procedures in Java.
Now, the skills of "being a good database programmer" and "being a good Java programmer" are not necessarily overlapping, especially when you're deep in the world of Oracle's approach to programming. Which is where this submission, from Tomas comes from.
private static final short m_maxCharWidth[][] = {
{
1, 1
}, {
2, 1
}, {
3, 1
}, {
4, 1
}, {
5, 1
}, {
6, 1
}, {
7, 1
}, {
8, 1
}, {
9, 1
// ... some time later ...
9998, 3
}, {
9999, 3
}
};
The first thing to note is that this 2D array uses its first dimension to store index+1
. Maybe someone really liked Matlab and wanted 1-based indexes. It's hard to say for sure.
It's also hard to say what this is actually for. My first thought was that it was mapping numbers to their number of digits, for display purposes. Given the name, it seems likely- but that would mean they're using 3 characters to display 4 digit numbers, which would be wrong. Maybe it's mapping Unicode code points to the number of bytes they require to be represented? That doesn't jive either. Or perhaps it's (short)log(n)
- a truncated log, but that would be wrong for all the single digit numbers. Our submitter snipped the 2 digit range, so I'm not sure what was inside of there, and that might answer the question.
But then again, why am I even trying to answer this question? This code just shouldn't exist.