changeset 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 c4d7e4a8ba59
children b24eebf34dc9
files src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java
diffstat 1 files changed, 48 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java	Tue Jan 08 18:44:01 2013 +0000
+++ b/src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java	Tue Jan 08 18:46:47 2013 +0000
@@ -1,6 +1,9 @@
 package org.qmul.eecs.c4dm.sia.model;
 
-import org.qmul.eecs.c4dm.sia.SiaMain;
+import java.util.Vector;
+
+import org.qmul.eecs.c4dm.sia.exceptions.DimensionException;
+import org.qmul.eecs.c4dm.sia.rdf.Namespaces;
 
 import com.hp.hpl.jena.rdf.model.Resource;
 
@@ -12,9 +15,10 @@
 	
 	private Datapoint fromDatapoint;
 	private Datapoint toDatapoint;
+	private NDimensionalObject vector;
 	private Resource resource;
 	
-	public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "VectorTableElement";
+	public static final String RESOURCE_URI = Namespaces.SIA_NS_URI + "VectorTableElement";
 
 	/**
 	 * @return
@@ -39,9 +43,11 @@
 
 	/**
 	 * @param fromDatapoint
+	 * @throws DimensionException 
 	 */
-	public void setFromDatapoint(Datapoint fromDatapoint) {
+	public void setFromDatapoint(Datapoint fromDatapoint) throws DimensionException {
 		this.fromDatapoint = fromDatapoint;
+		setVector();
 	}
 
 	/**
@@ -53,9 +59,47 @@
 
 	/**
 	 * @param toDatapoint
+	 * @throws DimensionException 
 	 */
-	public void setToDatapoint(Datapoint toDatapoint) {
+	public void setToDatapoint(Datapoint toDatapoint) throws DimensionException {
 		this.toDatapoint = toDatapoint;
+		setVector();
+	}
+
+	/**
+	 * @throws DimensionException
+	 */
+	private void setVector() throws DimensionException {
+		NDimensionalObject vector = new NDimensionalObject();
+		Vector<DimensionValue> dimVals = new Vector<DimensionValue>();
+		
+		if (this.getFromDatapoint() != null && this.getToDatapoint() != null)
+		{
+			int fromDimValsSize = this.getFromDatapoint().getDimensionValues().size();
+			int toDimValsSize = this.getToDatapoint().getDimensionValues().size();
+
+			if (fromDimValsSize != toDimValsSize)
+				throw new DimensionException("'from' and 'to' Datapoints have an unequal number of dimensions");
+			
+			DimensionValue dimVal;
+			
+			for (int dim = 1; dim <= fromDimValsSize; dim++)
+			{
+				dimVal = new DimensionValue();
+				double fromDimVal = this.getFromDatapoint().getDimensionValue(dim);
+				double toDimVal = this.getToDatapoint().getDimensionValue(dim);
+				dimVal.setDimension(dim);
+				dimVal.setValue(toDimVal - fromDimVal);
+				dimVals.add(dimVal);
+			}
+			vector.setDimensionValues(dimVals);
+			this.vector = vector;
+		}
+	}
+
+	public NDimensionalObject getVector() {
+
+		return this.vector;
 	}
 
 	/* (non-Javadoc)