当前位置: 首页>>代码示例>>Java>>正文


Java CellProcessorAdaptor类代码示例

本文整理汇总了Java中org.supercsv.cellprocessor.CellProcessorAdaptor的典型用法代码示例。如果您正苦于以下问题:Java CellProcessorAdaptor类的具体用法?Java CellProcessorAdaptor怎么用?Java CellProcessorAdaptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CellProcessorAdaptor类属于org.supercsv.cellprocessor包,在下文中一共展示了CellProcessorAdaptor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decideAdaptor

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
static CellProcessorAdaptor decideAdaptor(Field field) {
    String fieldType = field.getType().getSimpleName().toUpperCase(Locale.ENGLISH);
    // if it is enum convert name to ENUM
    if(field.getType().getGenericSuperclass() != null) {
        if (field.getType().getGenericSuperclass().toString().startsWith("java.lang.Enum")) {
            fieldType = "ENUM";
            return Parsers.valueOf(fieldType).getParser(field.getType());
        }
    }
    if(fieldType.equals("DATE")){
        if(field.getAnnotation(JsonFormat.class) != null){
            String format = field.getAnnotation(JsonFormat.class).pattern();
            return new ParseDate(format);
        }else{
            throw  new RuntimeException("Date type must have SimpleDateFormat annotation with a valid format.");
        }
    }else{
        return Parsers.valueOf(fieldType).getParser();
    }





}
 
开发者ID:robeio,项目名称:robe,代码行数:26,代码来源:CSVUtil.java

示例2: decideAdaptor

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
@Test
public void decideAdaptor() throws Exception {
    Field[] fields = SamplePojo.class.getFields();
    for (int i = 0; i < fields.length; i++) {
        CellProcessorAdaptor adapter = CSVUtil.decideAdaptor(fields[i]);
        if (!fields[i].getType().getTypeName().equals(String.class.getName())) {
            assertNotNull(adapter);
        }
    }
}
 
开发者ID:robeio,项目名称:robe,代码行数:11,代码来源:CSVUtilTest.java

示例3: printCellProcessorChain

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
public static void printCellProcessorChain(final CellProcessor cellProcessor, final PrintWriter writer) {
    
    String index = "";
    CellProcessor cp = cellProcessor;
    do {
        if(index.length() == 0) {
            writer.printf("%s%s\n", index, cp.getClass().getName());
            writer.flush();
        } else {
            writer.printf("%s└%s\n", index, cp.getClass().getName());
            writer.flush();
        }
        
        // next processor
        try {
            if(cp instanceof CellProcessorAdaptor) {
                Field field = CellProcessorAdaptor.class.getDeclaredField("next");
                field.setAccessible(true);
                cp = (CellProcessor) field.get(cp);
            } else {
                break;
            }
            
        } catch(ReflectiveOperationException e) {
            return;
        }
        
        index += "    ";
        
    } while(cp != null);
    
}
 
开发者ID:mygreen,项目名称:super-csv-annotation,代码行数:33,代码来源:TestUtils.java

示例4: hasCellProcessor

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
public HasCellProcessorAssert hasCellProcessor(final Class<? extends CellProcessor> clazz) {
    
    CellProcessor cp = actual;
    if(!(cp instanceof CellProcessorAdaptor)) {
        failWithMessage("Expected CellProcessor should be implemeted CellProcessorAdaptor, but <%s> wat not implemented",
                cp.getClass().getName());
    }
    
    do{
        if(cp.getClass().isAssignableFrom(clazz)) {
            return this;
        }
        
        // next processor
        try {
            if(cp instanceof CellProcessorAdaptor) {
                final Field field = CellProcessorAdaptor.class.getDeclaredField("next");
                field.setAccessible(true);
                cp = (CellProcessor) field.get(cp);
            } else {
                break;
            }
            
        } catch(ReflectiveOperationException e) {
            failWithMessage("Fail get field of CellProcessor next chain. :%s", e.getMessage());
        }
        
    } while(cp != null);
    
    StringWriter writer = new StringWriter();
    TestUtils.printCellProcessorChain((CellProcessor)actual, new PrintWriter(writer));
    writer.flush();
    
    failWithMessage("Expected CellProcessor should be implemeted CellProcessorAdaptor, but <%s> wat not implemented.%s",
            cp.getClass().getName(), writer.toString());
    
    return this;
}
 
开发者ID:mygreen,项目名称:super-csv-annotation,代码行数:39,代码来源:HasCellProcessorAssert.java

示例5: ParseCodeShare

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
ParseCodeShare(CellProcessorAdaptor next) {
    super(next);
}
 
开发者ID:Educama,项目名称:Showcase,代码行数:4,代码来源:ConnectionCsvDeserializer.java

示例6: ParseAirportIataCode

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
ParseAirportIataCode(CellProcessorAdaptor next) {
    super(next);
}
 
开发者ID:Educama,项目名称:Showcase,代码行数:4,代码来源:ConnectionCsvDeserializer.java

示例7: ParseAirlinesIataCode

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
ParseAirlinesIataCode(CellProcessorAdaptor next) {
    super(next);
}
 
开发者ID:Educama,项目名称:Showcase,代码行数:4,代码来源:ConnectionCsvDeserializer.java

示例8: decideAdaptorDateError

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void decideAdaptorDateError() throws Exception {
    Field field = getClass().getField("failDate");
    CellProcessorAdaptor adapter = CSVUtil.decideAdaptor(field);
    assertNotNull(adapter);
}
 
开发者ID:robeio,项目名称:robe,代码行数:7,代码来源:CSVUtilTest.java

示例9: readWithCsvDozerBeanReaderUsingIndexMappingAndHints

import org.supercsv.cellprocessor.CellProcessorAdaptor; //导入依赖的package包/类
/**
 * An example of reading using CsvDozerBeanReader that uses indexed mapping and a cell processor
 * to read into a List of Answer beans (this requires a hint).
 */
private static void readWithCsvDozerBeanReaderUsingIndexMappingAndHints() throws Exception {
	
	// simple cell processor that creates an Answer with a value
	final CellProcessor parseAnswer = new CellProcessorAdaptor() {
		public Object execute(Object value, CsvContext context) {
			return new Answer(null, (String) value);
		}
	};
	
	final CellProcessor[] processors = new CellProcessor[] { 
		new Optional(new ParseInt()), // age
		null,                         // consent
		null,                         // questionNo 1
		new Optional(parseAnswer),    // answer 1
		null,                         // questionNo 2
		new Optional(parseAnswer),    // answer 2
		null,                         // questionNo 3
		new Optional(parseAnswer)     // answer 3
	};
	
	// no deep mapping (answers[0].answer) required as we're using a cell processor to create the bean
	final String[] fieldMapping = {"age", null, null, "answers[0]", null, "answers[1]", null, "answers[2]"};
	
	// the indexed mappings need a hint for Dozer to work
	final Class<?>[] hintTypes = {null, null, null, Answer.class, null, Answer.class, null, Answer.class};
	
	ICsvDozerBeanReader beanReader = null;
	try {
		beanReader = new CsvDozerBeanReader(new FileReader(CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
		
		beanReader.getHeader(true); // ignore the header
		beanReader.configureBeanMapping(SurveyResponse.class, fieldMapping, hintTypes);
		
		SurveyResponse surveyResponse;
		while( (surveyResponse = beanReader.read(SurveyResponse.class, processors)) != null ) {
			System.out.println(String.format("lineNo=%s, rowNo=%s, surveyResponse=%s", beanReader.getLineNumber(),
				beanReader.getRowNumber(), surveyResponse));
		}
		
	}
	finally {
		if( beanReader != null ) {
			beanReader.close();
		}
	}
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:51,代码来源:Reading.java


注:本文中的org.supercsv.cellprocessor.CellProcessorAdaptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。