samples/deadlock/test/org/apidesign/javamonitorflaws/MultiplyCache.java
changeset 315 08dd52950883
child 316 41a4abecb600
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/deadlock/test/org/apidesign/javamonitorflaws/MultiplyCache.java	Tue Feb 10 18:36:21 2009 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +package org.apidesign.javamonitorflaws;
     1.5 +
     1.6 +import org.apidesign.javamonitorflaws.Cache;
     1.7 +import java.beans.PropertyChangeListener;
     1.8 +import java.beans.PropertyChangeSupport;
     1.9 +
    1.10 +/**
    1.11 + *
    1.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.13 + */
    1.14 +public class MultiplyCache extends Cache<String,Integer> {
    1.15 +    private PropertyChangeSupport pcs;
    1.16 +    private int multiply;
    1.17 +    public static final String PROP_MULTIPLY = "multiply";
    1.18 +
    1.19 +    public synchronized int getMultiply() {
    1.20 +        return multiply;
    1.21 +    }
    1.22 +    public synchronized void setMultiply(int multiply) {
    1.23 +        int oldMultiply = this.multiply;
    1.24 +        this.multiply = multiply;
    1.25 +        pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
    1.26 +    }
    1.27 +
    1.28 +    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
    1.29 +        if (pcs == null) {
    1.30 +            pcs = new PropertyChangeSupport(this);
    1.31 +        }
    1.32 +        pcs.addPropertyChangeListener(listener);
    1.33 +    }
    1.34 +    public void removePropertyChangeListener(PropertyChangeListener listener) {
    1.35 +        if (pcs != null) {
    1.36 +            pcs.removePropertyChangeListener(listener);
    1.37 +        }
    1.38 +    }
    1.39 +
    1.40 +    @Override
    1.41 +    protected Integer createItem(String f) {
    1.42 +        return f.length() * getMultiply();
    1.43 +    }
    1.44 +
    1.45 +
    1.46 +}
    1.47 \ No newline at end of file