Search in sources :

Example 1 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport in project jdk8u_jdk by JetBrains.

the class TestVetoableChangeSupport method test.

private static void test(int step, int listeners, int attempts) throws PropertyVetoException {
    TestVetoableChangeSupport test = new TestVetoableChangeSupport();
    VetoableChangeSupport vcs = new VetoableChangeSupport(test);
    PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
    PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
    long time1 = System.currentTimeMillis();
    for (int i = 0; i < listeners; i++) {
        vcs.addVetoableChangeListener(test);
        vcs.addVetoableChangeListener(NAME, test);
    }
    long time2 = System.currentTimeMillis();
    for (int i = 0; i < attempts; i++) {
        vcs.fireVetoableChange(eventNull);
        vcs.fireVetoableChange(eventName);
    }
    long time3 = System.currentTimeMillis();
    // time of adding the listeners
    time1 = time2 - time1;
    // time of firing the events
    time2 = time3 - time2;
    System.out.println("Step: " + step + "; Listeners: " + listeners + "; Attempts: " + attempts + "; Time (ms): " + time1 + "/" + time2);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 2 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport in project jdk8u_jdk by JetBrains.

the class TestListeners method main.

public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));
    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);
    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);
    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);
    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);
    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));
    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);
    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);
    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
Also used : VetoableChangeListenerProxy(java.beans.VetoableChangeListenerProxy) VetoableChangeSupport(java.beans.VetoableChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 3 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport in project jdk8u_jdk by JetBrains.

the class TestSerialization method create.

private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
Also used : VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 4 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport in project jdk8u_jdk by JetBrains.

the class TestSynchronization method main.

public static void main(String[] args) throws PropertyVetoException {
    final VetoableChangeSupport vcs = new VetoableChangeSupport(TestSynchronization.class);
    vcs.addVetoableChangeListener("name", new VetoableChangeListener() {

        public void vetoableChange(PropertyChangeEvent event) {
            isCalled = true;
        }
    });
    vcs.addVetoableChangeListener(new VetoableChangeListener() {

        public void vetoableChange(PropertyChangeEvent event) {
            for (VetoableChangeListener listener : vcs.getVetoableChangeListeners()) vcs.removeVetoableChangeListener(listener);
        }
    });
    vcs.fireVetoableChange("name", null, null);
    if (!isCalled)
        throw new Error("test failed");
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeSupport(java.beans.VetoableChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 5 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport in project jdk8u_jdk by JetBrains.

the class Test4985020 method main.

public static void main(String[] args) {
    PropertyChangeSupport pcs = new PropertyChangeSupport(args);
    VetoableChangeSupport vcs = new VetoableChangeSupport(args);
    Test4985020 listener = new Test4985020();
    //PropertyChangeSupport.addPropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.addPropertyChangeListener(null, listener)");
    try {
        pcs.addPropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.removePropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.removePropertyChangeListener(null, listener)");
    try {
        pcs.removePropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.getPropertyChangeListeners(null)
    System.out.println("PropertyChangeSupport.getPropertyChangeListeners(null)");
    try {
        PropertyChangeListener[] pcls = pcs.getPropertyChangeListeners(null);
        if (pcls == null) {
            throw new Error("getPropertyChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getPropertyChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null)
    System.out.println("PropertyChangeSupport.hasListeners(null)");
    try {
        pcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null): with a generic listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a generic listener");
    try {
        pcs.addPropertyChangeListener(listener);
        if (!pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    pcs = new PropertyChangeSupport(args);
    //PropertyChangeSupport.hasListeners(null): with a specific listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a specific listener");
    try {
        pcs.addPropertyChangeListener(NAME, listener);
        if (pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.addVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.addVetoableChangeListener(null, listener)");
    try {
        vcs.addVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.removeVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.removeVetoableChangeListener(null, listener)");
    try {
        vcs.removeVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.getVetoableChangeListeners(null)
    System.out.println("VetoableChangeSupport.getVetoableChangeListeners(null)");
    try {
        VetoableChangeListener[] pcls = vcs.getVetoableChangeListeners(null);
        if (pcls == null) {
            throw new Error("getVetoableChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getVetoableChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null)
    System.out.println("VetoableChangeSupport.hasListeners(null)");
    try {
        boolean result = vcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null): with a generic listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a generic listener");
    try {
        vcs.addVetoableChangeListener(listener);
        if (!vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    vcs = new VetoableChangeSupport(args);
    //VetoableChangeSupport.hasListeners(null): with a specific listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a specific listener");
    try {
        vcs.addVetoableChangeListener(NAME, listener);
        if (vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    if (failed) {
        throw new Error("TEST FAILED");
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) VetoableChangeSupport(java.beans.VetoableChangeSupport) PropertyChangeSupport(java.beans.PropertyChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Aggregations

VetoableChangeSupport (java.beans.VetoableChangeSupport)10 VetoableChangeListener (java.beans.VetoableChangeListener)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyVetoException (java.beans.PropertyVetoException)3 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 VetoableChangeListenerProxy (java.beans.VetoableChangeListenerProxy)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1