class MathHelper {

    public static ListSimilarity computeListSimilarity(List<String> list1, List<String> list2) {

        // get maximum possible distance
        int summedMaxDistance = 0;
        int summedMaxSquaredDistance = 0;
        int distance = list1.size() - 1;
        for (int i = list1.size(); i > 0; i -= 2) {
            summedMaxDistance += 2 * distance;
            summedMaxSquaredDistance += 2 * Math.pow(distance, 2);
            distance -= 2;
        }

        // get real distance between lists
        int summedRealDistance = 0;
        int summedRealSquaredDistance = 0;
        int position1 = 0;
        Stats stats = new SlimStats();

        for (String entry1 : list1) {

            int position2 = 0;
            for (String entry2 : list2) {
                if (entry1.equals(entry2)) {
                    summedRealDistance += Math.abs(position1 - position2);
                    summedRealSquaredDistance += Math.pow(position1 - position2, 2);

                    double[] values = new double[2];
                    values[0] = position1;
                    values[1] = position2;
                    stats.add(Math.abs(position1 - position2));
                    break;
                }
                position2++;
            }

            position1++;
        }

        double similarity = 1 - (double) summedRealDistance / (double) summedMaxDistance;
        double squaredShiftSimilarity = 1 - (double) summedRealSquaredDistance / (double) summedMaxSquaredDistance;
        double rootMeanSquareError = stats.getRmse();

        return new ListSimilarity(similarity, squaredShiftSimilarity, rootMeanSquareError);
    }

    private  MathHelper();

}