Hello.
in class org.apache.commons.math3.linear.RealVector there is the embedded class Entry which is protected, but it is exposed by method public Iterator<Entry> iterator() ...
Good catch. Thanks.
My solution: 1. make class Entry public 2. make class RealVector implement Iterable<RealVector<Entry>> so one can do this: for (RealVector.Entry e : v) { if (Double.isNaN(e.getValue()) || Double.isInfinite(e.getValue())) { throw new RuntimeException("roots: inputs must not contain Inf or NaN"); } }
IMO, exposing an "Entry" is a mistake: From a user point-of-view, a "RealVector" should be a collection of "[Dd]ouble". IIUC, the "Entry" was meant to allow storage or iteration optimizations in subclasses. I think that the current "iterator()" method must be deprecated and removed; in its place, there should be a protected Iterator<Entry> entryIterator() and a new public Iterator<Double> iterator() (that would use the above method), such that "RealVector" would implement "Iterable<Double>", as is appropriate for this concept. Eventually, your use-case would become: ----- for (Double e : v) { if (e.isNaN() || e.isInfinite()) { throw new RuntimeException("inputs must not contain Inf or NaN"); } } -----
JIRA + diff???
A bug report mentioning the inconsistency is welcome. A diff is not necessary until we agree on the way to go. Thanks, Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org