X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FNCNode.java;h=b9917501717f0379283545fc67fe84ebe32a8bd8;hb=8c5cefb3ac80bd094a8dab7ce6735a11583b1772;hp=ab10f67aaec0ca7c5fdb17b1efcf1251d4820718;hpb=0ea61b395605ecf1854406f8e0c9a0be04404cb1;p=jalview.git diff --git a/src/jalview/datamodel/features/NCNode.java b/src/jalview/datamodel/features/NCNode.java index ab10f67..b991750 100644 --- a/src/jalview/datamodel/features/NCNode.java +++ b/src/jalview/datamodel/features/NCNode.java @@ -1,5 +1,27 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel.features; +import jalview.datamodel.ContiguousI; + import java.util.ArrayList; import java.util.List; @@ -9,7 +31,7 @@ import java.util.List; * * @param */ -class NCNode +class NCNode implements ContiguousI { /* * deep size (number of ranges included) @@ -18,6 +40,9 @@ class NCNode private V region; + /* + * null, or an object holding contained subregions of this nodes region + */ private NCList subregions; /** @@ -37,7 +62,7 @@ class NCNode */ NCNode(V range) { - List ranges = new ArrayList(); + List ranges = new ArrayList<>(); ranges.add(range); build(ranges); } @@ -46,7 +71,7 @@ class NCNode { region = entry; subregions = newNCList; - // size = 1 + newNCList.size(); + size = 1 + newNCList.size(); } /** @@ -66,12 +91,14 @@ class NCNode } } - int getStart() + @Override + public int getBegin() { return region.getBegin(); } - int getEnd() + @Override + public int getEnd() { return region.getEnd(); } @@ -112,7 +139,7 @@ class NCNode * @param to * @param result */ - void addOverlaps(long from, long to, List result) + void findOverlaps(long from, long to, List result) { if (region.getBegin() <= to && region.getEnd() >= from) { @@ -145,6 +172,7 @@ class NCNode { subregions.add(entry); } + size++; } /** @@ -155,10 +183,93 @@ 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()); + } + + /** + * Adds all contained entries to the given list + * + * @param entries + */ + void getEntries(List entries) + { + entries.add(region); + if (subregions != null) + { + 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; } }