samples/deadlock/test/org/apidesign/javamonitorflaws/MultiplyCacheOK.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 12 Feb 2009 10:55:02 +0100
changeset 319 6c1d8b5553d8
permissions -rw-r--r--
Changing the test to run with both version, the bad Cache as well as CacheOK. Making sure the same test passes for CacheOK
jtulach@319
     1
package org.apidesign.javamonitorflaws;
jtulach@319
     2
jtulach@319
     3
import java.beans.PropertyChangeListener;
jtulach@319
     4
import java.beans.PropertyChangeSupport;
jtulach@319
     5
jtulach@319
     6
/**
jtulach@319
     7
 *
jtulach@319
     8
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@319
     9
 */
jtulach@319
    10
// BEGIN: monitor.pitfalls.subclassok
jtulach@319
    11
public class MultiplyCacheOK extends CacheOK<String,Integer>
jtulach@319
    12
implements CacheTest.CacheToTest {
jtulach@319
    13
    private PropertyChangeSupport pcs;
jtulach@319
    14
    private int multiply;
jtulach@319
    15
    public static final String PROP_MULTIPLY = "multiply";
jtulach@319
    16
jtulach@319
    17
    public synchronized int getMultiply() {
jtulach@319
    18
        return multiply;
jtulach@319
    19
    }
jtulach@319
    20
    public synchronized void setMultiply(int multiply) {
jtulach@319
    21
        int oldMultiply = this.multiply;
jtulach@319
    22
        this.multiply = multiply;
jtulach@319
    23
        pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
jtulach@319
    24
    }
jtulach@319
    25
jtulach@319
    26
    public synchronized void addPropertyChangeListener(
jtulach@319
    27
        PropertyChangeListener listener
jtulach@319
    28
    ) {
jtulach@319
    29
        if (pcs == null) {
jtulach@319
    30
            pcs = new PropertyChangeSupport(this);
jtulach@319
    31
        }
jtulach@319
    32
        pcs.addPropertyChangeListener(listener);
jtulach@319
    33
    }
jtulach@319
    34
    public synchronized void removePropertyChangeListener(
jtulach@319
    35
        PropertyChangeListener listener
jtulach@319
    36
    ) {
jtulach@319
    37
        if (pcs != null) {
jtulach@319
    38
            pcs.removePropertyChangeListener(listener);
jtulach@319
    39
        }
jtulach@319
    40
    }
jtulach@319
    41
jtulach@319
    42
    @Override
jtulach@319
    43
    protected Integer createItem(String f) {
jtulach@319
    44
        return f.length() * multiply;
jtulach@319
    45
    }
jtulach@319
    46
}
jtulach@319
    47
// END: monitor.pitfalls.subclassok
jtulach@319
    48
jtulach@319
    49