@Override protected boolean extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { value = safeCastLongToByte( extractLong( data, offset, length ) ); return true; }
@Override protected void extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { int numberOfValues = numberOfValues( data, offset, length ); value = numberOfValues > 0 ? new byte[numberOfValues] : EMPTY; for ( int arrayIndex = 0, charIndex = 0; arrayIndex < numberOfValues; arrayIndex++, charIndex++ ) { int numberOfChars = charsToNextDelimiter( data, offset + charIndex, length - charIndex ); value[arrayIndex] = safeCastLongToByte( extractLong( data, offset + charIndex, numberOfChars ) ); charIndex += numberOfChars; } } }
@Test void castLongToByte() { assertEquals(1, safeCastLongToByte( 1L )); assertEquals(10, safeCastLongToByte( 10L )); assertEquals(-1, safeCastLongToByte( -1L )); assertEquals(Byte.MAX_VALUE, safeCastLongToByte( Byte.MAX_VALUE )); assertEquals(Byte.MIN_VALUE, safeCastLongToByte( Byte.MIN_VALUE )); }
@Test void failSafeCastLongToByte() { expectedException.expect( ArithmeticException.class ); expectedException.expectMessage( "Value 128 is too big to be represented as byte" ); safeCastLongToByte( Byte.MAX_VALUE + 1 ); }
@Override protected boolean extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { value = safeCastLongToByte( extractLong( data, offset, length ) ); return true; }
@Override protected void extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { int numberOfValues = numberOfValues( data, offset, length ); value = numberOfValues > 0 ? new byte[numberOfValues] : EMPTY; for ( int arrayIndex = 0, charIndex = 0; arrayIndex < numberOfValues; arrayIndex++, charIndex++ ) { int numberOfChars = charsToNextDelimiter( data, offset + charIndex, length - charIndex ); value[arrayIndex] = safeCastLongToByte( extractLong( data, offset + charIndex, numberOfChars ) ); charIndex += numberOfChars; } } }