Initial checkin of KMeans implementation

Basic framework for KMeans implementation and code refactoring.
This won't be correct for k-means, and neither is the javadoc. It can be removed now that this code is common.