support for empty linear type order
@@ -65,8 +65,10 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
private int computedHashCode;
- private TotalTypeOrder(String[] typeList, TypeSystem ts) throws CASException {
- this(encodeTypeList(typeList, ts), ts);
+ private final boolean isEmptyTypeOrder;
+
+ private TotalTypeOrder(String[] typeList, TypeSystem ts, boolean isEmpty) throws CASException {
+ this(encodeTypeList(typeList, ts), ts, isEmpty);
}
private static int[] encodeTypeList(String[] typeList, TypeSystem ts) throws CASException {
@@ -89,7 +91,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
* @param typeList the list of ordered types
* @param ts the type system
*/
- private TotalTypeOrder(int[] typeList, TypeSystem ts) {
+ private TotalTypeOrder(int[] typeList, TypeSystem ts, boolean isEmpty) {
super();
TypeSystemImpl tsi = (TypeSystemImpl) ts;
this.order = typeList;
@@ -102,6 +104,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
for (int i = 0; i < this.order.length; i++) {
this.typeCodeToOrder[this.order[i]] = (short)i;
}
+ this.isEmptyTypeOrder = isEmpty;
}
@@ -129,7 +132,6 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
@Override
public boolean lessThan(int t1, int t2) {
return this.typeCodeToOrder[t1] < this.typeCodeToOrder[t2];
-
// return this.lt[t1].get(t2);
}
@@ -168,8 +170,14 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
return true;
}
+ @Override
+ public boolean isEmptyTypeOrder() {
+ return isEmptyTypeOrder;
+ }
+
}
+
private class Node extends GraphNode {
private Node(Object o) {
@@ -347,7 +355,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
* @return -
*/
public static LinearTypeOrder createTypeOrder(int[] typeList, TypeSystem ts) {
- return new TotalTypeOrder(typeList, ts);
+ return new TotalTypeOrder(typeList, ts, false);
}
@Override
@@ -431,6 +439,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
@Override
public LinearTypeOrder getOrder() throws CASException {
+ int origOrderSize = order.size();
addInheritanceTypes();
Node inRank0Nodes = new Node("");
Graph g = this.order.copy(inRank0Nodes);
@@ -451,7 +460,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder {
// for (int i = 0; i < totalOrder.length; i++) {
// System.out.println(" " + totalOrder[i]);
// }
- return new TotalTypeOrder(totalOrder, this.ts);
+ return new TotalTypeOrder(totalOrder, this.ts, origOrderSize == 0);
}
}
