/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
* This program is free software; you can redistribute it and/or\r
* modify it under the terms of the GNU General Public License\r
* replaces oldref with newref in the alignment order.\r
* @param oldref\r
* @param newref\r
- * @return\r
+ * @return true if oldref was contained in order and replaced with newref\r
*/\r
public boolean updateSequence(SequenceI oldref, SequenceI newref) {\r
int found=Order.indexOf(oldref);\r
return found>-1;\r
}\r
/**\r
+ * Exact equivalence of two AlignmentOrders\r
+ * @param o\r
+ * @return true if o orders the same sequenceI objects in the same way\r
+ */\r
+ public boolean equals(AlignmentOrder o) {\r
+ return equals(o, true);\r
+ }\r
+ /**\r
+ * Exact equivalence of two AlignmentOrders\r
+ * // TODO: Weak SequenceI equivalence - will throw Error at moment\r
+ * @param o\r
+ * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)\r
+ * @return true if o orders equivalent sequenceI objects in the same way\r
+ */\r
+ public boolean equals(AlignmentOrder o, boolean identity) {\r
+ if (o!=this) {\r
+ if (o==null)\r
+ return false;\r
+ if (Order!=null && o.Order!=null && Order.size()==o.Order.size()) {\r
+ if (!identity) {\r
+ throw new Error("Weak sequenceI equivalence not yet implemented.");\r
+ } else {\r
+ for (int i=0,j=o.Order.size(); i<j; i++) {\r
+ if (Order.elementAt(i)!=o.Order.elementAt(i))\r
+ return false;\r
+ }\r
+ }\r
+ } else\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ /**\r
+ * Consistency test for alignmentOrders\r
+ * @param o\r
+ * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way\r
+ */\r
+ public boolean isConsistent(AlignmentOrder o) {\r
+ return isConsistent(o, true);\r
+ }\r
+ /**\r
+ * Consistency test for alignmentOrders\r
+ * @param o\r
+ * // TODO: Weak SequenceI equivalence - will throw Error at moment\r
+ * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)\r
+ * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way\r
+ */\r
+ public boolean isConsistent(AlignmentOrder o, boolean identity) {\r
+ if (o!=this) {\r
+ if (o==null)\r
+ return false;\r
+ if (Order!=null && o.Order!=null) {\r
+ Vector c,s;\r
+ if (o.Order.size()>Order.size()) {\r
+ c = o.Order;\r
+ s = Order;\r
+ } else {\r
+ c = Order;\r
+ s = o.Order;\r
+ }\r
+ if (!identity) {\r
+ throw new Error("Weak sequenceI equivalence not yet implemented.");\r
+ } else {\r
+ // test if c contains s and order in s is conserved in c\r
+ int last=-1;\r
+ for (int i=0,j=s.size(); i<j; i++) {\r
+ int pos=c.indexOf(s.elementAt(i)); // JBPNote - optimize by incremental position search\r
+ if (pos>last) {\r
+ last=pos;\r
+ } else\r
+ return false;\r
+ }\r
+ }\r
+ } else\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ /**\r
* AlignmentOrder\r
*\r
* @param orderThis AlignmentI\r