author | Jaroslav Tulach <jtulach@netbeans.org> |
Wed, 11 Feb 2009 10:16:43 +0100 | |
changeset 318 | 38ebce3000fd |
parent 317 | e101649dbd17 |
child 319 | 6c1d8b5553d8 |
permissions | -rw-r--r-- |
jtulach@315 | 1 |
package org.apidesign.javamonitorflaws; |
jtulach@315 | 2 |
|
jtulach@315 | 3 |
import org.apidesign.javamonitorflaws.Cache; |
jtulach@315 | 4 |
import java.beans.PropertyChangeListener; |
jtulach@315 | 5 |
import java.beans.PropertyChangeSupport; |
jtulach@315 | 6 |
|
jtulach@315 | 7 |
/** |
jtulach@315 | 8 |
* |
jtulach@315 | 9 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jtulach@315 | 10 |
*/ |
jtulach@317 | 11 |
// BEGIN: monitor.pitfalls.subclass |
jtulach@315 | 12 |
public class MultiplyCache extends Cache<String,Integer> { |
jtulach@315 | 13 |
private PropertyChangeSupport pcs; |
jtulach@315 | 14 |
private int multiply; |
jtulach@315 | 15 |
public static final String PROP_MULTIPLY = "multiply"; |
jtulach@315 | 16 |
|
jtulach@315 | 17 |
public synchronized int getMultiply() { |
jtulach@315 | 18 |
return multiply; |
jtulach@315 | 19 |
} |
jtulach@315 | 20 |
public synchronized void setMultiply(int multiply) { |
jtulach@315 | 21 |
int oldMultiply = this.multiply; |
jtulach@315 | 22 |
this.multiply = multiply; |
jtulach@315 | 23 |
pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply); |
jtulach@315 | 24 |
} |
jtulach@315 | 25 |
|
jtulach@318 | 26 |
public synchronized void addPropertyChangeListener( |
jtulach@318 | 27 |
PropertyChangeListener listener |
jtulach@318 | 28 |
) { |
jtulach@315 | 29 |
if (pcs == null) { |
jtulach@315 | 30 |
pcs = new PropertyChangeSupport(this); |
jtulach@315 | 31 |
} |
jtulach@315 | 32 |
pcs.addPropertyChangeListener(listener); |
jtulach@315 | 33 |
} |
jtulach@318 | 34 |
public synchronized void removePropertyChangeListener( |
jtulach@318 | 35 |
PropertyChangeListener listener |
jtulach@318 | 36 |
) { |
jtulach@315 | 37 |
if (pcs != null) { |
jtulach@315 | 38 |
pcs.removePropertyChangeListener(listener); |
jtulach@315 | 39 |
} |
jtulach@315 | 40 |
} |
jtulach@315 | 41 |
|
jtulach@315 | 42 |
@Override |
jtulach@315 | 43 |
protected Integer createItem(String f) { |
jtulach@315 | 44 |
return f.length() * getMultiply(); |
jtulach@315 | 45 |
} |
jtulach@317 | 46 |
} |
jtulach@317 | 47 |
// END: monitor.pitfalls.subclass |
jtulach@315 | 48 |
|
jtulach@315 | 49 |