Comparator<? super IntervalI> 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)
}
/**
- * Adds one interval to the store, allowing duplicates.
+ * Adds one interval to the store, allowing duplicates
*
* @param interval
*/
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;
int pt0 = pt;
while (--pt >= 0 && offsets[pt] == 0)
{
- ;
+
}
if (pt < 0)
{
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
break;
}
if ((bsIgnore == null || !bsIgnore.get(i))
- && iv.equalsInterval(interval))
+ && sameInterval(interval, iv))
{
return i;
}
return -1 - ++i;
}
if ((bsIgnore == null || !bsIgnore.get(i))
- && iv.equalsInterval(interval))
+ && sameInterval(interval, iv))
{
return i;
}
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);
}
/**
}
/**
- * 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.
*
*/
}
/**
- * 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
* <code>remove</code> operation (throws
{
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));
}
case -1:
break;
case 0:
- if (iv.equalsInterval(interval))
+ if (sameInterval(interval, iv))
{
return pt;
}
else
{
int i = intervalCount;
- while (--i >= 0 && !intervals[i].equalsInterval(interval))
+ while (--i >= 0 && !sameInterval(intervals[i], interval))
{
- ;
+
}
return i;
}
* Recreate the key nest arrays.
*
*/
- @Override
public boolean revalidate()
{
isTainted = true;
int beginLast2 = beginLast;
// Phase One: Get the temporary container array myContainer.
-
for (int i = 1; i < intervalCount; i++)
{
int pt = i - 1;