01: /*
02: * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
03: * Copyright (C) 2006 - JScience (http://jscience.org/)
04: * All rights reserved.
05: *
06: * Permission to use, copy, modify, and distribute this software is
07: * freely granted, provided that this notice is preserved.
08: */
09: package org.jscience.mathematics.function;
10:
11: import javolution.context.ObjectFactory;
12:
13: import org.jscience.mathematics.structure.Ring;
14:
15: /**
16: * <p> This class represents a constant function (polynomial of degree 0).<p>
17: *
18: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
19: * @version 3.1, April 1, 2006
20: */
21: public final class Constant<R extends Ring<R>> extends Polynomial<R> {
22:
23: /**
24: * Default constructor.
25: */
26: private Constant() {
27: }
28:
29: /**
30: * Returns a constant function of specified value.
31: *
32: * @param value the value returned by this function.
33: * @return the corresponding constant function.
34: */
35: @SuppressWarnings("unchecked")
36: public static <R extends Ring<R>> Constant<R> valueOf(R value) {
37: Constant<R> cst = FACTORY.object();
38: cst._termToCoef.put(Term.ONE, value);
39: return cst;
40: }
41:
42: @SuppressWarnings("unchecked")
43: private static final ObjectFactory<Constant> FACTORY = new ObjectFactory<Constant>() {
44: protected Constant create() {
45: return new Constant();
46: }
47:
48: protected void cleanup(Constant cst) {
49: cst._termToCoef.reset();
50: }
51: };
52:
53: /**
54: * Returns the constant value for this function.
55: *
56: * @return <code>getCoefficient(Term.CONSTANT)</code>
57: */
58: public R getValue() {
59: return getCoefficient(Term.ONE);
60: }
61:
62: private static final long serialVersionUID = 1L;
63: }
|