All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.intarsys.tools.format.NullableFormat Maven / Gradle / Ivy

There is a newer version: 4.11
Show newest version
package de.intarsys.tools.format;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;

/**
 * This format allows a daisy chain style null filtering.
 * 
 */
public class NullableFormat extends Format {

	final private Format format;

	final private String nullValue;

	public NullableFormat(Format format, String nullValue) {
		super();
		this.format = format;
		this.nullValue = nullValue;
	}

	@Override
	public StringBuffer format(Object obj, StringBuffer toAppendTo,
			FieldPosition pos) {
		if (obj == null) {
			toAppendTo.append(getNullValue());
		} else {
			format.format(obj, toAppendTo, pos);
		}
		return toAppendTo;
	}

	public Format getFormat() {
		return format;
	}

	public String getNullValue() {
		return nullValue;
	}

	@Override
	public Object parseObject(String source, ParsePosition pos) {
		return format.parseObject(source, pos);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy