KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > mathematics > functions > Constant


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2006 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.mathematics.functions;
10
11 import org.jscience.mathematics.structures.Ring;
12
13 /**
14  * <p> This class represents a constant function (polynomial of degree 0).<p>
15  *
16  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
17  * @version 3.1, April 1, 2006
18  */

19 public final class Constant<R extends Ring<R>> extends Polynomial<R> {
20
21     /**
22      * Default constructor.
23      */

24     private Constant() {
25     }
26
27     /**
28      * Returns a constant function of specified value.
29      *
30      * @param value the value returned by this function.
31      * @return the corresponding constant function.
32      */

33     @SuppressWarnings JavaDoc("unchecked")
34     public static <R extends Ring<R>> Constant<R> valueOf(R value) {
35         Constant<R> cst = FACTORY.object();
36         cst._termToCoef.put(Term.ONE, value);
37         return cst;
38     }
39
40     private static final Factory<Constant> FACTORY = new Factory<Constant>() {
41         protected Constant create() {
42             return new Constant();
43         }
44
45         protected void cleanup(Constant cst) {
46             cst._termToCoef.reset();
47         }
48     };
49
50     /**
51      * Returns the constant value for this function.
52      *
53      * @return <code>getCoefficient(Term.CONSTANT)</code>
54      */

55     public R getValue() {
56         return getCoefficient(Term.ONE);
57     }
58
59     private static final long serialVersionUID = 1L;
60 }
Popular Tags