ClusterCountReader { public static int getNumberOfClusters(Path clusterOutputPath, Configuration conf) throws IOException { FileSystem fileSystem = clusterOutputPath.getFileSystem(conf); FileStatus[] clusterFiles = fileSystem.listStatus(clusterOutputPath, PathFilters.finalPartFilter()); int numberOfClusters = 0; Iterator<?> it = new SequenceFileDirValueIterator<Writable>(clusterFiles[0].getPath(), PathType.LIST, PathFilters.partFilter(), null, true, conf); while (it.hasNext()) { it.next(); numberOfClusters++; } return numberOfClusters; } private  ClusterCountReader(); static int getNumberOfClusters(Path clusterOutputPath, Configuration conf); static Map<Integer, Integer> getClusterIDs(Path clusterOutputPath, Configuration conf, boolean keyIsClusterId);  }
@Test public void testGetNumberOfClusters() throws Exception { List<VectorWritable> points = getPointsWritable(REFERENCE); Path pointsPath = getTestTempDirPath("points"); Configuration conf = getConfiguration(); ClusteringTestUtils.writePointsToFile(points, new Path(pointsPath, "file1"), fs, conf); ClusteringTestUtils.writePointsToFile(points, new Path(pointsPath, "file2"), fs, conf); outputPathForCanopy = getTestTempDirPath("canopy"); outputPathForKMeans = getTestTempDirPath("kmeans"); topLevelClustering(pointsPath, conf); int numberOfClusters = ClusterCountReader.getNumberOfClusters(outputPathForKMeans, conf); Assert.assertEquals(2, numberOfClusters); verifyThatNumberOfClustersIsCorrect(conf, new Path(outputPathForKMeans, new Path("clusteredPoints"))); }