From 9f5a7d59af78f4327f12c4df89f094cb29911db3 Mon Sep 17 00:00:00 2001 From: chochos Date: Thu, 11 Aug 2011 15:27:49 +0000 Subject: [PATCH] Improved the generics usage in methods returning IsoValues (and getObjectValue() as well). Now you can do stuff like this: IsoValue v = message.getField(7); BigDecimal amount = message.getObjectValue(4); No need to cast. Having generified IsoValue is now useful. git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@91 db60a039-f72e-0410-b1d2-baa000846441 --- .../java/com/solab/iso8583/IsoMessage.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/solab/iso8583/IsoMessage.java b/src/main/java/com/solab/iso8583/IsoMessage.java index 43c210f..70b04d4 100644 --- a/src/main/java/com/solab/iso8583/IsoMessage.java +++ b/src/main/java/com/solab/iso8583/IsoMessage.java @@ -42,7 +42,7 @@ public class IsoMessage { /** Indicates if the message is binary-coded. */ private boolean binary; /** This is where the values are stored. */ - private IsoValue[] fields = new IsoValue[129]; + private IsoValue[] fields = new IsoValue[129]; /** Stores the optional ISO header. */ private String isoHeader; private int etx = -1; @@ -111,13 +111,15 @@ public class IsoMessage { /** Returns the stored value in the field, without converting or formatting it. * @param field The field number. 1 is the secondary bitmap and is not returned as such; * real fields go from 2 to 128. */ - public Object getObjectValue(int field) { - IsoValue v = fields[field]; + public T getObjectValue(int field) { + @SuppressWarnings("unchecked") + IsoValue v = fields[field]; return v == null ? null : v.getValue(); } /** Returns the IsoValue for the specified field. First real field is 2. */ - public IsoValue getField(int field) { + @SuppressWarnings("unchecked") + public IsoValue getField(int field) { return fields[field]; } @@ -357,7 +359,7 @@ public class IsoMessage { setField(i, v); } /** Returns the IsoValue in the specified field, just like {@link #getField(int)}. */ - public IsoValue getAt(int i) { + public IsoValue getAt(int i) { return getField(i); } @@ -365,7 +367,7 @@ public class IsoMessage { public void update(int i, IsoValue v) { setField(i, v); } - public IsoValue apply(int i) { + public IsoValue apply(int i) { return getField(i); } @@ -374,7 +376,9 @@ public class IsoMessage { public void copyFieldsFrom(IsoMessage src, int...idx) { for (int i : idx) { IsoValue v = src.getField(i); - if (v != null) { + if (v == null) { + setField(i, null); + } else { setValue(i, v.getValue(), v.getEncoder(), v.getType(), v.getLength()); } }