@Test public void testToObjectType() throws Exception { Column col; col = new Column("title", 0); Assert.assertEquals("test", col.toObjectType("test", String.class)); col = new Column("title {{ String }}", 0); Assert.assertEquals("true", col.toObjectType("true", String.class)); }
protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data); if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } }
Column { protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data); if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } } }
Column { protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data); if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } } Column(final String raw, final int index); }
Column { protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data); if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } } Column(final String raw, final int index); T getData(String data); T[] getMultiData(String data); int getJcrPropertyType(); String getRaw(); String getPropertyName(); String getRelPropertyPath(); boolean isMulti(); Class getDataType(); int getIndex(); boolean isIgnore(); void setIgnore(final boolean ignore); void setMultiDelimiter(final String multiDelimiter); static Map<String, Column> getColumns(final String[] row,
                                                 final String multiDelimiter,
                                                 final String[] ignoreProperties,
                                                 final String[] requiredProperties); }
Column { protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data); if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } } Column(final String raw, final int index); T getData(String data); T[] getMultiData(String data); int getJcrPropertyType(); String getRaw(); String getPropertyName(); String getRelPropertyPath(); boolean isMulti(); Class getDataType(); int getIndex(); boolean isIgnore(); void setIgnore(final boolean ignore); void setMultiDelimiter(final String multiDelimiter); static Map<String, Column> getColumns(final String[] row,
                                                 final String multiDelimiter,
                                                 final String[] ignoreProperties,
                                                 final String[] requiredProperties);  }