01: package net.sf.jmoney.model2;
02:
03: import java.util.Comparator;
04:
05: /**
06: * This class provides a default implementation of some of the methods
07: * in the IPropertyControlFactory interface. Plug-ins do not have to use
08: * this class but can instead implement the interface directly.
09: *
10: * This class, like the IPropertyControlFactory interface, is parameterized
11: * with the class of values of the property. However, this class further
12: * requires that the class implements the Comparable interface. This allows
13: * this class to provide a default implementation of the getComparator method.
14: * If the values of the property are of a class that does not implement Comparable
15: * then this helper class cannot be used.
16: *
17: * @author Nigel
18: *
19: */
20: public abstract class PropertyControlFactory<V extends Comparable<? super V>>
21: implements IPropertyControlFactory<V> {
22:
23: public String formatValueForTable(
24: ExtendableObject extendableObject,
25: ScalarPropertyAccessor<? extends V> propertyAccessor) {
26: V value = extendableObject.getPropertyValue(propertyAccessor);
27: return value.toString();
28: }
29:
30: public String formatValueForMessage(
31: ExtendableObject extendableObject,
32: ScalarPropertyAccessor<? extends V> propertyAccessor) {
33: V value = extendableObject.getPropertyValue(propertyAccessor);
34: return value.toString();
35: }
36:
37: public Comparator<V> getComparator() {
38: return new Comparator<V>() {
39: public int compare(V value1, V value2) {
40: return value1.compareTo(value2);
41: }
42: };
43: }
44: }
|