1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.betwixt.strategy;
17
18 import org.apache.commons.betwixt.AttributeDescriptor;
19
20 /***
21 * Determines whether the expression of an attribute with a values
22 * should be suppressed.
23 *
24 * @since 0.7
25 * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
26 */
27 public abstract class ValueSuppressionStrategy {
28
29 /***
30 * Strategy allows all values to be expressed for all attributes
31 */
32 public static final ValueSuppressionStrategy ALLOW_ALL_VALUES = new ValueSuppressionStrategy() {
33 public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) {
34 return true;
35 }
36 };
37
38 /***
39 * Suppresses all null values.
40 */
41 public static final ValueSuppressionStrategy SUPPRESS_EMPTY = new ValueSuppressionStrategy() {
42 public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) {
43 return "".equals(value);
44 }
45 };
46
47 /***
48 * Default strategy is {@link #SUPPRESS_EMPTY}.
49 */
50 public static final ValueSuppressionStrategy DEFAULT = SUPPRESS_EMPTY;
51
52
53 /***
54 * Should the given attribute value be suppressed?
55 * @param attributeDescriptor <code>AttributeDescriptor</code> describing the attribute, not null
56 * @param value <code>Object</code> value, possibly null
57 * @return true if the attribute should not be written for the given value
58 */
59 public abstract boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value);
60
61 }