source: trunk/autoquest-plugin-android/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/TouchSingle.java @ 2254

Last change on this file since 2254 was 2254, checked in by pharms, 7 years ago
  • solved some findbugs issues
  • Property svn:mime-type set to text/plain
File size: 3.3 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.eventcore.gui;
16
17/**
18 * <p>
19 * Event type for a single touch events, i.e. touch on a mobile phone.
20 * </p>
21 *
22 * @version 1.0
23 * @author Florian Unger
24 */
25public class TouchSingle extends TouchInteraction {
26
27    /**
28     * <p>
29     * Id for object serialization.
30     * </p>
31     */
32    private static final long serialVersionUID = 1L;
33
34    /**
35     * <p>
36     * The x coordinate of the touched view in time of touch.
37     * </p>
38     */
39    /*
40     * (non-Javadoc)
41     *
42     * @see android.view.View#getX()
43     * http://developer.android.com/reference/android/view/View.html#getX()
44     */
45    private float x;
46
47    /**
48     * <p>
49     * The y coordinate of the touched view in time of touch.
50     * </p>
51     */
52    /*
53     * (non-Javadoc)
54     *
55     * @see android.view.View#getY()
56     * http://developer.android.com/reference/android/view/View.html#getY()
57     */
58    private float y;
59
60    /**
61     * <p>
62     * Constructor. Creates a new {@link TouchSingle} event type.
63     * </p>
64     */
65    public TouchSingle(float x, float y) {
66        this.x = x;
67        this.y = y;
68    }
69
70    @Override
71    public String getName() {
72        return "TouchSingle";
73    }
74
75    /**
76     * @return the x position of the touched view in time of touch
77     */
78    public float getX() {
79        return x;
80    }
81
82    /**
83     * @return the y position of the touched view in time of touch
84     */
85    public float getY() {
86        return y;
87    }
88
89    /*
90     * (non-Javadoc)
91     *
92     * @see java.lang.Object#equals(java.lang.Object)
93     */
94    @Override
95    public boolean equals(Object obj) {
96        if(obj == this){
97            return true;
98        }
99        if(!(obj instanceof TouchSingle)){
100            return false;
101        }
102        TouchSingle touch = (TouchSingle)obj;
103        return touch.getX() == x && touch.getY() == y;
104    }
105
106    /*
107     * (non-Javadoc)
108     *
109     * @see java.lang.Object#hashCode()
110     */
111    @Override
112    public int hashCode() {
113        // 17 due to the reason that this is a prime number.
114        int result = 17;
115        /*
116         * 31 due to the reason that a lot of VM's could optimize this multiplication by a shift.
117         * Source: Effective Java, Joshua Bloch, 2008, p.48
118         */
119        result = 31 * result + Float.floatToIntBits(x);
120        result = 31 * result + Float.floatToIntBits(y);
121        return result;
122    }
123
124    /*
125     * (non-Javadoc)
126     *
127     * @see java.lang.Object#toString()
128     */
129    @Override
130    public String toString() {
131        return "SingleTouch(" + x + "," + y + ")";
132    }
133
134}
Note: See TracBrowser for help on using the repository browser.