package aQute.bnd.build.model.conversions;

/**
 * Formats an enum type. Outputs {@code null} when the value of the enum is
 * equal to a default value.
 * 
 * @param <E>
 * @author Neil Bartlett
 */
public class EnumFormatter<E extends Enum<E>> implements Converter<String,E> {

	private final Class<E>	enumType;
	private final E			defaultValue;

	/**
	 * Construct a new formatter with no default value, i.e. any non-null value
	 * of the enum will print that value.
	 * 
	 * @param enumType
	 *            The enum type.
	 * @return
	 */
	public static <E extends Enum<E>> EnumFormatter<E> create(Class<E> enumType) {
		return new EnumFormatter<E>(enumType, null);
	}

	/**
	 * Construct a new formatter with the specified default value.
	 * 
	 * @param enumType
	 *            The enum type.
	 * @param defaultValue
	 *            The default value, which will never be output.
	 * @return
	 */
	public static <E extends Enum<E>> EnumFormatter<E> create(Class<E> enumType, E defaultValue) {
		return new EnumFormatter<E>(enumType, defaultValue);
	}

	private EnumFormatter(Class<E> enumType, E defaultValue) {
		this.enumType = enumType;
		this.defaultValue = defaultValue;
	}

	public String convert(E input) throws IllegalArgumentException {
		String result;
		if (input == defaultValue || input == null)
			result = null;
		else {
			result = input.toString();
		}
		return result;
	}

}

@@ -277,42 +277,8 @@
  %7B%0A%0A
-%09private final Class%3CE%3E%09enumType;%0A
 %09pri
@@ -610,26 +610,16 @@
 tter%3CE%3E(
-enumType, 
 null);%0A%09
@@ -974,26 +974,16 @@
 tter%3CE%3E(
-enumType, 
 defaultV
@@ -1020,72 +1020,25 @@
 ter(
-Class%3CE%3E enumType, E defaultValue) %7B%0A%09%09this.enumType = enumType;
+E defaultValue) %7B
 %0A%09%09t

remove unused enumType in EnumFormatter