I have a class which analyzes a string and if the string is not null or an empty string, it creates a new String or new Date using the object depending on the type of subclass. If the string is null or empty it returns an empty string. Currently I call this class converter however I feel this name is misleading, is there a better name anyone can think of for what this class is doing? I want something intuitive that will make my code more readable. Thanks.
public abstract class Converter {
Object returnObject;
public Converter() {
}
public Object convert(String value)
{
if(!this.isEmpty(value))
{
this.setReturnObject(value);
}else
{
this.returnObject = "";
}
return this.getReturnObject();
}
protected boolean isEmpty(String value)
{
return (value != null && value.equalsIgnoreCase(""));
}
protected abstract void setReturnObject(String value);
protected Object getReturnObject(){
return this.returnObject;
}
}
public class NumberConverter extends Converter {
public NumberConverter() {
}
protected void setReturnObject(String value) {
this.returnObject = new Number(Integer.parseInt(value));
}
}
You can use either EntityMapper or EntityTransformer.