X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fintervalstore%2Fnonc%2FIntervalStore.java;h=5c013adde18030ffbeec423172e179d4f09d74bf;hb=08b87509ada06ac8614424247346daef4054b41a;hp=bc9ca8329f31f9e8920a187f33ef51b7507a640f;hpb=595a9e25db7f4f24c17de84656d7d5391a3d104d;p=jalview.git diff --git a/src/intervalstore/nonc/IntervalStore.java b/src/intervalstore/nonc/IntervalStore.java index bc9ca83..5c013ad 100644 --- a/src/intervalstore/nonc/IntervalStore.java +++ b/src/intervalstore/nonc/IntervalStore.java @@ -224,8 +224,8 @@ public class IntervalStore Comparator comparator, boolean bigendian) { icompare = (comparator != null ? comparator - : bigendian ? IntervalI.COMPARATOR_BIGENDIAN - : IntervalI.COMPARATOR_LITTLEENDIAN); + : bigendian ? IntervalI.COMPARE_BEGIN_ASC_END_DESC + : IntervalI.COMPARE_BEGIN_ASC_END_ASC); this.bigendian = bigendian; if (intervals != null) @@ -259,7 +259,7 @@ public class IntervalStore } /** - * Adds one interval to the store, allowing duplicates. + * Adds one interval to the store, allowing duplicates * * @param interval */ @@ -320,9 +320,6 @@ public class IntervalStore else { index = findInterval(interval); - // System.out.println("index = " + index + " for " + interval + "\n" - // + Arrays.toString(intervals) + "\n" - // + Arrays.toString(offsets)); if (!allowDuplicates && index >= 0) { return false; @@ -405,7 +402,7 @@ public class IntervalStore int pt0 = pt; while (--pt >= 0 && offsets[pt] == 0) { - ; + } if (pt < 0) { @@ -484,7 +481,7 @@ public class IntervalStore case 0: IntervalI iv = intervals[mid]; if ((bsIgnore == null || !bsIgnore.get(mid)) - && iv.equalsInterval(interval)) + && sameInterval(interval, iv)) { return mid; // found one; just scan up and down now, first checking the range, but @@ -498,7 +495,7 @@ public class IntervalStore break; } if ((bsIgnore == null || !bsIgnore.get(i)) - && iv.equalsInterval(interval)) + && sameInterval(interval, iv)) { return i; } @@ -511,7 +508,7 @@ public class IntervalStore return -1 - ++i; } if ((bsIgnore == null || !bsIgnore.get(i)) - && iv.equalsInterval(interval)) + && sameInterval(interval, iv)) { return i; } @@ -522,10 +519,21 @@ public class IntervalStore return -1 - start; } - @Override - public boolean canCheckForDuplicates() + /** + * Answers true if the two intervals are equal (as determined by + * {@code i1.equals(i2)}, else false + * + * @param i1 + * @param i2 + * @return + */ + static boolean sameInterval(IntervalI i1, IntervalI i2) { - return true; + /* + * for speed, do the fast check for begin/end equality before + * the equals check which includes type checking + */ + return i1.equalsInterval(i2) && i1.equals(i2); } /** @@ -766,21 +774,6 @@ public class IntervalStore } /** - * return the i-th interval in the designated order (bigendian or - * littleendian) - */ - @Override - public IntervalI get(int i) - { - if (i < 0 || i >= intervalCount + added) - { - return null; - } - ensureFinalized(); - return intervals[i]; - } - - /** * Return the deepest level of nesting. * */ @@ -821,26 +814,6 @@ public class IntervalStore } /** - * Get the number of root-level nests. - * - */ - @Override - public int getWidth() - { - ensureFinalized(); - // System.out.println( - // "ISList w[0]=" + nestCounts[0] + " w[1]=" + nestCounts[1]); - return nestCounts[0] + (createUnnested ? nestCounts[1] : 0); - } - - @Override - public boolean isValid() - { - ensureFinalized(); - return true; - } - - /** * Answers an iterator over the intervals in the store, with no particular * ordering guaranteed. The iterator does not support the optional * remove operation (throws @@ -915,17 +888,15 @@ public class IntervalStore { sb.append(sep).append(nests[pt + i].toString()); if (nestCounts[pt + i] > 0) + { dump(pt + i, sb, sep + " "); + } } } @Override public synchronized boolean remove(Object o) { - // if (o == null) - // { - // throw new NullPointerException(); - // } return (o != null && intervalCount > 0 && removeInterval((IntervalI) o)); } @@ -964,7 +935,7 @@ public class IntervalStore case -1: break; case 0: - if (iv.equalsInterval(interval)) + if (sameInterval(interval, iv)) { return pt; } @@ -979,9 +950,9 @@ public class IntervalStore else { int i = intervalCount; - while (--i >= 0 && !intervals[i].equalsInterval(interval)) + while (--i >= 0 && !sameInterval(intervals[i], interval)) { - ; + } return i; } @@ -1067,7 +1038,6 @@ public class IntervalStore * Recreate the key nest arrays. * */ - @Override public boolean revalidate() { isTainted = true; @@ -1186,7 +1156,6 @@ public class IntervalStore int beginLast2 = beginLast; // Phase One: Get the temporary container array myContainer. - for (int i = 1; i < intervalCount; i++) { int pt = i - 1;