1 8 package org.lsmp.djep.vectorJep.values; 9 10 import org.lsmp.djep.vectorJep.*; 11 12 18 19 public class MVector extends Number implements MatrixValueI 20 { 21 private Object data[] = null; 22 private Dimensions dim; 23 25 private MVector() {} 26 27 public MVector(int size) 28 { 29 data = new Object [size]; 30 dim = Dimensions.valueOf(size); 31 } 32 33 37 49 public String toString() 50 { 51 StringBuffer sb = new StringBuffer (); 52 sb.append('['); 53 for(int i = 0;i<data.length;++i) 54 { 55 if(i>0) sb.append(','); 56 sb.append(data[i]); 57 } 58 sb.append(']'); 59 return sb.toString(); 60 } 61 62 public Dimensions getDim() { return dim; } 63 public int getNumEles() { return data.length; } 64 public void setEle(int i,Object value) { data[i] = value; } 65 public Object getEle(int i) { return data[i]; } 66 67 public void setEles(MatrixValueI val) 68 { 69 if(!dim.equals(val.getDim())) return; 70 System.arraycopy(((MVector) val).data,0,data,0,getNumEles()); 71 } 72 73 74 public int intValue() {return ((Number ) data[0]).intValue(); } 75 76 public long longValue() {return ((Number ) data[0]).longValue(); } 77 78 public float floatValue() { return ((Number ) data[0]).floatValue(); } 79 80 public double doubleValue() {return ((Number ) data[0]).doubleValue(); } 81 82 public boolean equals(Object obj) { 83 if(!(obj instanceof MVector)) return false; 84 MVector vec = (MVector) obj; 85 if(!vec.getDim().equals(getDim())) return false; 86 for(int i=0;i<data.length;++i) 87 if(!data[i].equals(vec.data[i])) return false; 88 return true; 89 } 90 91 95 public int hashCode() { 96 int result = 17; 97 for(int i=0;i<data.length;++i) 98 result = 37*result+ data[i].hashCode(); 99 return result; 100 } 101 102 } 103 | Popular Tags |