comparison src/org/qmul/eecs/c4dm/sia/model/VectorTableElement.java @ 8:842ce6ca6e29

modified the 'compareTo' method so that it is now an extension of the base version given in the superclass
author stevenh
date Tue, 01 Jan 2013 21:18:18 +0000
parents 08675ab08e7f
children 8901059f8144
comparison
equal deleted inserted replaced
7:ffd47645ca13 8:842ce6ca6e29
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 /** 7 /**
12 * @author stevenhargreaves 8 * @author stevenhargreaves
13 * 9 *
14 */ 10 */
15 public class VectorTableElement extends NDimensionalObject implements Comparable { 11 public class VectorTableElement extends NDimensionalObject {
16 12
17 private Datapoint fromDatapoint; 13 private Datapoint fromDatapoint;
18 private Datapoint toDatapoint; 14 private Datapoint toDatapoint;
19 private Resource resource; 15 private Resource resource;
20 16
65 /* (non-Javadoc) 61 /* (non-Javadoc)
66 * @see java.lang.Comparable#compareTo(java.lang.Object) 62 * @see java.lang.Comparable#compareTo(java.lang.Object)
67 */ 63 */
68 @Override 64 @Override
69 public int compareTo(Object o2) { 65 public int compareTo(Object o2) {
70 VectorTableElement vte2 = (VectorTableElement)o2;
71 66
72 Vector<DimensionValue> vte2DimVals = vte2.getDimensionValues(); 67 int compareResult = super.compareTo(o2);
73 68
74 int vte2DimSize = vte2DimVals.size(); 69 if (compareResult == 0)
70 {
71 VectorTableElement vte2 = (VectorTableElement)o2;
75 72
76 if (vte2DimSize != this.getDimensionValues().size()) 73 if (this.getFromDatapoint().getOrderedIndex() < vte2.getFromDatapoint().getOrderedIndex())
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 { 74 {
106 return -1; 75 return -1;
107 } 76 }
108 else if (dimension1 > dimension2) 77 else if (this.getFromDatapoint().getOrderedIndex() > vte2.getFromDatapoint().getOrderedIndex())
109 { 78 {
110 return 1; 79 return 1;
111 } 80 }
81 else
82 {
83 return 0;
84 }
112 } 85 }
113 86 return compareResult;
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 } 87 }
124 88
89 public int compareToIgnoreDatapoints(Object o2) {
90
91 int compareResult = super.compareTo(o2);
92 return compareResult;
93 }
125 } 94 }