JAL-3401 reset 'no repaint' flag after New View / copyAlignPanel
[jalview.git] / test / intervalstore / nonc / SimpleFeature.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.nonc;
33
34 import intervalstore.api.IntervalI;
35
36 /**
37  * A simplified feature instance sufficient for unit test purposes
38  */
39 public class SimpleFeature implements IntervalI
40 {
41   final private int begin;
42
43   final private int end;
44
45   private String description;
46
47   /**
48    * Constructor
49    * 
50    * @param from
51    * @param to
52    * @param desc
53    */
54   public SimpleFeature(int from, int to, String desc)
55   {
56     begin = from;
57     end = to;
58     description = desc;
59   }
60
61   /**
62    * Copy constructor
63    * 
64    * @param sf1
65    */
66   public SimpleFeature(SimpleFeature sf1)
67   {
68     this(sf1.begin, sf1.end, sf1.description);
69   }
70
71   @Override
72   public int getBegin()
73   {
74     return begin;
75   }
76
77   @Override
78   public int getEnd()
79   {
80     return end;
81   }
82
83   public String getDescription()
84   {
85     return description;
86   }
87
88   @Override
89   public int hashCode()
90   {
91     return begin + 37 * end
92             + (description == null ? 0 : description.hashCode());
93   }
94
95   /**
96    * Equals method that requires two instances to have the same description, as
97    * well as start and end position.
98    */
99   @Override
100   public boolean equals(Object obj)
101   {
102     if (obj != null && obj instanceof SimpleFeature)
103     {
104       SimpleFeature o = (SimpleFeature) obj;
105       if (this.begin == o.begin && this.end == o.end)
106       {
107         if (this.description == null)
108         {
109           return o.description == null;
110         }
111         return this.description.equals(o.description);
112       }
113     }
114     return false;
115   }
116
117   @Override
118   public String toString()
119   {
120     return begin + ":" + end + ":" + description;
121   }
122
123 }