@Override public FieldSet tokenize(String line) { return tokenizers.match(line).tokenize(line); }
@Override public T mapLine(String line, int lineNumber) throws Exception { return fieldSetMapper.mapFieldSet(tokenizer.tokenize(line)); }
@Override public FieldSet tokenize(String line) { if(line.charAt(0) == 'F'){ //line starts with F, so the footer tokenizer should tokenize it. FieldSet fs = footerTokenizer.tokenize(line); long customerUpdateTotal = stepExecution.getReadCount(); long fileUpdateTotal = fs.readLong(1); if(customerUpdateTotal != fileUpdateTotal){ throw new IllegalStateException("The total number of customer updates in the file footer does not match the " + "number entered File footer total: [" + fileUpdateTotal + "] Total encountered during processing: [" + customerUpdateTotal + "]"); } else{ //return null, because the footer indicates an end of processing. return null; } } else if(line.charAt(0) == 'A' || line.charAt(0) == 'U' || line.charAt(0) == 'D'){ //line starts with A,U, or D, so it must be a customer operation. return customerTokenizer.tokenize(line); } else{ //If the line doesn't start with any of the characters above, it must obviously be invalid. throw new IllegalArgumentException("Invalid line encountered for tokenizing: " + line); } }
@Test public void testMapping() throws Exception { final String line = "TEST"; final FieldSet fs = new DefaultFieldSet(new String[]{"token1", "token2"}); final String item = "ITEM"; LineTokenizer tokenizer = mock(LineTokenizer.class); when(tokenizer.tokenize(line)).thenReturn(fs); @SuppressWarnings("unchecked") FieldSetMapper<String> fsMapper = mock(FieldSetMapper.class); when(fsMapper.mapFieldSet(fs)).thenReturn(item); tested.setLineTokenizer(tokenizer); tested.setFieldSetMapper(fsMapper); assertSame(item, tested.mapLine(line, 1)); }
@Override public T mapLine(String line, int lineNumber) throws Exception { return fieldSetMapper.mapFieldSet(tokenizer.tokenize(line)); }
@Override public FieldSet tokenize(String line) { return tokenizers.match(line).tokenize(line); }