/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/FD.java
package com.calebfontenot.mp5_calebfontenot;


/**
 *
 * @author ASDV2
 */
public class FD
{

    private String lhs;

    private String rhs;

    /**
     *
     * @param lhs the LHS of the FD
     * @param rhs the RHS of the FD
     * @throws IllegalArgumentException if the length of the LHS or the length
     * of the RHS are less than 1 or if they are null.
     */
    public FD(String lhs, String rhs)
            throws IllegalArgumentException
    {
        if (lhs == null || rhs == null )
            throw new IllegalArgumentException( "the LHS and/or RHS cannot be null.");
        
        if (lhs.length() < 1 || rhs.length() < 1 )
            throw new IllegalArgumentException( "the LHS and/or RHS cannot be of lenght less than 1.");
        
        this.lhs = lhs;
        this.rhs = rhs;
    }

    /**
     * Get the value of rhs
     *
     * @return the value of rhs
     */
    public String getRhs()
    {
        return rhs;
    }

    /**
     * Set the value of rhs
     *
     * @param rhs new value of rhs
     */
    public void setRhs(String rhs)
    {
        this.rhs = rhs;
    }

    /**
     * Get the value of lhs
     *
     * @return the value of lhs
     */
    public String getLhs()
    {
        return lhs;
    }

    /**
     * Set the value of lhs
     *
     * @param lhs new value of lhs
     */
    public void setLhs(String lhs)
    {
        this.lhs = lhs;
    }

    @Override
    public String toString()
    {
        return lhs + " -> " + rhs;
    }

    /**
     * Decomposes the RHS of the FD into singletons. where the LHS is the same
     * as this FD and the RHS is 1 character of each character of the FD.
     *
     * @return array of FD he
     */
    public FD[] decomposeRightHandSide()
    {
        FD[] fdDecomosition = new FD[this.rhs.length()];

        for (int i = 0; i < this.rhs.length(); ++i)
          {
            fdDecomosition[i] = new FD(this.lhs, Character.toString(rhs.charAt(i)));
          }
        return fdDecomosition;
    }
}