Mercurial > hg > semantic-sia
comparison src/org/qmul/eecs/c4dm/sia/model/Datapoint.java @ 6:7c2d7e0946b3
moved the 'compareTo' method up to the superclass
author | stevenh |
---|---|
date | Tue, 01 Jan 2013 21:15:38 +0000 |
parents | 08675ab08e7f |
children | f21eb0fddba2 |
comparison
equal
deleted
inserted
replaced
5:fea6c3dde1c1 | 6:7c2d7e0946b3 |
---|---|
1 package org.qmul.eecs.c4dm.sia.model; | 1 package org.qmul.eecs.c4dm.sia.model; |
2 | 2 |
3 import java.util.Iterator; | |
4 import java.util.Vector; | |
5 | |
6 import org.qmul.eecs.c4dm.sia.SiaMain; | 3 import org.qmul.eecs.c4dm.sia.SiaMain; |
7 import org.qmul.eecs.c4dm.sia.exceptions.DimensionException; | |
8 | 4 |
9 import com.hp.hpl.jena.rdf.model.Resource; | 5 import com.hp.hpl.jena.rdf.model.Resource; |
10 | 6 |
11 public class Datapoint extends NDimensionalObject implements Comparable { | 7 public class Datapoint extends NDimensionalObject { |
12 | 8 |
13 private Resource resource; | 9 private Resource resource; |
14 private int orderedIndex; | 10 private int orderedIndex; |
15 | 11 |
16 public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "Datapoint"; | 12 public static final String RESOURCE_URI = SiaMain.SIA_NS_URI + "Datapoint"; |
41 */ | 37 */ |
42 public void setOrderedIndex(int orderedIndex) { | 38 public void setOrderedIndex(int orderedIndex) { |
43 this.orderedIndex = orderedIndex; | 39 this.orderedIndex = orderedIndex; |
44 } | 40 } |
45 | 41 |
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 } | 42 } |