1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/deadlock/test/org/apidesign/javamonitorflaws/MultiplyCacheOK.java Thu Feb 12 10:55:02 2009 +0100
1.3 @@ -0,0 +1,49 @@
1.4 +package org.apidesign.javamonitorflaws;
1.5 +
1.6 +import java.beans.PropertyChangeListener;
1.7 +import java.beans.PropertyChangeSupport;
1.8 +
1.9 +/**
1.10 + *
1.11 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.12 + */
1.13 +// BEGIN: monitor.pitfalls.subclassok
1.14 +public class MultiplyCacheOK extends CacheOK<String,Integer>
1.15 +implements CacheTest.CacheToTest {
1.16 + private PropertyChangeSupport pcs;
1.17 + private int multiply;
1.18 + public static final String PROP_MULTIPLY = "multiply";
1.19 +
1.20 + public synchronized int getMultiply() {
1.21 + return multiply;
1.22 + }
1.23 + public synchronized void setMultiply(int multiply) {
1.24 + int oldMultiply = this.multiply;
1.25 + this.multiply = multiply;
1.26 + pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
1.27 + }
1.28 +
1.29 + public synchronized void addPropertyChangeListener(
1.30 + PropertyChangeListener listener
1.31 + ) {
1.32 + if (pcs == null) {
1.33 + pcs = new PropertyChangeSupport(this);
1.34 + }
1.35 + pcs.addPropertyChangeListener(listener);
1.36 + }
1.37 + public synchronized void removePropertyChangeListener(
1.38 + PropertyChangeListener listener
1.39 + ) {
1.40 + if (pcs != null) {
1.41 + pcs.removePropertyChangeListener(listener);
1.42 + }
1.43 + }
1.44 +
1.45 + @Override
1.46 + protected Integer createItem(String f) {
1.47 + return f.length() * multiply;
1.48 + }
1.49 +}
1.50 +// END: monitor.pitfalls.subclassok
1.51 +
1.52 +