Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/VetoableChangeSupport/TestMethods.java
41149 views
1
/*
2
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 5004188
27
* @summary Tests sequence of methods
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyVetoException;
33
import java.beans.VetoableChangeListener;
34
import java.beans.VetoableChangeSupport;
35
36
enum Fire {
37
PropertyChangeEvent,
38
PropertyObject,
39
PropertyInteger,
40
PropertyBoolean,
41
}
42
43
public class TestMethods extends VetoableChangeSupport implements VetoableChangeListener {
44
private static final String NAME = "property";
45
46
public static void main(String[] args) throws PropertyVetoException {
47
Object source = new Object();
48
new TestMethods(source).fireVetoableChange(new PropertyChangeEvent(source, NAME, null, null));
49
new TestMethods(source).fireVetoableChange(NAME, null, null);
50
new TestMethods(source).fireVetoableChange(NAME, 0, 1);
51
new TestMethods(source).fireVetoableChange(NAME, true, false);
52
}
53
54
private Fire state;
55
56
public TestMethods(Object source) {
57
super(source);
58
addVetoableChangeListener(this);
59
}
60
61
public void vetoableChange(PropertyChangeEvent event) {
62
if (this.state != Fire.PropertyChangeEvent)
63
throw new Error("Illegal state: " + this.state);
64
}
65
66
@Override
67
public void fireVetoableChange(String property, Object oldValue, Object newValue) throws PropertyVetoException {
68
if ((this.state != null) && (this.state != Fire.PropertyBoolean) && (this.state != Fire.PropertyInteger))
69
throw new Error("Illegal state: " + this.state);
70
71
this.state = Fire.PropertyObject;
72
super.fireVetoableChange(property, oldValue, newValue);
73
}
74
75
@Override
76
public void fireVetoableChange(String property, int oldValue, int newValue) throws PropertyVetoException {
77
if (this.state != null)
78
throw new Error("Illegal state: " + this.state);
79
80
this.state = Fire.PropertyInteger;
81
super.fireVetoableChange(property, oldValue, newValue);
82
}
83
84
@Override
85
public void fireVetoableChange(String property, boolean oldValue, boolean newValue) throws PropertyVetoException {
86
if (this.state != null)
87
throw new Error("Illegal state: " + this.state);
88
89
this.state = Fire.PropertyBoolean;
90
super.fireVetoableChange(property, oldValue, newValue);
91
}
92
93
@Override
94
public void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
95
if ((this.state != null) && (this.state != Fire.PropertyObject))
96
throw new Error("Illegal state: " + this.state);
97
98
this.state = Fire.PropertyChangeEvent;
99
super.fireVetoableChange(event);
100
}
101
}
102
103