Mercurial > hg > semantic-sia
view 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 |
line wrap: on
line source
package org.qmul.eecs.c4dm.sia.model; 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; /** * @author stevenhargreaves * */ public class VectorTableElement extends NDimensionalObject { private Datapoint fromDatapoint; private Datapoint toDatapoint; private NDimensionalObject vector; private Resource resource; public static final String RESOURCE_URI = Namespaces.SIA_NS_URI + "VectorTableElement"; /** * @return */ public Resource getResource() { return resource; } /** * @param resource */ public void setResource(Resource resource) { this.resource = resource; } /** * @return */ public Datapoint getFromDatapoint() { return fromDatapoint; } /** * @param fromDatapoint * @throws DimensionException */ public void setFromDatapoint(Datapoint fromDatapoint) throws DimensionException { this.fromDatapoint = fromDatapoint; setVector(); } /** * @return */ public Datapoint getToDatapoint() { return toDatapoint; } /** * @param toDatapoint * @throws DimensionException */ 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) * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(Object o2) { int compareResult = super.compareTo(o2); if (compareResult == 0) { VectorTableElement vte2 = (VectorTableElement)o2; if (this.getFromDatapoint().getOrderedIndex() < vte2.getFromDatapoint().getOrderedIndex()) { return -1; } else if (this.getFromDatapoint().getOrderedIndex() > vte2.getFromDatapoint().getOrderedIndex()) { return 1; } else { return 0; } } return compareResult; } public int compareToIgnoreDatapoints(Object o2) { int compareResult = super.compareTo(o2); return compareResult; } }