X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FNCNode.java;h=007f3b12cbd7b8821bd9b84676c38d38f38dfcc4;hb=c2e16e95b564932deda33dc59ecaea367e7b33b0;hp=6af913a64eb4be7cf034e15af59d4159c63be6d8;hpb=30355a6f53c842429f4ca2e31f60a7c5de167f1a;p=jalview.git diff --git a/src/jalview/datamodel/features/NCNode.java b/src/jalview/datamodel/features/NCNode.java index 6af913a..007f3b1 100644 --- a/src/jalview/datamodel/features/NCNode.java +++ b/src/jalview/datamodel/features/NCNode.java @@ -1,5 +1,7 @@ package jalview.datamodel.features; +import jalview.datamodel.ContiguousI; + import java.util.ArrayList; import java.util.List; @@ -9,7 +11,7 @@ import java.util.List; * * @param */ -class NCNode +class NCNode implements ContiguousI { /* * deep size (number of ranges included) @@ -40,7 +42,7 @@ class NCNode */ NCNode(V range) { - List ranges = new ArrayList(); + List ranges = new ArrayList<>(); ranges.add(range); build(ranges); } @@ -49,7 +51,7 @@ class NCNode { region = entry; subregions = newNCList; - size = 1 + newNCList.getSize(); + size = 1 + newNCList.size(); } /** @@ -69,12 +71,14 @@ class NCNode } } - int getStart() + @Override + public int getBegin() { return region.getBegin(); } - int getEnd() + @Override + public int getEnd() { return region.getEnd(); } @@ -148,6 +152,7 @@ class NCNode { subregions.add(entry); } + size++; } /** @@ -158,11 +163,18 @@ class NCNode */ boolean isValid() { + /* + * we don't handle reverse ranges + */ + if (region != null && region.getBegin() > region.getEnd()) + { + return false; + } if (subregions == null) { return true; } - return subregions.isValid(getStart(), getEnd()); + return subregions.isValid(getBegin(), getEnd()); } /** @@ -178,4 +190,66 @@ class NCNode subregions.getEntries(entries); } } + + /** + * Answers true if this object contains the given entry (by object equals + * test), else false + * + * @param entry + * @return + */ + boolean contains(V entry) + { + if (entry == null) + { + return false; + } + if (entry.equals(region)) + { + return true; + } + return subregions == null ? false : subregions.contains(entry); + } + + /** + * Answers the 'root' region modelled by this object + * + * @return + */ + V getRegion() + { + return region; + } + + /** + * Answers the (possibly null) contained regions within this object + * + * @return + */ + NCList getSubRegions() + { + return subregions; + } + + /** + * Nulls the subregion reference if it is empty (after a delete entry + * operation) + */ + void deleteSubRegionsIfEmpty() + { + if (subregions != null && subregions.size() == 0) + { + subregions = null; + } + } + + /** + * Answers the (deep) size of this node i.e. the number of ranges it models + * + * @return + */ + int size() + { + return size; + } }