本文整理汇总了Java中org.supercsv.exception.SuperCsvCellProcessorException类的典型用法代码示例。如果您正苦于以下问题:Java SuperCsvCellProcessorException类的具体用法?Java SuperCsvCellProcessorException怎么用?Java SuperCsvCellProcessorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SuperCsvCellProcessorException类属于org.supercsv.exception包,在下文中一共展示了SuperCsvCellProcessorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
@Override
public Object execute(Object value, CsvContext context) {
validateInputNotNull(value, context);
try {
DateTimeFormatter pattern = DateTimeFormat
.forPattern(DETAILED_CSV_DATE_FORMAT_YYYY_MM_DD_HH_MM_SS);
LocalDateTime localDate = new LocalDateTime(
pattern.parseLocalDateTime(value.toString()));
return next.execute(localDate, context);
} catch (IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(
String.format("Could not parse '%s' as a LocalDateTime", value), context,
this);
}
}
示例2: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
@Override
/**
* The airports codes contained in the csv can be IATA ( 3-letter) codes or ICAO (4-letter) codes.
*/
public Object execute(Object value, CsvContext context) {
validateInputNotNull(value, context);
String airportCode = (String) value;
if ((airportCode.length() == AIRPORT_IATACODE_LENGTH)) {
return next.execute(value, context);
}
// attempt to convert the icao code to an IATA code. If not possible proceed with the code as it is.
if (airportCode.length() == AIRPORT_ICAOCODE_LENGTH) {
List<Airport> airports = airportBusinessService.findAirportByIcaoCode(airportCode);
if (!airports.isEmpty()) {
return next.execute(airports.get(0)
.getIataCode(), context);
} else {
return next.execute(airportCode, context);
}
}
throw new SuperCsvCellProcessorException(
String.format("Could not parse '%s' neither as an IATA nor as an IACAO code for Airports", value),
context, this);
}
示例3: deserializeThrowsExceptionWhenInvalidAirportCodeLength
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
@Test
public void deserializeThrowsExceptionWhenInvalidAirportCodeLength() throws IOException {
//Given
final String invalidAirportCode = "invalid airport code";
boolean thrown = false;
FlightConnection flightConnection = getDefaultConnection();
flightConnection.setSourceAirportIataCode(invalidAirportCode);
List<FlightConnection> flightConnections = new ArrayList<>();
flightConnections.add(flightConnection);
String csvContent = cut.createCsvContentForConnections(flightConnections);
InputStream inputStream = new ByteArrayInputStream(csvContent.getBytes(charset));
//When
try {
cut.deserialize(inputStream);
} catch (SuperCsvCellProcessorException e) {
//Then: ensure that the proper cell processor what activated to reject the invalid airport code
thrown = true;
assertThat(e.getMessage()).containsIgnoringCase(invalidAirportCode);
}
assertThat(thrown).isTrue();
}
示例4: deserializeThrowsExceptionWhenInvalidAirlineCodeLength
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
@Test
public void deserializeThrowsExceptionWhenInvalidAirlineCodeLength() throws IOException {
//Given
final String invalidAirlineCode = "invalid airline code";
boolean thrown = false;
FlightConnection flightConnection = getDefaultConnection();
flightConnection.setDestinationAirportIataCode(invalidAirlineCode);
List<FlightConnection> flightConnections = new ArrayList<>();
flightConnections.add(flightConnection);
String csvContent = cut.createCsvContentForConnections(flightConnections);
InputStream inputStream = new ByteArrayInputStream(csvContent.getBytes(charset));
//When
try {
cut.deserialize(inputStream);
} catch (SuperCsvCellProcessorException e) {
//Then: ensure that the proper cell processor what activated to reject the invalid airline code
thrown = true;
assertThat(e.getMessage()).containsIgnoringCase(invalidAirlineCode);
}
assertThat(thrown).isTrue();
}
示例5: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
public Object execute(Object value, CsvContext context) {
validateInputNotNull(value, context);
if(!(value instanceof String)) {
throw new SuperCsvCellProcessorException(String.class, value, context, this);
}
String numString = (String)value;
int number = Integer.parseInt(numString);
Team team = new Select().from(Team.class).where(Team.TEAM_NUMBER+"=?",number).executeSingle();
if(null==team) {
team = new Team();
team.setTeamNumber(number);
team.save();
}
return next.execute(team,context);
}
示例6: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null, isn't a Character or String, or is a String of multiple characters
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
final Character result;
if( value instanceof Character ) {
result = (Character) value;
} else if( value instanceof String ) {
final String stringValue = (String) value;
if( stringValue.length() == 1 ) {
result = Character.valueOf(stringValue.charAt(0));
} else {
throw new SuperCsvCellProcessorException(String.format(
"'%s' cannot be parsed as a char as it is a String longer than 1 character", stringValue), context,
this);
}
} else {
final String actualClassName = value.getClass().getName();
throw new SuperCsvCellProcessorException(String.format(
"the input value should be of type Character or String but is of type %s", actualClassName), context,
this);
}
return next.execute(result, context);
}
示例7: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException if value is null or is not a String
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if( !(value instanceof String) ) {
throw new SuperCsvCellProcessorException(String.class, value, context, this);
}
final String string = (String) value;
final T result;
try {
if( formatter != null ) {
result = parse(string, formatter);
} else {
result = parse(string);
}
}
catch(DateTimeParseException e) {
throw new SuperCsvCellProcessorException("Failed to parse value", context, this, e);
}
return next.execute(result, context);
}
示例8: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException if value is null, not the correct type, or can't be formatted
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
final Class<T> ourType = getType();
if( !(value.getClass().equals(ourType)) ) {
throw new SuperCsvCellProcessorException(ourType, value, context, this);
}
final TemporalAccessor timeType = ourType.cast(value);
try {
if( formatter != null ) {
return formatter.format(timeType);
} else {
return timeType.toString();
}
}
catch(DateTimeException | IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(
String.format("Failed to format value as a %s", ourType.getSimpleName()), context, this, e);
}
}
示例9: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException if value is null or is not a String
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if( !(value instanceof String) ) {
throw new SuperCsvCellProcessorException(String.class, value, context, this);
}
final ZoneId result;
try {
if( aliasMap != null ) {
result = ZoneId.of((String) value, aliasMap);
} else {
result = ZoneId.of((String) value);
}
}
catch(DateTimeException e) {
throw new SuperCsvCellProcessorException("Failed to parse value as a ZoneId", context, this, e);
}
return next.execute(result, context);
}
示例10: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null or not a Number, or if an invalid decimalFormat String was supplied
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if( !(value instanceof Number) ) {
throw new SuperCsvCellProcessorException(Number.class, value, context, this);
}
// create a new DecimalFormat if one is not supplied
final DecimalFormat decimalFormatter;
try {
decimalFormatter = formatter != null ? formatter : new DecimalFormat(decimalFormat);
}
catch(IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(
String.format("'%s' is not a valid decimal format", decimalFormat), context, this, e);
}
final String result = decimalFormatter.format(value);
return next.execute(result, context);
}
示例11: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null, not a String, or can't be parsed to a Boolean
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if( !(value instanceof String) ) {
throw new SuperCsvCellProcessorException(String.class, value, context, this);
}
final String stringValue = (String) value;
final Boolean result;
if( contains(trueValues, stringValue, ignoreCase) ) {
result = Boolean.TRUE;
} else if( contains(falseValues, stringValue, ignoreCase) ) {
result = Boolean.FALSE;
} else {
throw new SuperCsvCellProcessorException(String.format("'%s' could not be parsed as a Boolean", value),
context, this);
}
return next.execute(result, context);
}
示例12: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null, isn't a Double or String, or can't be parsed as a Double
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
final Double result;
if( value instanceof Double ) {
result = (Double) value;
} else if( value instanceof String ) {
try {
result = new Double((String) value);
}
catch(final NumberFormatException e) {
throw new SuperCsvCellProcessorException(String.format("'%s' could not be parsed as a Double", value),
context, this, e);
}
} else {
final String actualClassName = value.getClass().getName();
throw new SuperCsvCellProcessorException(String.format(
"the input value should be of type Double or String but is of type %s", actualClassName), context, this);
}
return next.execute(result, context);
}
示例13: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null or is not a Date, or if dateFormat is not a valid date format
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if( !(value instanceof Date) ) {
throw new SuperCsvCellProcessorException(Date.class, value, context, this);
}
final SimpleDateFormat formatter;
try {
formatter = new SimpleDateFormat(dateFormat);
}
catch(IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(String.format("'%s' is not a valid date format", dateFormat),
context, this, e);
}
String result = formatter.format((Date) value);
return next.execute(result, context);
}
示例14: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null or is not a String
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if (!(value instanceof String)) {
throw new SuperCsvCellProcessorException(String.class, value,
context, this);
}
final DateTimeZone result;
try {
result = DateTimeZone.forID((String) value);
} catch (IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(
"Failed to parse value as a DateTimeZone", context, this, e);
}
return next.execute(result, context);
}
示例15: execute
import org.supercsv.exception.SuperCsvCellProcessorException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null or can't be parsed as an Enum
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
final String inputString = value.toString();
for( final Enum<?> enumConstant : enumClass.getEnumConstants() ) {
String constantName = enumConstant.name();
if( ignoreCase ? constantName.equalsIgnoreCase(inputString) : constantName.equals(inputString) ) {
return enumConstant;
}
}
throw new SuperCsvCellProcessorException(String.format("'%s' could not be parsed as a enum of type %s", value,
enumClass.getName()), context, this);
}