43aea2b7e71f962349450784389f426e93a312ab
[jalview.git] / src / intervalstore / api / IntervalStoreI.java
1 /*
2 BSD 3-Clause License
3
4 Copyright (c) 2018, Mungo Carstairs
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice, this
11   list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright notice,
14   this list of conditions and the following disclaimer in the documentation
15   and/or other materials provided with the distribution.
16
17 * Neither the name of the copyright holder nor the names of its
18   contributors may be used to endorse or promote products derived from
19   this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package intervalstore.api;
33
34 import java.util.Collection;
35 import java.util.List;
36
37 import intervalstore.impl.NCList;
38
39 public interface IntervalStoreI<T extends IntervalI> extends Collection<T>
40 {
41
42   /**
43    * Returns a (possibly empty) list of items whose extent overlaps the given
44    * range
45    * 
46    * @param from
47    *          start of overlap range (inclusive)
48    * @param to
49    *          end of overlap range (inclusive)
50    * @return
51    */
52   List<T> findOverlaps(long from, long to);
53
54   /**
55    * Ensures that the IntervalStore is ready for findOverlap.
56    * 
57    * @return true iff the data held satisfy the rules of construction of an
58    *         IntervalStore.
59    * 
60    */
61   boolean isValid();
62
63   /**
64    * Answers the level of nesting of intervals in the store, as
65    * <ul>
66    * <li>0 if the store is empty</li>
67    * <li>1 if all intervals are 'top level' (non nested)</li>
68    * <li>else 1 plus the depth of the enclosed NCList</li>
69    * </ul>
70    * 
71    * @return
72    * @see NCList#getDepth()
73    */
74   int getDepth();
75
76   /**
77    * Return the number of top-level (not-contained) intervals.
78    * 
79    * @return
80    */
81   int getWidth();
82
83   List<T> findOverlaps(long start, long end, List<T> result);
84
85   String prettyPrint();
86
87   /**
88    * Resort and rebuild links.
89    * 
90    * @return
91    */
92   boolean revalidate();
93
94   /**
95    * Get the i-th interval, whatever that means to this store.
96    * 
97    * @param i
98    * @return
99    */
100   IntervalI get(int i);
101
102   /**
103    * Check to see if this store can check for duplicates while adding.
104    * 
105    * @return
106    */
107   boolean canCheckForDuplicates();
108
109   /**
110    * Add with a check for duplicates, if possible.
111    * 
112    * @param interval
113    * @param checkForDuplicate
114    * @return false only if addition was unsuccessful because there was an
115    *         identical interval already in the store or because the store cannot
116    *         check for duplicates
117    */
118   boolean add(T interval, boolean checkForDuplicate);
119
120 }