Well the reason I added VectorPair is that I was going through the
MAHOUT-20 codes and sought to remove every single for loop there I'm not sure what you mean by "static inner classes of the test" but yes, the thought of putting VectorPairElement and VectorPairIterator as inner classes to VectorPair did occur to me. At the time, I guess I just wanted to keep each file short and simple. And the thing is I really didn't see anything gained by making VectorPairElement inner. As for VectorPairIterator, we can simply make it a package private rather than inner, as users are supposed to access it as Iterator<VectorPairElement> anyway. That's pretty much all the factoring I could come up with.
And yes, in fact more generic solutions are possible. But the most elegant ones I could come up with entailed modifying the Vector interface by making it use Java generics, like java.lang do. Presently the Vectors are tied down to Double values (might even be useful if we need complex-valued vectors later). That would allow the users to use a more or less uniform interface, and might even allow the "Element" class to be factored out. Problems with such a change might be:
The Iterator logics used in each (VectorPair, SparseVector, DenseVector) are quite distinct and hard to specify from a generic class given that Java do not support the kind of template specialization features of C++. But still, I guess doable by implementing a generic interface by concrete classes. Would enable the users to write codes like:
VectorIterator<Double> it = sparsevec.iterator();
VectorIterator<Complex> jt = cmplxdensevec.iterator();
VectorIterator<Pair<Double,Complex>> kt = Vector.pairiterator(sparsevec,cmplxdensevec);
Could design it this way if you want me to. But is there any specific redundancy in these Iterator classes that you have in mind? And do bear in mind this would probably mean changing the Vector interface to a generic one - meaning other classes that depend on it will have to be tweaked accordingly (probably just by simply replacing Vector by Vector<Double>). This is why I opted in for the simpler designs here.