@Override public Object fromString(String str) { try { return str2Measure.convert(str, Measure.class); } catch (Exception e) { throw new IllegalArgumentException(e); } }
@Override public String toString(Object obj) { try { return measure2Str.convert(obj, String.class); } catch (Exception e) { throw new IllegalArgumentException(e); } } }
public <T> T convert(Object source, Class<T> target) throws Exception { Calendar calendar = createConverter(XMLGregorianCalendar.class, Calendar.class, null) .convert(source, Calendar.class); if (calendar != null) { return (T) createConverter(Calendar.class, Date.class, null) .convert(calendar, Date.class); } return null; } };
@Override protected T convertValue(Object o) { double val = ((Number) o).doubleValue(); if (!Double.isNaN(scaleFactor)) { val *= scaleFactor; } if (!Double.isNaN(offsetFactor)) { val += offsetFactor; } try { return converter.convert(val, this.binding); } catch (Exception e) { throw new RuntimeException(e); } } }
public <T> T convert(Object source, Class<T> target) throws Exception { // first go to java.util.Date Date d = Converters.convert(source, Date.class); // then go from date to instant return d != null ? dateToInstant.convert(d, target) : null; } };
public <T> T convert(Object source, Class<T> target) throws Exception { Date date = (Date) source; Calendar calendar = createConverter(Date.class, Calendar.class, null) .convert(date, Calendar.class); return (T) createConverter(Calendar.class, XMLGregorianCalendar.class, null) .convert(calendar, XMLGregorianCalendar.class); } };
/** * Return an HEX representation of a Color * * @param color * @return */ private static String toHexColor(final Color color) { Utilities.ensureNonNull("color", color); try { return COLOR_CONVERTER.convert(color, String.class); } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public void setProperties(SimpleFeature feature) { // get all the matches and convert them in times final List<Number> values = new ArrayList<Number>(); for (String match : getMatches()) { // try to convert to date try { values.add(converter.convert(match, targetClasse)); } catch (Exception e) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.log(Level.INFO, e.getLocalizedMessage(), e); } } // set the properties, if we have some if (values.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("No matches found for this property extractor:"); } int index = 0; for (String propertyName : getPropertyNames()) { // set the property feature.setAttribute(propertyName, values.get(index++)); // do we have more dates? if (index >= values.size()) return; } } }
if (converter != null) { try { T converted = converter.convert(source, target); if (converted != null) { return converted;
if (converter != null) { try { T converted = converter.convert(source, target); if (converted != null) { return converted;
if (converter != null) { try { T converted = converter.convert(source, target); if (converted != null) { return converted;
Boolean convert(Object value) throws Exception { return (Boolean) factory.createConverter(value.getClass(), Boolean.class, null) .convert(value, Boolean.class); } }
private String convert(Clob clob) throws Exception { return factory.createConverter(clob.getClass(), String.class, null) .convert(clob, String.class); } }
Color convert(Object value) throws Exception { Converter converter = factory.createConverter(value.getClass(), Color.class, null); return (Color) converter.convert(value, Color.class); }
private byte[] convert(Blob blob) throws Exception { return factory.createConverter(blob.getClass(), byte[].class, null) .convert(blob, byte[].class); }
private String sut1Convert(Date date) throws Exception { return sut1.createConverter(Date.class, String.class, null).convert(date, String.class); }
Object convert(Object source, Class target) throws Exception { return factory.createConverter(source.getClass(), target, null).convert(source, target); }
Object convert(Object source, Class target) throws Exception { return factory.createConverter(source.getClass(), target, null).convert(source, target); }
public void testTimeZoneToString() throws Exception { Converter converter = factory.createConverter(TimeZone.class, String.class, null); assertNotNull(converter); assertEquals( TimeZone.getDefault().getID(), converter.convert(TimeZone.getDefault(), String.class)); assertNull(converter.convert(null, String.class)); }