/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package expressiontree.operators.unary;

import apfloatextraclasses.ApfloatMatrixException;
import apfloatextraclasses.ApfloatMatrixMath;
import expressiontree.ExpressionTreeElement;
import expressiontree.operands.Matrix;
import expressiontree.operators.UnaryOperator;
import expressiontree.operands.NumberType;
import expressiontree.operators.IncompatibleNumberFormatException;

/**
 * A transzponálás operátorok osztálya.
 * @author Esta
 */
public class Transponate extends UnaryOperator {

    @Override
    public ExpressionTreeElement getValue() throws IncompatibleNumberFormatException {
        ExpressionTreeElement op1 = this.operands.get(0).getValue();
        if (op1 instanceof NumberType) {
            //Ha csak számot talál, akkor semmit sem tesz.
            return this.operands.get(0);
        } else if (op1 instanceof Matrix) {
            try {
                //Ha vektor, vagy mátrix, akkor transzponálja.
                Matrix m = (Matrix) op1;
                Matrix retValue = new Matrix(m.getCols(), m.getRows());
                retValue.setValues(ApfloatMatrixMath.transponate(m.getMatrixValues()));
                return retValue;
            } catch (ApfloatMatrixException ex) {
                throw new IncompatibleNumberFormatException(ex.getMessage());
            }
        } else { //Ez elvileg SOHA nem fordulhat elő.
            throw new IncompatibleNumberFormatException("ERROR_TRANSP");
        }
    }

    @Override
    public String toText(boolean b) {
        if (b) {
            return "tr()";
        } else {
            return "tr ";
        }
    }

    @Override
    public String getLocalizedName() {
        return java.util.ResourceBundle.getBundle("languages/operators").getString("TRANSPONATE");
    }
}
