1 package jalview.datamodel.features;
3 import java.util.ArrayList;
7 * Each node of the NCList tree consists of a range, and (optionally) the NCList
8 * of ranges it encloses
12 class NCNode<V extends ContiguousI>
15 * deep size (number of ranges included)
21 private NCList<V> subregions;
28 NCNode(List<V> ranges)
40 List<V> ranges = new ArrayList<V>();
48 protected void build(List<V> ranges)
52 if (!ranges.isEmpty())
54 region = ranges.get(0);
56 if (ranges.size() > 1)
58 subregions = new NCList<V>(ranges.subList(1, ranges.size()));
64 return region.getBegin();
69 return region.getEnd();
73 public String toString() {
74 StringBuilder sb = new StringBuilder(10 * size);
75 sb.append(region.getBegin()).append("-").append(region.getEnd());
76 if (subregions != null)
78 sb.append(" ").append(subregions.toString());
84 * Add any ranges that overlap the from-to range to the result list
90 void addOverlaps(long from, long to, List<V> result)
92 if (region.getBegin() <= to && region.getEnd() >= from)
96 if (subregions != null)
98 subregions.findOverlaps(from, to, result);
103 * Add one range to this subrange
107 public synchronized void add(V entry)
109 if (entry.getBegin() < region.getBegin() || entry.getEnd() > region.getEnd()) {
110 throw new IllegalArgumentException(String.format(
111 "adding improper subrange %d-%d to range %d-%d",
112 entry.getBegin(), entry.getEnd(), region.getBegin(),
115 if (subregions == null)
117 subregions = new NCList<V>(entry);
121 subregions.add(entry);