本文整理汇总了Java中org.supercsv.cellprocessor.FmtNumber类的典型用法代码示例。如果您正苦于以下问题:Java FmtNumber类的具体用法?Java FmtNumber怎么用?Java FmtNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FmtNumber类属于org.supercsv.cellprocessor包,在下文中一共展示了FmtNumber类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertsToBasicObjects
import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Test
public void testConvertsToBasicObjects() throws IOException {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 1999);
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.DAY_OF_MONTH, 12);
FeatureBean character = new FeatureBean("John", "Connor", 16);
character.setSavings(new BigDecimal(6.65));
character.setBirthDate(calendar.getTime());
String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
new FmtNumber(formatter) };
StringWriter writer = new StringWriter();
CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
beanWriter.write(character, mapping, processors);
beanWriter.close();
String csv = writer.toString();
Assert.assertNotNull(csv);
Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
示例2: testConverterSupport
import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Test
public void testConverterSupport() throws IOException {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 1999);
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.DAY_OF_MONTH, 12);
FeatureBean character = new FeatureBean("John", "Connor", 16);
character.setSavings(new BigDecimal(6.65));
character.setBirthDate(calendar.getTime());
String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
new FmtNumber(formatter) };
StringWriter writer = new StringWriter();
CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
beanWriter.write(character, mapping, processors);
beanWriter.close();
String csv = writer.toString();
Assert.assertNotNull(csv);
Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
示例3: buildForWriting
import org.supercsv.cellprocessor.FmtNumber; //导入依赖的package包/类
@Override
public Optional<CellProcessor> buildForWriting(final Class<Integer> type, final FieldAccessor field,
final Configuration config, final Class<?>[] groups) {
CellProcessor processor = new NotNull(new FmtNumber(new DecimalFormat("#,##0")));
return Optional.of(processor);
}