Skip to content

Commit

Permalink
Noch zu PR #142 - wenn die Methode nur noch mit "true" bei "leadingSvwz"
Browse files Browse the repository at this point in the history
aufgerufen wird, kann der Parameter auch ganz entfallen.
  • Loading branch information
willuhn committed Jul 9, 2024
1 parent 4b377bd commit 771ad5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/de/willuhn/jameica/hbci/server/VerwendungszweckUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,29 @@ public static Map<Tag,String> parse(Transfer t) throws RemoteException
public static Map<Tag,String> parse(String... lines) throws RemoteException
{
// Wir parsen erstmal alles mit "+".
Map<Tag,String> result = parse(true,'+',lines);
Map<Tag,String> result = parse('+',lines);
if (result == null || result.size() == 0)
{
// Vielleicht enthaelt es ja nur Tags mit Doppelpunkt?
return parse(true,':',lines);
return parse(':',lines);
}

// Jetzt schauen wir, ob wir den Verwendungszweck per ":" noch weiter zerlegen koennen
String svwz = result.get(Tag.SVWZ);
if (StringUtils.trimToNull(svwz) != null)
result.putAll(parse(true,':',svwz));
result.putAll(parse(':',svwz));

return result;
}

/**
* Parst die SEPA-Tags aus den Verwendungszweck-Zeilen.
* @param leadingSvwz true, wenn ein fuehrerender Verwendungszweck ohne dediziertes Tag beachtet werden soll.
* @param sep das zu verwendende Trennzeichen.
* @param lines die Verwendungszweck-Zeilen.
* @return Map mit den geparsten Infos. Niemals NULL sondern hoechstens eine leere Map.
* @throws RemoteException
*/
private static Map<Tag,String> parse(boolean leadingSvwz, char sep, String... lines) throws RemoteException
private static Map<Tag,String> parse(char sep, String... lines) throws RemoteException
{
Map<Tag,String> result = new HashMap<Tag,String>();

Expand Down Expand Up @@ -298,7 +297,7 @@ private static Map<Tag,String> parse(boolean leadingSvwz, char sep, String... li
// Sprich: Der Verwendungszweck enthaelt zwar Tags, der Verwendungszweck selbst hat aber keines
// sondern steht nur vorn dran.
// Wenn wir Tags haben, SVWZ aber fehlt, nehmen wir als SVWZ den Text bis zum ersten Tag
if (leadingSvwz && result.size() > 0 && !result.containsKey(Tag.SVWZ) && first > 0)
if (result.size() > 0 && !result.containsKey(Tag.SVWZ) && first > 0)
{
result.put(Tag.SVWZ,StringUtils.trimToEmpty(line.substring(0,first).replace("\n","")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void testRewrap() throws Exception
String[] result = VerwendungszweckUtil.rewrap(27,test);

assertArrayEquals(new String[]{"123456789012345678901234567",
"890123456789012345678901234",
"567890d12345678901234567890",
"1234567"},
"890123456789012345678901234",
"567890d12345678901234567890",
"1234567"},
result);
}

Expand Down

0 comments on commit 771ad5e

Please sign in to comment.