comparison src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java @ 0:08675ab08e7f

New
author Steven Hargreaves <steve.harg@gmail.com>
date Sat, 29 Dec 2012 17:41:06 +0000
parents
children 842ce6ca6e29
comparison
equal deleted inserted replaced
-1:000000000000 0:08675ab08e7f
1 package org.qmul.eecs.c4dm.sia.model;
2
3 import java.util.Iterator;
4 import java.util.Vector;
5
6 import org.qmul.eecs.c4dm.sia.SiaMain;
7 import org.qmul.eecs.c4dm.sia.exceptions.DimensionException;
8
9 import com.hp.hpl.jena.rdf.model.Resource;
10
11 /**
12 * @author stevenhargreaves
13 *
14 */
15 public class VectorTableElement extends NDimensionalObject implements Comparable {
16
17 private Datapoint fromDatapoint;
18 private Datapoint toDatapoint;
19 private Resource resource;
20
21 public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "VectorTableElement";
22
23 /**
24 * @return
25 */
26 public Resource getResource() {
27 return resource;
28 }
29
30 /**
31 * @param resource
32 */
33 public void setResource(Resource resource) {
34 this.resource = resource;
35 }
36
37 /**
38 * @return
39 */
40 public Datapoint getFromDatapoint() {
41 return fromDatapoint;
42 }
43
44 /**
45 * @param fromDatapoint
46 */
47 public void setFromDatapoint(Datapoint fromDatapoint) {
48 this.fromDatapoint = fromDatapoint;
49 }
50
51 /**
52 * @return
53 */
54 public Datapoint getToDatapoint() {
55 return toDatapoint;
56 }
57
58 /**
59 * @param toDatapoint
60 */
61 public void setToDatapoint(Datapoint toDatapoint) {
62 this.toDatapoint = toDatapoint;
63 }
64
65 /* (non-Javadoc)
66 * @see java.lang.Comparable#compareTo(java.lang.Object)
67 */
68 @Override
69 public int compareTo(Object o2) {
70 VectorTableElement vte2 = (VectorTableElement)o2;
71
72 Vector<DimensionValue> vte2DimVals = vte2.getDimensionValues();
73
74 int vte2DimSize = vte2DimVals.size();
75
76 if (vte2DimSize != this.getDimensionValues().size())
77 throw new ClassCastException("VectorTableElements have an unequal number of dimensions");
78
79 Iterator<DimensionValue> vte1DimValsIter = this.getDimensionValues().iterator();
80 Iterator<DimensionValue> vte2DimValsIter = vte2DimVals.iterator();
81
82 DimensionValue vte1DimVal;
83 DimensionValue vte2DimVal;
84
85 for (int dimension = 1; dimension <= vte2DimSize; dimension++)
86 {
87 double dimension1 = 0;
88 try {
89 dimension1 = this.getDimensionValue(dimension);
90 } catch (DimensionException e) {
91 System.out.println(e.getMessage());
92 e.printStackTrace();
93 System.exit(-1);
94 }
95 double dimension2 = 0;
96 try {
97 dimension2 = vte2.getDimensionValue(dimension);
98 } catch (DimensionException e) {
99 System.out.println(e.getMessage());
100 e.printStackTrace();
101 System.exit(-1);
102 }
103
104 if (dimension1 < dimension2)
105 {
106 return -1;
107 }
108 else if (dimension1 > dimension2)
109 {
110 return 1;
111 }
112 }
113
114 if (this.getFromDatapoint().getOrderedIndex() < vte2.getFromDatapoint().getOrderedIndex())
115 {
116 return -1;
117 }
118 else if (this.getFromDatapoint().getOrderedIndex() > vte2.getFromDatapoint().getOrderedIndex())
119 {
120 return 1;
121 }
122 return 0;
123 }
124
125 }