JAL-3210 updated IntervalStoreJ classes in srcjar
[jalview.git] / srcjar / 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 /**
38  * An interface describing a store of (possibly overlapping) features which may
39  * be queried to find features which overlap a given start-end range
40  * 
41  * @author gmcarstairs
42  *
43  * @param <T>
44  */
45 public interface IntervalStoreI<T extends IntervalI> extends Collection<T>
46 {
47   /**
48    * Returns a (possibly empty) list of items whose extent overlaps the given
49    * range
50    * 
51    * @param from
52    *          start of overlap range (inclusive)
53    * @param to
54    *          end of overlap range (inclusive)
55    * @return
56    */
57   List<T> findOverlaps(long from, long to);
58
59   /**
60    * Returns a (possibly empty) list of items whose extent overlaps the given
61    * range. If the {@code results} parameter is not null, items are appended to
62    * this list and the (possibly extended) list is returned. There is no check
63    * for duplicate entries in the result list.
64    * 
65    * @param from
66    *          start of overlap range (inclusive)
67    * @param to
68    *          end of overlap range (inclusive)
69    * @param result
70    * @return
71    */
72   List<T> findOverlaps(long from, long to, List<T> result);
73
74   /**
75    * Adds the entry to the store, unless {@code allowDuplicates} is false and
76    * the entry is already contained in the store. The test for containment
77    * should match that used in the {@code contains} method.
78    */
79   boolean add(T entry, boolean allowDuplicates);
80
81   /**
82    * Returns a string representation of the data where containment is shown by
83    * indentation on new lines
84    * 
85    * @return
86    */
87   String prettyPrint();
88
89   /**
90    * Answers the depth of nesting of intervals in the store. The precise
91    * definition depends on the implementation.
92    * 
93    * @return
94    */
95   int getDepth();
96
97 }