Skip to content

Instantly share code, notes, and snippets.

View algorythmist's full-sized avatar

Dimitri Papaioannou algorythmist

View GitHub Profile
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
@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
JobParametersBuilder builder = new JobParametersBuilder();
JobParameters parameters = builder
.addString("scriptFilename", "create_transaction_table.sql")
.addLong("currentTime", System.currentTimeMillis())
.toJobParameters();
JobExecution execution = jobLauncher.run(executeScriptJob, parameters);
@Bean
@StepScope
FlatFileItemReader<BankTransaction>
transactionFileReader(@Value("#{jobParameters['filename']}") String filename) {
...
}
@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.");
}
JobParametersBuilder builder = new JobParametersBuilder();
JobParameters parameters = builder
.addString("scriptFilename", "create_transaction_table.sql")
.toJobParameters();
JobExecution execution = jobLauncher.run(executeScriptJob, parameters);
@Bean
Step executeScriptStep() {
return stepBuilderFactory.get("executeScriptTasklet")
.tasklet(executeScriptTasklet)
.build();
}
@Component
public class ExecuteScriptTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
...
return RepeatStatus.FINISHED;
}
}
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]
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))
}