@Test public void testToList() throws Throwable { String aStringArray = "1, 2, 3, 4"; List<Number> received = ConverterNumberList.toList( aStringArray, "," ); Assert.assertNotNull( received ); Assert.assertEquals( 4, received.size() ); }
public static List<Number> toList( String aStringArray, String aDelimiter ) throws SdiException { List<Number> result = new ArrayList<Number>(); if ( !StringUtils.hasText( aStringArray ) ) { return result; } String[] items = aStringArray.trim().split( aDelimiter ); for ( String item : items ) { try { result.add( Long.parseLong( item.trim() ) ); } catch ( NumberFormatException t ) { throw new SdiException( "Item " + item + " cannot be converted to number", t, SdiException.EXIT_CODE_PARSE_ERROR ); } } return result; }
ConverterNumberList implements FieldConverter<List<Number>> { public static List<Number> toList( String aStringArray, String aDelimiter ) throws SdiException { List<Number> result = new ArrayList<Number>(); if ( !StringUtils.hasText( aStringArray ) ) { return result; } String[] items = aStringArray.trim().split( aDelimiter ); for ( String item : items ) { try { result.add( Long.parseLong( item.trim() ) ); } catch ( NumberFormatException t ) { throw new SdiException( "Item " + item + " cannot be converted to number", t, SdiException.EXIT_CODE_PARSE_ERROR ); } } return result; } }
ConverterNumberList implements FieldConverter<List<Number>> { public static List<Number> toList( String aStringArray, String aDelimiter ) throws SdiException { List<Number> result = new ArrayList<Number>(); if ( !StringUtils.hasText( aStringArray ) ) { return result; } String[] items = aStringArray.trim().split( aDelimiter ); for ( String item : items ) { try { result.add( Long.parseLong( item.trim() ) ); } catch ( NumberFormatException t ) { throw new SdiException( "Item " + item + " cannot be converted to number", t, SdiException.EXIT_CODE_PARSE_ERROR ); } } return result; }  }
ConverterNumberList implements FieldConverter<List<Number>> { public static List<Number> toList( String aStringArray, String aDelimiter ) throws SdiException { List<Number> result = new ArrayList<Number>(); if ( !StringUtils.hasText( aStringArray ) ) { return result; } String[] items = aStringArray.trim().split( aDelimiter ); for ( String item : items ) { try { result.add( Long.parseLong( item.trim() ) ); } catch ( NumberFormatException t ) { throw new SdiException( "Item " + item + " cannot be converted to number", t, SdiException.EXIT_CODE_PARSE_ERROR ); } } return result; }  @Override FieldConverter<List<Number>> init( Environment aEnv, String aFieldname ); @Override List<Number> convert( String aValue ); static List<Long> toLongList( String aStringArray,
                                         String aDelimiter ); static List<Number> toList( String aStringArray, String aDelimiter ); String getDelimiter(); void setDelimiter( String aDelimiter ); }
ConverterNumberList implements FieldConverter<List<Number>> { public static List<Number> toList( String aStringArray, String aDelimiter ) throws SdiException { List<Number> result = new ArrayList<Number>(); if ( !StringUtils.hasText( aStringArray ) ) { return result; } String[] items = aStringArray.trim().split( aDelimiter ); for ( String item : items ) { try { result.add( Long.parseLong( item.trim() ) ); } catch ( NumberFormatException t ) { throw new SdiException( "Item " + item + " cannot be converted to number", t, SdiException.EXIT_CODE_PARSE_ERROR ); } } return result; }  @Override FieldConverter<List<Number>> init( Environment aEnv, String aFieldname ); @Override List<Number> convert( String aValue ); static List<Long> toLongList( String aStringArray,
                                         String aDelimiter ); static List<Number> toList( String aStringArray, String aDelimiter ); String getDelimiter(); void setDelimiter( String aDelimiter ); static final String CONVERTER_NAME; static final String DELIMITER_SUFFIX; }