package polyVisitor; import arrayPoly.*; /** * Adds host polynomial to a constant. Returns the resulting sum polynomial.
 * Copyright 2000, by Dung X. Nguyen, All rights reserved.
 
* @author Dung X. Nguyen * @since 02/16/2000 */ public class AddConst implements IVisitor { public final static AddConst Singleton = new AddConst (); private AddConst() { } /** * @param poly a Constant polynomial * @param input a Double * @return a APolynomial representing the sum of poly and input. */ public Object forConst (APolynomial poly, Object input) { return PolyFactory.MakeConstPoly (poly.getLeadCoef() + ((Double)input).doubleValue ()); } /** * @param poly a non-constant APolynomial * @param input a Double * @return a APolynomial representing the sum of poly and input. */ public Object forNonConst(APolynomial poly, Object input) { APolynomial lowerSum = (APolynomial)poly.getLowerPoly().execute (this, input); return PolyFactory.MakePoly (poly.getLeadCoef(), poly.getDegree(), lowerSum); } }