package com.ms.biz.test;

import java.util.ArrayList;
import java.util.List;

public class StringDifferencesTest {

    public static void main(String[] args) {
        String str1 = "dighgfghf^&)l3sedi&(.D@BCarrayInt64[10000,10000]arrayString[\"arrayString1\",\"arrayString2\"]arrayStruct[{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0},[],[]]double10.1int1610000int3210000int6410000mapStringString{\"A\":\"mapStringString1\",\"B\":\"mapStringString2\"}mapStringStruct{\"mapstruct3\":[],\"mapstruct1\":{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0},\"mapstruct2\":[]}stringteststruct{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0}dighgfghf^&)l3sedi&(.D@BC";
        String str2 = "dighgfghf^&)l3sedi&(.D@BCarrayInt64[10000,10000]arrayString[\"arrayString1\",\"arrayString2\"]arrayStruct[{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0},{},{}]double10.1int1610000int3210000int6410000mapStringString{\"A\":\"mapStringString1\",\"B\":\"mapStringString2\"}mapStringStruct{\"mapstruct3\":{},\"mapstruct1\":{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0},\"mapstruct2\":{}}stringteststruct{\"deliveryDelayDay\":0,\"freightTemplateId\":0,\"moveOnsaleType\":0,\"moveShopConfigId\":0,\"noConsignPriceType\":0,\"priceTail\":0,\"reduceType\":0,\"supply7dayReturn\":0}dighgfghf^&)l3sedi&(.D@BC";

        List<Difference> differences = findDifferences(str1, str2);
        for (Difference diff : differences) {
            System.out.println(diff);
        }
    }

    public static List<Difference> findDifferences(String str1, String str2) {
        List<Difference> differences = new ArrayList<>();

        int len = Math.min(str1.length(), str2.length());
        for (int i = 0; i < len; i++) {
            if (str1.charAt(i) != str2.charAt(i)) {
                differences.add(new Difference(i, str1.charAt(i), str2.charAt(i)));
            }
        }

        // Handle case where one string is longer than the other
        for (int i = len; i < str1.length(); i++) {
            differences.add(new Difference(i, str1.charAt(i), null));
        }
        for (int i = len; i < str2.length(); i++) {
            differences.add(new Difference(i, null, str2.charAt(i)));
        }

        return differences;
    }

    static class Difference {
        int position;
        Character charInStr1;
        Character charInStr2;

        Difference(int position, Character charInStr1, Character charInStr2) {
            this.position = position;
            this.charInStr1 = charInStr1;
            this.charInStr2 = charInStr2;
        }

        @Override
        public String toString() {
            return "Position: " + position + ", str1: " + charInStr1 + ", str2: " + charInStr2;
        }
    }
}

