}
/**
+ * Sort and group ranges into sublists where each sublist represents a region
+ * and its contained subregions
+ *
* @param ranges
*/
protected void build(List<T> ranges)
public NCList(T entry)
{
this();
- List<T> ranges = new ArrayList<T>();
- ranges.add(entry);
- build(ranges);
+ subranges.add(new NCNode<T>(entry));
+ size = 1;
}
public NCList()
final int j)
{
NCList<T> newNCList = new NCList<T>();
- newNCList.subranges.addAll(subranges.subList(i, j + 1));
+ newNCList.addNodes(subranges.subList(i, j + 1));
NCNode<T> newNode = new NCNode<T>(entry, newNCList);
for (int k = j; k >= i; k--)
{
subranges.add(i, newNode);
}
+ protected void addNodes(List<NCNode<T>> nodes)
+ {
+ for (NCNode<T> node : nodes)
+ {
+ subranges.add(node);
+ size += node.size();
+ }
+ }
+
/**
* Returns a (possibly empty) list of items whose extent overlaps the given
* range
*
* @return
*/
- public int getSize()
+ public int size()
{
return size;
}
subranges.remove(i);
if (subRegions != null)
{
- subranges.addAll(i, subRegions.subranges);
+ subranges.addAll(subRegions.subranges);
Collections.sort(subranges, intervalSorter);
}
size--;
if (subRegions != null && subRegions.delete(entry))
{
size--;
+ subrange.deleteSubRegionsIfEmpty();
return true;
}
}