1 package org.apidesign.javamonitorflaws;
3 import org.apidesign.javamonitorflaws.Cache;
4 import java.beans.PropertyChangeListener;
5 import java.beans.PropertyChangeSupport;
9 * @author Jaroslav Tulach <jtulach@netbeans.org>
11 // BEGIN: monitor.pitfalls.subclass
12 public class MultiplyCache extends Cache<String,Integer> {
13 private PropertyChangeSupport pcs;
15 public static final String PROP_MULTIPLY = "multiply";
17 public synchronized int getMultiply() {
20 public synchronized void setMultiply(int multiply) {
21 int oldMultiply = this.multiply;
22 this.multiply = multiply;
23 pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
26 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
28 pcs = new PropertyChangeSupport(this);
30 pcs.addPropertyChangeListener(listener);
32 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
34 pcs.removePropertyChangeListener(listener);
39 protected Integer createItem(String f) {
40 return f.length() * getMultiply();
43 // END: monitor.pitfalls.subclass