comparison src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java @ 28:8901059f8144

organized imports use the new "Namespaces" class when creating String RESOURCE_URI added throws DimensionException where necessary added private NDimensionalObject vector, together with getter and setter
author stevenh
date Tue, 08 Jan 2013 18:46:47 +0000
parents 842ce6ca6e29
children 4b74b959b576
comparison
equal deleted inserted replaced
27:c4d7e4a8ba59 28:8901059f8144
1 package org.qmul.eecs.c4dm.sia.model; 1 package org.qmul.eecs.c4dm.sia.model;
2 2
3 import org.qmul.eecs.c4dm.sia.SiaMain; 3 import java.util.Vector;
4
5 import org.qmul.eecs.c4dm.sia.exceptions.DimensionException;
6 import org.qmul.eecs.c4dm.sia.rdf.Namespaces;
4 7
5 import com.hp.hpl.jena.rdf.model.Resource; 8 import com.hp.hpl.jena.rdf.model.Resource;
6 9
7 /** 10 /**
8 * @author stevenhargreaves 11 * @author stevenhargreaves
10 */ 13 */
11 public class VectorTableElement extends NDimensionalObject { 14 public class VectorTableElement extends NDimensionalObject {
12 15
13 private Datapoint fromDatapoint; 16 private Datapoint fromDatapoint;
14 private Datapoint toDatapoint; 17 private Datapoint toDatapoint;
18 private NDimensionalObject vector;
15 private Resource resource; 19 private Resource resource;
16 20
17 public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "VectorTableElement"; 21 public static final String RESOURCE_URI = Namespaces.SIA_NS_URI + "VectorTableElement";
18 22
19 /** 23 /**
20 * @return 24 * @return
21 */ 25 */
22 public Resource getResource() { 26 public Resource getResource() {
37 return fromDatapoint; 41 return fromDatapoint;
38 } 42 }
39 43
40 /** 44 /**
41 * @param fromDatapoint 45 * @param fromDatapoint
46 * @throws DimensionException
42 */ 47 */
43 public void setFromDatapoint(Datapoint fromDatapoint) { 48 public void setFromDatapoint(Datapoint fromDatapoint) throws DimensionException {
44 this.fromDatapoint = fromDatapoint; 49 this.fromDatapoint = fromDatapoint;
50 setVector();
45 } 51 }
46 52
47 /** 53 /**
48 * @return 54 * @return
49 */ 55 */
51 return toDatapoint; 57 return toDatapoint;
52 } 58 }
53 59
54 /** 60 /**
55 * @param toDatapoint 61 * @param toDatapoint
62 * @throws DimensionException
56 */ 63 */
57 public void setToDatapoint(Datapoint toDatapoint) { 64 public void setToDatapoint(Datapoint toDatapoint) throws DimensionException {
58 this.toDatapoint = toDatapoint; 65 this.toDatapoint = toDatapoint;
66 setVector();
67 }
68
69 /**
70 * @throws DimensionException
71 */
72 private void setVector() throws DimensionException {
73 NDimensionalObject vector = new NDimensionalObject();
74 Vector<DimensionValue> dimVals = new Vector<DimensionValue>();
75
76 if (this.getFromDatapoint() != null && this.getToDatapoint() != null)
77 {
78 int fromDimValsSize = this.getFromDatapoint().getDimensionValues().size();
79 int toDimValsSize = this.getToDatapoint().getDimensionValues().size();
80
81 if (fromDimValsSize != toDimValsSize)
82 throw new DimensionException("'from' and 'to' Datapoints have an unequal number of dimensions");
83
84 DimensionValue dimVal;
85
86 for (int dim = 1; dim <= fromDimValsSize; dim++)
87 {
88 dimVal = new DimensionValue();
89 double fromDimVal = this.getFromDatapoint().getDimensionValue(dim);
90 double toDimVal = this.getToDatapoint().getDimensionValue(dim);
91 dimVal.setDimension(dim);
92 dimVal.setValue(toDimVal - fromDimVal);
93 dimVals.add(dimVal);
94 }
95 vector.setDimensionValues(dimVals);
96 this.vector = vector;
97 }
98 }
99
100 public NDimensionalObject getVector() {
101
102 return this.vector;
59 } 103 }
60 104
61 /* (non-Javadoc) 105 /* (non-Javadoc)
62 * @see java.lang.Comparable#compareTo(java.lang.Object) 106 * @see java.lang.Comparable#compareTo(java.lang.Object)
63 */ 107 */