This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trans_id | account_id | date | type | operation | amount | balance | k_symbol | bank | account | ||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 732635 | 2504 | 1993-12-09 | CREDIT | CASH CR | 30 | 30 | NA | |||
| 2 | 732647 | 2504 | 1993-12-14 | CREDIT | CASH CR | 3506.4 | 3536.4 | NA | |||
| 3 | 3613037 | 2504 | 1993-12-31 | CREDIT | 8.56 | 3544.96 | UROK | NA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| @StepScope | |
| FlatFileItemReader<BankTransaction> transactionFileReader(@Value("#{jobParameters['filename']}") String filename) { | |
| //The properties we want to map to the BankTransaction bean in the order they appear in the file | |
| //columns that we do not wish to map are marked with X | |
| String[] properties = new String[] {"X", "transactionId", "accountId", "date", "type", "X", "amount"}; | |
| //The LineTokenizer describes how to parse a line into tokens | |
| DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer(); | |
| lineTokenizer.setDelimiter(","); | |
| //The fields (columns) of the file to include. In this case same as the length of the properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| JobParametersBuilder builder = new JobParametersBuilder(); | |
| JobParameters parameters = builder | |
| .addString("scriptFilename", "create_transaction_table.sql") | |
| .addLong("currentTime", System.currentTimeMillis()) | |
| .toJobParameters(); | |
| JobExecution execution = jobLauncher.run(executeScriptJob, parameters); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| @StepScope | |
| FlatFileItemReader<BankTransaction> | |
| transactionFileReader(@Value("#{jobParameters['filename']}") String filename) { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class ExecuteScriptTasklet implements Tasklet { | |
| @Override | |
| public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { | |
| String scriptFilename = chunkContext.getStepContext().getStepExecution() | |
| .getJobParameters().getString("scriptFilename"); | |
| if (scriptFilename == null) { | |
| throw new IOException("Parameter 'scriptFilename' is not defined."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| JobParametersBuilder builder = new JobParametersBuilder(); | |
| JobParameters parameters = builder | |
| .addString("scriptFilename", "create_transaction_table.sql") | |
| .toJobParameters(); | |
| JobExecution execution = jobLauncher.run(executeScriptJob, parameters); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| Step executeScriptStep() { | |
| return stepBuilderFactory.get("executeScriptTasklet") | |
| .tasklet(executeScriptTasklet) | |
| .build(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class ExecuteScriptTasklet implements Tasklet { | |
| @Override | |
| public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { | |
| ... | |
| return RepeatStatus.FINISHED; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun divide(dividend: ComplexPolynomial, | |
| divisor: ComplexPolynomial): Pair<ComplexPolynomial, ComplexPolynomial> { | |
| var quotient = ComplexPolynomial.ZERO | |
| var remainder = dividend | |
| val divisorDegree = divisor.degree | |
| var remainderDegree = remainder.degree | |
| while (!isZero(remainder) && remainderDegree >= divisorDegree) { | |
| val c = remainder[remainderDegree] / divisor[divisorDegree] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ComplexPolynomial(vararg coefficients: Complex) { | |
| private val coefficients = create(arrayOf(*coefficients)) | |
| //discard leading zero coefficients from the right | |
| private fun create(coeff: Array<Complex>): Array<Complex> { | |
| var n = coeff.size | |
| while ((n > 1) && coeff[n - 1].isZero(TOLERANCE)) --n | |
| return coeff.sliceArray(IntRange(0, n - 1)) | |
| } |