
de.tsl2.nano.util.operation.ToStrConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.operation Show documentation
Show all versions of tsl2.nano.operation Show documentation
TSL2 Framework Operation (abstract parser, conditioned functional or boolean operations - abstract structure for rule-engines)
The newest version!
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Thomas Schneider
* created on: Jun 29, 2012
*
* Copyright: (c) Thomas Schneider 2012, all rights reserved
*/
package de.tsl2.nano.util.operation;
import java.text.Format;
import java.text.ParseException;
import de.tsl2.nano.core.ManagedException;
/**
* standard converter to convert an object into a string and vice versa - using a given {@link Format}. Does exactly the
* same as {@link FromCharSequenceConverter} but swaps the FROM, TO parameter.
*
* @author Thomas Schneider
* @version $Revision$
*/
public class ToStrConverter implements IConverter {
Format format;
/**
* constructor
* @param format
*/
public ToStrConverter(Format format) {
super();
this.format = format;
}
/**
* {@inheritDoc}
*/
@Override
public T from(String toValue) {
try {
return (T) format.parseObject(toValue);
} catch (ParseException e) {
ManagedException.forward(e);
return null;
}
}
/**
* {@inheritDoc}
*/
@Override
public String to(T fromValue) {
return format.format(fromValue);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy