Skip to content

Commit

Permalink
Add ISOMsg.merge(ISOMsg m, boolean mergeHeader) option
Browse files Browse the repository at this point in the history
rolled back change from the previous commit to avoid rocking the boat
with a non backward compatible (@barspi raised a very reasonable
concern).
  • Loading branch information
ar committed Mar 29, 2024
1 parent fbebfee commit dbe1468
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jpos/src/main/java/org/jpos/iso/ISOMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,11 @@ public ISOMsg clone(String ... fpaths) {
*
* @param m The ISOMsg to merge into this ISOMsg. It must not be {@code null}.
* The method does nothing if {@code m} is {@code null}.
* @param mergeHeader A boolean flag indicating whether to merge the header of the input message into this message.
*
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public void merge (ISOMsg m) {
public void merge (ISOMsg m, boolean mergeHeader) {
for (int i : m.fields.keySet()) {
try {
if (i >= 0 && m.hasField(i))
Expand All @@ -860,10 +861,20 @@ public void merge (ISOMsg m) {
// should never happen
}
}
if (m.header != null)
if (mergeHeader && m.header != null)
header = (ISOHeader) m.header.clone();
}

/*
* Merges the content of the specified ISOMsg into this ISOMsg instance, excluding the header.
* This method is a convenience wrapper around {@link #merge(ISOMsg, boolean)} with the {@code mergeHeader}
* parameter set to {@code false} for backward compatibility, indicating that the header of the input message
* will not be merged.
*/
public void merge (ISOMsg m) {
merge (m, false);
}

/**
* @return a string suitable for a log
*/
Expand Down
2 changes: 2 additions & 0 deletions jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ public void testMerge1() throws Throwable {
assertEquals(3, iSOMsg.maxField, "iSOMsg.maxField");
assertTrue(iSOMsg.dirty, "iSOMsg.dirty");
assertEquals("000000", iSOMsg.getString(3));
assertNull(iSOMsg.getHeader());
iSOMsg.merge(m, true);
assertArrayEquals("ISOHEADER".getBytes(), iSOMsg.getHeader());
}

Expand Down

0 comments on commit dbe1468

Please sign in to comment.