Tanimoto { public static double method2(ICountFingerprint fp1, ICountFingerprint fp2) { long maxSum = 0, minSum = 0; int i = 0, j = 0; while (i < fp1.numOfPopulatedbins() || j < fp2.numOfPopulatedbins()) { Integer hash1 = i < fp1.numOfPopulatedbins() ? fp1.getHash(i) : null; Integer hash2 = j < fp2.numOfPopulatedbins() ? fp2.getHash(j) : null; Integer count1 = i < fp1.numOfPopulatedbins() ? fp1.getCount(i) : null; Integer count2 = j < fp2.numOfPopulatedbins() ? fp2.getCount(j) : null; if (count2 == null || (hash1 != null && hash1 < hash2)) { maxSum += count1; i++; continue; } if (count1 == null || (hash2 != null && hash1 > hash2)) { maxSum += count2; j++; continue; } if (hash1.equals(hash2)) { maxSum += Math.max(count1, count2); minSum += Math.min(count1, count2); i++; j++; } } return ((double) minSum) / maxSum; } private  Tanimoto(); static float calculate(BitSet bitset1, BitSet bitset2); static double calculate(IBitFingerprint fingerprint1, IBitFingerprint fingerprint2); static float calculate(double[] features1, double[] features2); static float calculate(Map<String, Integer> features1, Map<String, Integer> features2); static double calculate(ICountFingerprint fp1, ICountFingerprint fp2); static double method1(ICountFingerprint fp1, ICountFingerprint fp2); static double method2(ICountFingerprint fp1, ICountFingerprint fp2);  }
@Test public void method2() throws CDKException { ICountFingerprint fp1 = new IntArrayCountFingerprint(new HashMap<String, Integer>() { { put("A", 3); } }); ICountFingerprint fp2 = new IntArrayCountFingerprint(new HashMap<String, Integer>() { { put("A", 4); } }); Assert.assertEquals(0.75, Tanimoto.method2(fp1, fp2), 0.001); }