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


Java ParsingContext类代码示例

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


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

示例1: testCustomReaderFactory

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testCustomReaderFactory() throws IOException {
    CsvMapper<DbObject> mapper = CsvMapperFactory.newInstance().failOnAsm(true).cellValueReaderFactory(new CellValueReaderFactory() {
        @Override
        public <P> CellValueReader<P> getReader(Type propertyType, int index, CsvColumnDefinition columnDefinition, ParsingContextFactoryBuilder builder) {
            return new CellValueReader<P>() {
                @SuppressWarnings("unchecked")
                @Override
                public P read(char[] chars, int offset, int length, ParsingContext parsingContext) {
                    return (P) "Hello!";
                }
            };
        }
    }).newBuilder(DbObject.class).addMapping("name").mapper();

    DbObject bop = mapper.iterator(new StringReader("bop")).next();

    assertEquals("Hello!", bop.getName());


}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:22,代码来源:CsvMapperCustomReaderFactoryTest.java

示例2: testDSLMapWithCustomDefinitionOnStaticMapper

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testDSLMapWithCustomDefinitionOnStaticMapper() throws  Exception {
	Iterator<Tuple2<String, String>> iterator = CsvParser.mapTo(String.class, String.class)
			.addMapping("0")
			.addMapping("1", CsvColumnDefinition.customReaderDefinition(new CellValueReader<String>() {
				@Override
				public String read(char[] chars, int offset, int length, ParsingContext parsingContext) {
					return "c1";
				}
			})).iterator(new StringReader("0,1\nv0,v1"));

	Tuple2<String, String> tuple = iterator.next();

	assertEquals("v0", tuple.first());
	assertEquals("c1", tuple.second());
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:17,代码来源:CsvParserTest.java

示例3: testMapDbObjectWithCustomReader

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testMapDbObjectWithCustomReader() throws Exception {
    CsvMapperBuilder<Db1DeepObject> builder = new CsvMapperBuilder<Db1DeepObject>(Db1DeepObject.class,  ReflectionService.newInstance(false));
    CsvColumnDefinition columnDefinition = CsvColumnDefinition.customReaderDefinition(new CellValueReader<String>() {
        @Override
        public String read(char[] chars, int offset, int length, ParsingContext parsingContext) {
            return "cv1";
        }
    });
    builder.addMapping("db_Object_name", columnDefinition);

    CsvMapper<Db1DeepObject> mapper = builder.mapper();

    Db1DeepObject v1 = mapper.iterator(new StringReader("v1")).next();

    assertEquals("cv1", v1.getDbObject().getName());
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:18,代码来源:CsvMapperBuilderSubObjectTest.java

示例4: testInstantiateStringWithCharArray

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testInstantiateStringWithCharArray() throws Exception {
	HashMap<Parameter, Getter<? super CsvMapperCellHandlerImpl<String>, ?>> injections = new HashMap<Parameter, Getter<? super CsvMapperCellHandlerImpl<String>, ?>>();

	Parameter parameter = new Parameter(0, "arg0", char[].class);
	DelayedGetter delayedGetter = new DelayedGetter(0);
	injections.put(parameter, delayedGetter);

	Class<CsvMapperCellHandlerImpl<String>> source = (Class)CsvMapperCellHandlerImpl.class;
	Instantiator<CsvMapperCellHandlerImpl<String>, String> instantiator =
			factory.createInstantiator(source,
					new ExecutableInstantiatorDefinition(String.class.getConstructor(char[].class), parameter),
					injections, true);
	DelayedCellSetterImpl delayedCellSetter = new DelayedCellSetterImpl(null, new CellValueReader() {
		@Override
		public char[] read(char[] chars, int offset, int length, ParsingContext parsingContext) {
			return new char[]{'h'};
		}
	});
	delayedCellSetter.set(null, 0, 0, null);

       CsvMapperCellHandlerImpl targetSettersImpl = new CsvMapperCellHandlerImpl(instantiator, new DelayedCellSetter[]{delayedCellSetter}, new CellSetter[]{}, null, null, null);

	Assert.assertNotNull(instantiator.newInstance(targetSettersImpl));
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:27,代码来源:CsvMapperCellHandlerImpAsmInstantiatorTest.java

示例5: testMapDbObjectCustomReader

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testMapDbObjectCustomReader() throws Exception {
    CsvMapperBuilder<DbObject> builder = csvMapperFactory.addCustomValueReader("id", new CellValueReader<Long>() {

        @Override
        public Long read(char[] chars, int offset, int length,
                         ParsingContext parsingContext) {
            return 0x5677al;
        }
    }).newBuilder(DbObject.class);
    CsvMapperBuilderTest.addDbObjectFields(builder);

    CsvMapper<DbObject> mapper = builder.mapper();
    List<DbObject> list = mapper.forEach(CsvMapperImplTest.dbObjectCsvReader(), new ListCollector<DbObject>()).getList();
    assertEquals(1, list.size());
    assertEquals(0x5677al, list.get(0).getId());
    assertEquals("name 1", list.get(0).getName());
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:19,代码来源:CsvMapperCustomReaderTest.java

示例6: testMapDbFinalObjectCustomReader

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testMapDbFinalObjectCustomReader() throws Exception {
    CsvMapperBuilder<DbFinalObject> builder = csvMapperFactory.addCustomValueReader("id", new CellValueReader<Long>() {

        @Override
        public Long read(char[] chars, int offset, int length,
                         ParsingContext parsingContext) {
            return 0x5677al;
        }
    }).newBuilder(DbFinalObject.class);
    CsvMapperBuilderTest.addDbObjectFields(builder);

    CsvMapper<DbFinalObject> mapper = builder.mapper();
    List<DbFinalObject> list = mapper.forEach(CsvMapperImplTest.dbObjectCsvReader(), new ListCollector<DbFinalObject>()).getList();
    assertEquals(1, list.size());
    assertEquals(0x5677al, list.get(0).getId());
    assertEquals("name 1", list.get(0).getName());
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:19,代码来源:CsvMapperCustomReaderTest.java

示例7: testCustomCsvReaderValueFactory

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Test
public void testCustomCsvReaderValueFactory() throws IOException {
    CsvMapper<Tuple2<String, String>> csvMapper = CsvMapperFactory.newInstance().addColumnDefinition(new Predicate<CsvColumnKey>() {
        @Override
        public boolean test(CsvColumnKey csvColumnKey) {
            return true;
        }
    }, CsvColumnDefinition.customCellValueReaderFactoryDefinition(new CellValueReaderFactory() {

        @SuppressWarnings("unchecked")
        @Override
        public <P> CellValueReader<P> getReader(Type propertyType, final int index, CsvColumnDefinition columnDefinition, ParsingContextFactoryBuilder builder) {
            return (CellValueReader<P>) new CellValueReader<String>() {
                @Override
                public String read(char[] chars, int offset, int length, ParsingContext parsingContext) {
                    return "g" + index;
                }
            };
        }
    })).newMapper(Tuples.typeDef(String.class, String.class));

    Tuple2<String, String> value = csvMapper.iterator(new StringReader("b0,b1\nc0,c1")).next();

    assertEquals("g0", value.first());
    assertEquals("g1", value.second());
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:27,代码来源:CsvMapperCustomReaderTest.java

示例8: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public Double read(char[] chars, int offset, int length, ParsingContext parsingContext) {
	try {
		return NumberFormat.getInstance(Locale.GERMANY).parse(new String(chars, offset, length)).doubleValue();
	} catch (ParseException e) {
		return defaultValue;
	}
}
 
开发者ID:almondtools,项目名称:stringbench,代码行数:9,代码来源:UpdateBenchmarks.java

示例9: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public T read(char[] chars, int offset, int length,
		ParsingContext parsingContext) {
	try {
		return instantiator.newInstance(innerReader.read(chars, offset, length, parsingContext));
	} catch (Exception e) {
           return ErrorHelper.rethrow(e);
	}
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:10,代码来源:InstantiatorOnReader.java

示例10: CsvMapperCellHandlerImpl

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
public CsvMapperCellHandlerImpl(Instantiator<CsvMapperCellHandler<T>, T> instantiator, DelayedCellSetter<T, ?>[] delayedCellSetters,
                                CellSetter<T>[] setters, CsvColumnKey[] columns,
                                ParsingContext parsingContext, FieldMapperErrorHandler<? super CsvColumnKey> fieldErrorHandler) {
    super(instantiator, columns, delayedCellSetters.length, setters.length, parsingContext, fieldErrorHandler);
    this.delayedCellSetters = delayedCellSetters;
    this.setters = setters;
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:8,代码来源:CsvMapperCellHandlerImpl.java

示例11: set

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public void set(T target, char[] chars, int offset, int length, ParsingContext context)
		throws Exception {
	this.handler.newCell(chars, offset, length, cellIndex);
       final BreakDetector breakDetector = handler.getBreakDetector();
       if (setter != null && (breakDetector == null || (breakDetector.broken()&& breakDetector.isNotNull()))) {
           setter.set(target, this.handler.getOrCreateCurrentInstance());
       }
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:10,代码来源:DelegateCellSetter.java

示例12: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public E read(char[] chars, int offset, int length, ParsingContext parsingContext) {
	
	int n = parsePositiveNumber(chars, offset, length);
	if (n >= 0 && n < values.length) {
		return values[n];
	} else {
		return Enum.valueOf(enumClass, stringCellValueReader.read(chars, offset, length, parsingContext));
	}
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:11,代码来源:EnumCellValueReader.java

示例13: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public P read(char[] chars, int offset, int length, ParsingContext parsingContext) {
    try {
        return converter.convert(String.valueOf(chars, offset, length));
    } catch (Exception e) {
        return ErrorHelper.rethrow(e);
    }
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:9,代码来源:CharSequenceConverterCellValueReader.java

示例14: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public Date read(char[] chars, int offset, int length, ParsingContext parsingContext) {
	if (length == 0) return null;

	String str = new String(chars, offset, length);
	DateFormat[] dfs = (DateFormat[]) parsingContext.getContext(index);
	for(int i = dfs.length - 1; i >= 0; i--) {
		try {
			return dfs[i].parse(str);
		} catch (ParseException e) {
			// ignore
		}
	}
	throw new ParsingException("Unable to parse date '" + str + "'");
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:16,代码来源:DateMultiFormatCellValueReader.java

示例15: read

import org.simpleflatmapper.csv.ParsingContext; //导入依赖的package包/类
@Override
public Date read(char[] chars, int offset, int length, ParsingContext parsingContext) {
	if (length == 0) return null;

	String str = new String(chars, offset, length);
	try {
		DateFormat df = (DateFormat) parsingContext.getContext(index);
		return df.parse(str);
	} catch (ParseException e) {
		throw new ParsingException(e.getMessage());
	}
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:13,代码来源:DateCellValueReader.java


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