# HG changeset patch # User stevenh # Date 1357670807 0 # Node ID 8901059f81443761f034d5dc0d613ecf88ea3eb4 # Parent c4d7e4a8ba59f9e776cb8d9335ca2d7a70a9ed1c 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 diff -r c4d7e4a8ba59 -r 8901059f8144 src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java --- 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 dimVals = new Vector(); + + 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)