Mercurial > hg > semantic-sia
comparison src/org/qmul/eecs/c4dm/sia/model/Datapoint.java @ 0:08675ab08e7f
New
author | Steven Hargreaves <steve.harg@gmail.com> |
---|---|
date | Sat, 29 Dec 2012 17:41:06 +0000 |
parents | |
children | 7c2d7e0946b3 |
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 public class Datapoint extends NDimensionalObject implements Comparable { | |
12 | |
13 private Resource resource; | |
14 private int orderedIndex; | |
15 | |
16 public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "Datapoint"; | |
17 | |
18 /** | |
19 * @return the resource | |
20 */ | |
21 public Resource getResource() { | |
22 return resource; | |
23 } | |
24 | |
25 /** | |
26 * @param resource the node to set | |
27 */ | |
28 public void setResource(Resource resource) { | |
29 this.resource = resource; | |
30 } | |
31 | |
32 /** | |
33 * @return the orderedIndex | |
34 */ | |
35 public int getOrderedIndex() { | |
36 return orderedIndex; | |
37 } | |
38 | |
39 /** | |
40 * @param orderedIndex the orderedIndex to set | |
41 */ | |
42 public void setOrderedIndex(int orderedIndex) { | |
43 this.orderedIndex = orderedIndex; | |
44 } | |
45 | |
46 @Override | |
47 public int compareTo(Object o2) { | |
48 Datapoint datapoint2 = (Datapoint)o2; | |
49 | |
50 Vector<DimensionValue> datapoint2DimVals = datapoint2.getDimensionValues(); | |
51 | |
52 int datapoint2DimSize = datapoint2DimVals.size(); | |
53 | |
54 if (datapoint2DimSize != this.getDimensionValues().size()) | |
55 throw new ClassCastException("Datapoints have an unequal number of dimensions"); | |
56 | |
57 Iterator<DimensionValue> datapoint1DimValsIter = this.getDimensionValues().iterator(); | |
58 Iterator<DimensionValue> datapoint2DimValsIter = datapoint2DimVals.iterator(); | |
59 | |
60 DimensionValue datapoint1DimVal; | |
61 DimensionValue datapoint2DimVal; | |
62 | |
63 for (int dimension = 1; dimension <= datapoint2DimSize; dimension++) | |
64 { | |
65 double dimension1 = 0; | |
66 try { | |
67 dimension1 = this.getDimensionValue(dimension); | |
68 } catch (DimensionException e) { | |
69 // TODO Auto-generated catch block | |
70 System.out.println(e.getMessage()); | |
71 e.printStackTrace(); | |
72 } | |
73 double dimension2 = 0; | |
74 try { | |
75 dimension2 = datapoint2.getDimensionValue(dimension); | |
76 } catch (DimensionException e) { | |
77 // TODO Auto-generated catch block | |
78 System.out.println(e.getMessage()); | |
79 e.printStackTrace(); | |
80 } | |
81 | |
82 if (dimension1 < dimension2) | |
83 { | |
84 return -1; | |
85 } | |
86 else if (dimension1 > dimension2) | |
87 { | |
88 return 1; | |
89 } | |
90 } | |
91 | |
92 return 0; | |
93 } | |
94 | |
95 } |