package data;

import java.util.ArrayList;
import java.util.Objects;

/*
Created for when words are sorted by multiple keys, i.e. not just lemmas but lemmas and msd simultaneously.
*/
public final class MultipleHMKeys5 implements MultipleHMKeys {
    private final String k1, k2, k3, k4, k5;

    public MultipleHMKeys5(String k1, String k2, String k3, String k4, String k5) {
        this.k1 = k1;
        this.k2 = k2;
        this.k3 = k3;
        this.k4 = k4;
        this.k5 = k5;
    }

    public String getK1() {
        return k1;
    }

    public String getK2() {
        return k2;
    }

    public String getK3() {
        return k3;
    }

    public String getK4() {
        return k4;
    }

    public String getK5() {
        return k5;
    }

    public ArrayList<MultipleHMKeys> getSplittedMultipleHMKeys(){
        ArrayList<MultipleHMKeys> r = new ArrayList<>();
        String[] splitedK1 = k1.split("\\s+");
        String[] splitedK2 = k2.split("\\s+");
        String[] splitedK3 = k3.split("\\s+");
        String[] splitedK4 = k4.split("\\s+");
        String[] splitedK5 = k5.split("\\s+");
        for(int i = 0; i < splitedK1.length; i ++){
            // in GOS words and normalized words may not both have specific word due to anon
            if(!(i < splitedK2.length && i < splitedK3.length && i < splitedK4.length && i < splitedK5.length)){
                continue;
            }
            MultipleHMKeys search = new MultipleHMKeys5(splitedK1[i], splitedK2[i], splitedK3[i], splitedK4[i], splitedK5[i]);
            r.add(search);
        }
        return r;
    }



    @Override
    public int hashCode() {
        return Objects.hash(k1, k2, k3, k4, k5);
    }

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof MultipleHMKeys5) && ((MultipleHMKeys5) obj).k1.equals(k1)
                && ((MultipleHMKeys5) obj).k2.equals(k2)
                && ((MultipleHMKeys5) obj).k3.equals(k3)
                && ((MultipleHMKeys5) obj).k4.equals(k4)
                && ((MultipleHMKeys5) obj).k5.equals(k5);
    }

    public MultipleHMKeys[] splitNgramTo1grams(){
        String[] k1 = getK1().split(" ");
        String[] k2 = getK2().split(" ");
        String[] k3 = getK3().split(" ");
        String[] k4 = getK4().split(" ");
        String[] k5 = getK5().split(" ");
        MultipleHMKeys[] res = new MultipleHMKeys[k1.length];
        for(int i = 0; i < k1.length; i++){
            res[i] = new MultipleHMKeys5(k1[i], k2[i], k3[i], k4[i], k5[i]);
        }
        return res;
    }
}
