On 11-01-03 10:44 AM, Tom Anderson wrote:
On Fri, 31 Dec 2010, Tom Anderson wrote:
On Fri, 31 Dec 2010, Ken Wesson wrote:
(In reality there's not much reason to have multiple implementations
of countNonNulls; *obviously* it'll be "int i = 0; for (Object o : x)
if (o ! = null) i++; return i;". :) But it serves as a quick example.)
Ahem:
return x.size() - Collections.frequency(x, null);
LOL j/k.
I do agree with Ken and Arved that 'frequency' is poorly named - it
really should be 'count'. It's not a disaster that it's called what it's
called, though.
No, it's not a disaster. Encountering its use in code, I'd look at the
context and the arguments and figure out what it does, probably checking
the API docs real quick to confirm that the writer meant "count".
However - and not with the Collections class specifically - bad naming
of this type might cause me to overlook a method if I were scanning
names in the top part of a class Javadoc. "frequency" in Collections I'd
probably catch (assuming that I was completely unfamiliar with that
class) as being really a "count" method. But I suspect I probably _have_
missed other API methods in the past simply because the authors couldn't
be arsed to give them a good name.
Arne points out that statisticians do use the term frequency for counts,
both absolute and relative. Point conceded. But how many developers are
familiar with statistics?
Some but definitely a minority.
an audience as possible.
of the naming.