KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > vectorJep > values > Scaler


1 /* @author rich
2  * Created on 04-Nov-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.vectorJep.values;
9
10 import org.lsmp.djep.vectorJep.*;
11
12 /**
13  * Degenerate i.e. rank 0 Tensor. Just has a single element.
14  * @author Rich Morris
15  * Created on 04-Nov-2003
16  * @version 1.3.0.2 now extends number
17  */

18 public class Scaler extends Number JavaDoc implements MatrixValueI {
19
20     Object JavaDoc value = new Double JavaDoc(0.0);
21     public Dimensions getDim() {return Dimensions.ONE; }
22     public int getNumEles() { return 1; }
23     public void setEle(int i, Object JavaDoc value) {if(value!=null) this.value = value;}
24     public Object JavaDoc getEle(int i) {return value; }
25 // public void setValue(Object value) { this.value = value;}
26
// public Object getValue() {return value; }
27
public String JavaDoc toString() { return value.toString(); }
28     /** sets the elements to those of the arguments. */
29     public void setEles(MatrixValueI val)
30     {
31         if(!(val.getDim().equals(Dimensions.ONE))) return;
32         value = val.getEle(0);
33     }
34     
35     /** value of constant coeff. */
36     public int intValue() {return ((Number JavaDoc) value).intValue(); }
37     /** value of constant coeff. */
38     public long longValue() {return ((Number JavaDoc) value).longValue(); }
39     /** value of constant coeff. */
40     public float floatValue() { return ((Number JavaDoc) value).floatValue(); }
41     /** value of constant coeff. */
42     public double doubleValue() {return ((Number JavaDoc) value).doubleValue(); }
43
44     public boolean equals(Object JavaDoc obj) {
45         if(!(obj instanceof Scaler)) return false;
46         Scaler s = (Scaler) obj;
47         if(!s.getDim().equals(getDim())) return false;
48         if(!value.equals(s.value)) return false;
49         return true;
50     }
51     
52     /**
53      * Always override hashCode when you override equals.
54      * Efective Java, Joshua Bloch, Sun Press
55      */

56     public int hashCode() {
57         int result = 17;
58             result = 37*result+ value.hashCode();
59         return result;
60     }
61
62 }
63
Popular Tags