diff --git a/src/main/java/com/solab/iso8583/codecs/CompositeField.java b/src/main/java/com/solab/iso8583/codecs/CompositeField.java index e7f5b8b..6cbfe24 100644 --- a/src/main/java/com/solab/iso8583/codecs/CompositeField.java +++ b/src/main/java/com/solab/iso8583/codecs/CompositeField.java @@ -1,6 +1,7 @@ package com.solab.iso8583.codecs; import com.solab.iso8583.CustomBinaryField; +import com.solab.iso8583.CustomField; import com.solab.iso8583.IsoType; import com.solab.iso8583.IsoValue; import com.solab.iso8583.parse.FieldParseInfo; @@ -24,26 +25,40 @@ public class CompositeField implements CustomBinaryField { private static final Logger log = LoggerFactory.getLogger(CompositeField.class); /** Stores the subfields. */ - private List> values; + @SuppressWarnings("rawtypes") + private List values; /** Stores the parsers for the subfields. */ private List parsers; - public void setValues(List> values) { + @SuppressWarnings("rawtypes") + public void setValues(List values) { this.values = values; } - public List> getValues() { + @SuppressWarnings("rawtypes") + public List getValues() { return values; } + @SuppressWarnings("rawtypes") public CompositeField addValue(IsoValue v) { if (values == null) { - values = new ArrayList>(4); + values = new ArrayList(4); } values.add(v); return this; } - public Object getObjectValue(int idx) { + public CompositeField addValue(T val, CustomField encoder, IsoType t, int length) { + return addValue(t.needsLength() ? new IsoValue(t, val, length, encoder) + : new IsoValue(t, val, encoder)); + } + + @SuppressWarnings("unchecked") + public IsoValue getField(int idx) { if (idx < 0 || idx > values.size())return null; - return values.get(idx).getValue(); + return values.get(idx); + } + public T getObjectValue(int idx) { + IsoValue v = getField(idx); + return v==null ? null : v.getValue(); } public void setParsers(List fpis) { @@ -62,7 +77,8 @@ public class CompositeField implements CustomBinaryField { @Override public CompositeField decodeBinaryField(byte[] buf, int offset, int length) { - List> vals = new ArrayList>(parsers.size()); + @SuppressWarnings("rawtypes") + List vals = new ArrayList(parsers.size()); int pos = 0; try { for (FieldParseInfo fpi : parsers) { @@ -97,7 +113,8 @@ public class CompositeField implements CustomBinaryField { @Override public CompositeField decodeField(String value) { - List> vals = new ArrayList>(parsers.size()); + @SuppressWarnings("rawtypes") + List vals = new ArrayList(parsers.size()); byte[] buf = value.getBytes(); int pos = 0; try { @@ -146,7 +163,7 @@ public class CompositeField implements CustomBinaryField { try { String encoding = null; for (IsoValue v : value.getValues()) { - v.write(bout, true, true); + v.write(bout, false, true); if (encoding == null)encoding = v.getCharacterEncoding(); } buf = bout.toByteArray();