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

Last change on this file was 2254, checked in by pharms, 7 years ago
  • solved some findbugs issues
  • Property svn:executable set to *
File size: 3.0 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    /**
[830]85     * <p>
86     * Returns the selected value associated with this event.
87     * </p>
88     *
[544]89     * @return the selectedValue
90     */
91    public T getSelectedValue() {
[550]92        return selectedValue;
[544]93    }
94
95    /*
96     * (non-Javadoc)
97     *
98     * @see java.lang.Object#equals(java.lang.Object)
99     */
100    @Override
101    public boolean equals(Object obj) {
102        if ((obj == null) || (!(obj instanceof ValueSelection<?>))) {
103            return false;
104        }
105
106        ValueSelection<?> otherValueSelection = (ValueSelection<?>) obj;
107
[2235]108        return ((selectedValue == otherValueSelection.selectedValue) ||
109                ((selectedValue != null) &&
110                 (selectedValue.equals(otherValueSelection.selectedValue))));
[544]111    }
112
[830]113    /*
114     * (non-Javadoc)
115     *
[564]116     * @see java.lang.Object#hashCode()
117     */
118    @Override
119    public int hashCode() {
[1388]120        if( selectedValue==null ) {
121                return 13;
122        }
[564]123        return selectedValue.hashCode();
124    }
125
[544]126}
Note: See TracBrowser for help on using the repository browser.