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