org.supercsv.cellprocessor.ParseBool Java Examples

The following examples show how to use org.supercsv.cellprocessor.ParseBool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarketLogReader.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
private static CellProcessor[] getProcessors() {
	return new CellProcessor[]{
		new ParseDouble(), // price
		new ParseDouble(), // volRemaining
		new ParseInt(), // typeID
		new ParseInt(), // range
		new ParseLong(), // orderID
		new ParseInt(), // volEntered
		new ParseInt(), // minVolume
		new ParseBool(), // bid
		new ParseDate(), // issueDate
		new ParseInt(), // duration
		new ParseLong(), // stationID
		new ParseLong(), // regionID
		new ParseLong(), // solarSystemID
		new ParseInt(), // jumps
		new Optional()
	};
}
 
Example #2
Source File: Reading.java    From super-csv with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the processors used for the examples. There are 10 CSV columns, so 10 processors are defined. Empty
 * columns are read as null (hence the NotNull() for mandatory columns).
 * 
 * @return the cell processors
 */
private static CellProcessor[] getProcessors() {
	
	final String emailRegex = "[a-z0-9\\._]+@[a-z0-9\\.]+"; // just an example, not very robust!
	StrRegEx.registerMessage(emailRegex, "must be a valid email address");
	
	final CellProcessor[] processors = new CellProcessor[] { new UniqueHashCode(), // customerNo (must be unique)
		new NotNull(), // firstName
		new NotNull(), // lastName
		new ParseDate("dd/MM/yyyy"), // birthDate
		new ParseSqlTime("HH:mm:ss"),
		new NotNull(), // mailingAddress
		new Optional(new ParseBool()), // married
		new Optional(new ParseInt()), // numberOfKids
		new NotNull(), // favouriteQuote
		new StrRegEx(emailRegex), // email
		new LMinMax(0L, LMinMax.MAX_LONG) // loyaltyPoints
	};
	
	return processors;
}
 
Example #3
Source File: SuperCsvBOMTest.java    From super-csv with Apache License 2.0 6 votes vote down vote up
public void ReadTestCSVFile(Reader reader) throws IOException {
	ICsvBeanReader beanReader = new CsvBeanReader(reader, CsvPreference.STANDARD_PREFERENCE);
	final String[] header = beanReader.getHeader(true);
	assertEquals("customerNo", header[0]);
	CustomerBean customer = null;
	final String emailRegex = "[a-z0-9\\._]+@[a-z0-9\\.]+"; // just an example, not very robust!
	StrRegEx.registerMessage(emailRegex, "must be a valid email address");
	final CellProcessor[] processors = new CellProcessor[]{new UniqueHashCode(), // customerNo (must be unique)
			new NotNull(), // firstName
			new NotNull(), // lastName
			new ParseDate("dd/MM/yyyy"), // birthDate
			new ParseSqlTime("HH:mm:ss"), // birthTime
			new NotNull(), // mailingAddress
			new Optional(new ParseBool()), // married
			new Optional(new ParseInt()), // numberOfKids
			new NotNull(), // favouriteQuote
			new StrRegEx(emailRegex), // email
			new LMinMax(0L, LMinMax.MAX_LONG) // loyaltyPoints
	};
	customer = beanReader.read(CustomerBean.class, header, processors);
	assertEquals("1", customer.getCustomerNo());
	assertEquals("John", customer.getFirstName());
	assertEquals("[email protected]", customer.getEmail());
	assertEquals(0, customer.getLoyaltyPoints());
	beanReader.close();
}
 
Example #4
Source File: Reading.java    From super-csv with Apache License 2.0 5 votes vote down vote up
/**
 * An example of reading using CsvDozerBeanReader.
 */
private static void readWithCsvDozerBeanReader() throws Exception {
	
	final CellProcessor[] processors = new CellProcessor[] { 
		new Optional(new ParseInt()), // age
		new ParseBool(),              // consent
		new ParseInt(),               // questionNo 1
		new Optional(),               // answer 1
		new ParseInt(),               // questionNo 2
		new Optional(),               // answer 2
		new ParseInt(),               // questionNo 3
		new Optional()                // answer 3
	};
	
	ICsvDozerBeanReader beanReader = null;
	try {
		beanReader = new CsvDozerBeanReader(new FileReader(CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
		
		beanReader.getHeader(true); // ignore the header
		beanReader.configureBeanMapping(SurveyResponse.class, FIELD_MAPPING);
		
		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();
		}
	}
}
 
Example #5
Source File: Reading.java    From super-csv with Apache License 2.0 5 votes vote down vote up
/**
 * An example of partial reading using CsvDozerBeanReader.
 */
private static void partialReadWithCsvDozerBeanReader() throws Exception {
	
	// ignore age, and question/answer 3
	final String[] partialFieldMapping = new String[] { null, "consentGiven", "answers[0].questionNo",
		"answers[0].answer", "answers[1].questionNo", "answers[1].answer", null, null };
	
	// set processors for ignored columns to null for efficiency (could have used full array if we wanted them to execute anyway)
	final CellProcessor[] processors = new CellProcessor[] { null, new ParseBool(), new ParseInt(), new Optional(),
		new ParseInt(), new Optional(), null, null };
	
	ICsvDozerBeanReader beanReader = null;
	try {
		beanReader = new CsvDozerBeanReader(new FileReader(CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
		
		beanReader.getHeader(true); // ignore the header
		beanReader.configureBeanMapping(SurveyResponse.class, partialFieldMapping);
		
		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();
		}
	}
}