source: trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/ValueSelection.java @ 1388

Last change on this file since 1388 was 1388, checked in by sherbold, 10 years ago
  • fixed bug that caused crashs when the selected value is null
  • Property svn:executable set to *
File size: 3.4 KB
RevLine 
[927]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.
[830]14
[922]15package de.ugoe.cs.autoquest.eventcore.gui;
[544]16
17/**
[830]18 * <p>
19 * Event type for selecting a value.
20 * </p>
[544]21 *
[830]22 * @version 1.0
23 * @author Patrick Harms
[544]24 */
25public class ValueSelection<T> implements IInteraction {
[830]26
27    /**
28     * <p>
29     * Id for object serialization.
30     * </p>
31     */
[544]32    private static final long serialVersionUID = 1L;
33
[830]34    /**
35     * <p>
36     * The selected value.
37     * </p>
38     */
[550]39    private T selectedValue;
[544]40
41    /**
[830]42     * <p>
43     * Constructor. Creates a new ValueSelection.
44     * </p>
[544]45     *
46     * @param selectedValue
[830]47     *            the selected value
[544]48     */
49    public ValueSelection(T selectedValue) {
[550]50        this.selectedValue = selectedValue;
[544]51    }
52
53    /*
54     * (non-Javadoc)
55     *
56     * @see de.harms.attef.userinteraction.Interaction#getName()
57     */
58    public String getName() {
[967]59        String result = "ValueSelection";
60       
61        if (selectedValue != null) {
62            result += "(\"" + selectedValue + "\")";
63        }
64       
65        return result;
[544]66    }
67
68    /*
69     * (non-Javadoc)
70     *
71     * @see java.lang.Object#toString()
72     */
73    @Override
74    public String toString() {
[967]75        String result = "select value";
76       
77        if (selectedValue != null) {
78            result += " \"" + selectedValue + "\"";
79        }
80       
81        return result;
[544]82    }
83
84    /*
85     * (non-Javadoc)
86     *
87     * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()
88     */
89    public boolean startsLogicalSequence() {
90        return false;
91    }
92
93    /*
94     * (non-Javadoc)
95     *
96     * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence()
97     */
98    public boolean finishesLogicalSequence() {
99        return false;
100    }
101
102    /**
[830]103     * <p>
104     * Returns the selected value associated with this event.
105     * </p>
106     *
[544]107     * @return the selectedValue
108     */
109    public T getSelectedValue() {
[550]110        return selectedValue;
[544]111    }
112
113    /*
114     * (non-Javadoc)
115     *
116     * @see java.lang.Object#equals(java.lang.Object)
117     */
118    @Override
119    public boolean equals(Object obj) {
120        if ((obj == null) || (!(obj instanceof ValueSelection<?>))) {
121            return false;
122        }
123
124        ValueSelection<?> otherValueSelection = (ValueSelection<?>) obj;
125
[830]126        return ((otherValueSelection != null) && ((selectedValue == otherValueSelection.selectedValue) || ((selectedValue != null) && (selectedValue
127            .equals(otherValueSelection.selectedValue)))));
[544]128    }
129
[830]130    /*
131     * (non-Javadoc)
132     *
[564]133     * @see java.lang.Object#hashCode()
134     */
135    @Override
136    public int hashCode() {
[1388]137        if( selectedValue==null ) {
138                return 13;
139        }
[564]140        return selectedValue.hashCode();
141    }
142
[544]143}
Note: See TracBrowser for help on using the repository browser.