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


Java CsvField类代码示例

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


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

示例1: calculateHeaders

import net.sf.jsefa.csv.annotation.CsvField; //导入依赖的package包/类
private void calculateHeaders(Class<?> type, SortedMap<Integer, SortedMap<Integer, String>> allHeaders, int index) {

        if (type.getSuperclass() != Object.class) {
            // decrement index for inheritance, because index will be the same
            // but if we have another object within OR the same positions specified in the @CsvField annotation
            // we override the values
            calculateHeaders(type.getSuperclass(), allHeaders, index - 1);
        }

        SortedMap<Integer, String> typeHeaders = new TreeMap<Integer, String>();

        for (Field field : type.getDeclaredFields()) {

            CsvField fieldAnnotation = field.getAnnotation(CsvField.class);
            if (fieldAnnotation == null) {
                continue;
            }

            if (field.getType().getAnnotation(CsvDataType.class) != null) {
                calculateHeaders(field.getType(), allHeaders, fieldAnnotation.pos());
            } else {

                String header = null;

                Header headerAnnotation = field.getAnnotation(Header.class);
                if (headerAnnotation != null) {
                    header = headerAnnotation.value();
                }

                // use field.getName() as default
                if (header == null || header.isEmpty()) {
                    header = field.getName();
                }

                String previousField = typeHeaders.put(fieldAnnotation.pos(), header);
                if (previousField != null) {
                    throw new IllegalArgumentException(String.format("multiple fields for position %d defined! Fields: %s! Type: %s", fieldAnnotation.pos(),
                                                                                                                                      previousField + ", " + field.getName(),
                                                                                                                                      type.getName()));
                }
            }
        }

        allHeaders.put(index, typeHeaders);
    }
 
开发者ID:apache,项目名称:incubator-batchee,代码行数:46,代码来源:JSefaCsvMapping.java

示例2: getValues

import net.sf.jsefa.csv.annotation.CsvField; //导入依赖的package包/类
private static SortedMap<Integer, String> getValues(Object object, Class<?> clazz, SortedMap<Integer, String> values) {

        if (clazz.getSuperclass() != Object.class) {
            values = getValues(object, clazz.getSuperclass(), values);
        }

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            CsvField annotation = field.getAnnotation(CsvField.class);
            if (annotation == null) {
                continue;
            }

            try {
                field.setAccessible(true);
                Object value = field.get(object);

                if (value != null) {

                    String valuetoPut;
                    if (value.getClass().getAnnotation(CsvDataType.class) != null) {
                        valuetoPut = toCsv(value, true);
                    }
                    else {
                        valuetoPut = value.toString();
                    }

                    values.put(annotation.pos(), valuetoPut);
                }
            }
            catch (IllegalAccessException e) {
                Assert.fail("Cannot read from field " + field.getName(), e);
            }
        }

        return values;
    }
 
开发者ID:apache,项目名称:incubator-batchee,代码行数:38,代码来源:CsvUtil.java


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