private static double jaccardSimilarity(@NotNull Bag bag1, @NotNull Bag bag2, double similarityThreshold, boolean isOptimised){
    final int cardinality1 = bag1.getCardinality();
    final int cardinality2 = bag2.getCardinality();
    if (!isOptimised && lessThen(Math.min(cardinality1, cardinality2), Math.max(cardinality1, cardinality2) * similarityThreshold)) {
      return 0;
    }
    int intersectionSize = Bag.intersectionSize(bag1, bag2);
    return intersectionSize / (double)(cardinality1 + cardinality2 - intersectionSize);
  }
private static double jaccardSimilarity(@NotNull Bag bag1, @NotNull Bag bag2, double similarityThreshold, boolean isOptimised)