ValueProcessor.java
/*
* Created on 2007/10/31
* Copyright (C) 2007 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.rpn;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.rpn.AbstractProcessor;
import org.mklab.nfc.rpn.ReversePolishNotationOperand;
import org.mklab.nfc.scalar.DoubleNumber;
import org.mklab.tool.control.system.math.DoubleConstantSystem;
/**
* 逆ポーランド記法を数値に関して評価(処理)するクラスです。
*
* @author Anan
* @version $Revision: 1.5 $, 2007/10/31
*/
public class ValueProcessor extends AbstractProcessor<DoubleNumber,DoubleMatrix> {
/**
* @see org.mklab.nfc.rpn.ReversePolishNotationProcessor#getResult(org.mklab.nfc.rpn.ReversePolishNotationOperand)
*/
public String getResult(final ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> operand) {
return evaluate(operand).toString();
}
/**
* @see org.mklab.nfc.rpn.ReversePolishNotationProcessor#multiplyOperation(org.mklab.nfc.rpn.ReversePolishNotationOperand, org.mklab.nfc.rpn.ReversePolishNotationOperand)
*/
public ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> multiplyOperation(ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> left, ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> right) {
final DoubleMatrix gain = left.getOperandValue().multiply(right.getOperandValue());
final ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> ans = left.createOperand(gain);
ans.setExpression(gain.getPrintingElementsString(gain.getColumnSize()));
return ans;
}
/**
* @see org.mklab.nfc.rpn.ReversePolishNotationProcessor#addOperation(org.mklab.nfc.rpn.ReversePolishNotationOperand, org.mklab.nfc.rpn.ReversePolishNotationOperand)
*/
public ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> addOperation(ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> left, ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> right) {
final DoubleMatrix gain = left.getOperandValue().add(right.getOperandValue());
final ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> ans = new DoubleConstantSystem(gain);
ans.setExpression(gain.getPrintingElementsString(gain.getColumnSize()));
return ans;
}
/**
* @see org.mklab.nfc.rpn.ReversePolishNotationProcessor#inverseOperation(org.mklab.nfc.rpn.ReversePolishNotationOperand)
*/
public ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> inverseOperation(ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> operand) {
final DoubleMatrix gain = operand.getOperandValue().inverse();
final ReversePolishNotationOperand<DoubleNumber,DoubleMatrix> ans = new DoubleConstantSystem(gain);
ans.setExpression(gain.getPrintingElementsString(gain.getColumnSize()));
return ans;
}
}