Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Jul 13, 2016
1 parent 704469b commit b52b206
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.DOTALL;
import static java.util.regex.Pattern.*;

/**
* Created by qoomon on 07/07/16.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SubMessageParserException(String message, int lineNumber) {
}

public SubMessageParserException(String message, int lineNumber, Throwable cause) {
super(message + " at line number " + lineNumber , cause);
super(message + " at line number " + lineNumber, cause);
this.lineNumber = lineNumber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,60 +84,60 @@ public static StatementLine of(GeneralField field) throws ParseException {

Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_61), "unexpected field tag '%s'", field.getTag());

List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

LocalDate valueDate = LocalDate.parse(subFields.get(0), VALUE_DATE_FORMATTER);
LocalDate entryDate = null;
// calculate entry date
if (subFields.get(1) != null) {
MonthDay entryMonthDay = MonthDay.parse(subFields.get(1), ENTRY_DATE_FORMATTER);
// calculate entry year
int entryYear = entryMonthDay.getMonthValue() >= valueDate.getMonthValue()
? valueDate.getYear()
: valueDate.getYear() + 1;
entryDate = entryMonthDay.atYear(entryYear);
}
DebitCreditMark debitCreditMark;
String foundsCode;
//// due to ambiguous format notation fo field 3 & 4 (2a[1!a]) it need some extra logic
// if field 3 starts with 'R' it is a two letter mark 'RC' or 'RD' and everything is fine
if (subFields.get(2).startsWith("R")) {
debitCreditMark = DebitCreditMark.of(subFields.get(2));
foundsCode = subFields.get(3);
}
// if field 3 does not start with 'R' it is a one letter mark 'C' or 'D'
// in this case optional field 4 can be part of field 3
else {

String firstLetterOfField3 = subFields.get(2).substring(0, 1);
String secondLetterOfField3 = subFields.get(2).length() > 1 ? subFields.get(2).substring(1, 2) : null;

debitCreditMark = DebitCreditMark.of(firstLetterOfField3);
foundsCode = secondLetterOfField3;

// ensure field 4 is not set also
if (subFields.get(3) != null) {
throw new ParseException("Field " + FIELD_TAG_61 + ": Founds Code already set", 0);
}

List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

LocalDate valueDate = LocalDate.parse(subFields.get(0), VALUE_DATE_FORMATTER);
LocalDate entryDate = null;
// calculate entry date
if (subFields.get(1) != null) {
MonthDay entryMonthDay = MonthDay.parse(subFields.get(1), ENTRY_DATE_FORMATTER);
// calculate entry year
int entryYear = entryMonthDay.getMonthValue() >= valueDate.getMonthValue()
? valueDate.getYear()
: valueDate.getYear() + 1;
entryDate = entryMonthDay.atYear(entryYear);
}
DebitCreditMark debitCreditMark;
String foundsCode;
//// due to ambiguous format notation fo field 3 & 4 (2a[1!a]) it need some extra logic
// if field 3 starts with 'R' it is a two letter mark 'RC' or 'RD' and everything is fine
if (subFields.get(2).startsWith("R")) {
debitCreditMark = DebitCreditMark.of(subFields.get(2));
foundsCode = subFields.get(3);
}
// if field 3 does not start with 'R' it is a one letter mark 'C' or 'D'
// in this case optional field 4 can be part of field 3
else {

String firstLetterOfField3 = subFields.get(2).substring(0, 1);
String secondLetterOfField3 = subFields.get(2).length() > 1 ? subFields.get(2).substring(1, 2) : null;

debitCreditMark = DebitCreditMark.of(firstLetterOfField3);
foundsCode = secondLetterOfField3;

// ensure field 4 is not set also
if (subFields.get(3) != null) {
throw new ParseException("Field " + FIELD_TAG_61 + ": Founds Code already set", 0);
}

BigDecimal amount = new BigDecimal(subFields.get(4).replaceFirst(",", "."));
TransactionTypeIdentificationCode transactionTypeIdentificationCode = TransactionTypeIdentificationCode.of(subFields.get(5) + subFields.get(6));
String referenceForAccountOwner = subFields.get(7);
String referenceForBank = subFields.get(8);
String supplementaryDetails = subFields.get(9);

return new StatementLine(
valueDate,
entryDate,
debitCreditMark,
foundsCode,
amount,
transactionTypeIdentificationCode,
referenceForAccountOwner,
referenceForBank,
supplementaryDetails);
}

BigDecimal amount = new BigDecimal(subFields.get(4).replaceFirst(",", "."));
TransactionTypeIdentificationCode transactionTypeIdentificationCode = TransactionTypeIdentificationCode.of(subFields.get(5) + subFields.get(6));
String referenceForAccountOwner = subFields.get(7);
String referenceForBank = subFields.get(8);
String supplementaryDetails = subFields.get(9);

return new StatementLine(
valueDate,
entryDate,
debitCreditMark,
foundsCode,
amount,
transactionTypeIdentificationCode,
referenceForAccountOwner,
referenceForBank,
supplementaryDetails);
}

public LocalDate getValueDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public GeneralField readField() throws FieldParseException {

ensureValidNextLine(nextFieldLine, nextValidFieldLineTypeSet, lineReader);

currentFieldLine = nextFieldLine;
currentFieldLine = nextFieldLine;
currentLineNumber = lineReader.getLineNumber();
nextFieldLine = readFieldLine(lineReader);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.qoomon.banking.swift.message.submessage.field.notation;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;

import java.text.ParseException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.quote;
import static java.util.regex.Pattern.*;

/**
* <pre>
Expand Down Expand Up @@ -47,6 +46,7 @@ public class SwiftFieldNotation {
private static final String SEPARATOR_SET = "(?:/|//|BR|ISIN)";

private static final Map<String, String> CHARSET_REGEX_MAP = new HashMap<String, String>();

static {
// see class description for charset details
CHARSET_REGEX_MAP.put("a", "[A-Z]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public SwiftMT940 readMessage() throws FieldParseException {
}

// finish message
if ( MESSAGE_END_FIELD_TAG_SET.contains(currentField.getTag())) {
if (MESSAGE_END_FIELD_TAG_SET.contains(currentField.getTag())) {
message = new SwiftMT940(
transactionReferenceNumber,
relatedReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public SwiftMT942 readMessage() throws FieldParseException {
}

// finish message
if ( MESSAGE_END_FIELD_TAG_SET.contains(currentField.getTag())) {
if (MESSAGE_END_FIELD_TAG_SET.contains(currentField.getTag())) {
message = new SwiftMT942(
transactionReferenceNumber,
relatedReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.junit.Test;

import java.io.StringReader;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;

import static org.assertj.core.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import com.google.common.base.Throwables;
import com.google.common.io.Resources;
import com.qoomon.banking.swift.TestUtils;
import com.qoomon.banking.swift.message.submessage.mt940.SwiftMT940;
import com.qoomon.banking.swift.message.submessage.mt940.SwiftMT940Reader;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;

import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.nio.file.Files;
Expand Down

0 comments on commit b52b206

Please sign in to comment.