Commit df0f7758 by WeiCong

增加基于域名的解析和组装

parent 30dcc426
...@@ -12,6 +12,7 @@ public class TagLine implements MessageArea { ...@@ -12,6 +12,7 @@ public class TagLine implements MessageArea {
private String tagName; private String tagName;
private String status; private String status;
public MessageArea parent; public MessageArea parent;
public boolean onlyOne;
public String getStatus() { public String getStatus() {
return status; return status;
......
package com.brilliace.swifteditor.tag.message; package com.brilliace.swifteditor.tag.message;
import com.brilliace.swifteditor.tag.TagCell;
import com.brilliace.swifteditor.tag.TagFormat; import com.brilliace.swifteditor.tag.TagFormat;
import com.brilliace.swifteditor.tag.TagLine; import com.brilliace.swifteditor.tag.TagLine;
import com.brilliace.swifteditor.util.Assert; import com.brilliace.swifteditor.util.Assert;
...@@ -14,6 +15,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -14,6 +15,7 @@ public class SWFMessage extends AbstractMessageArea {
private String mtType; private String mtType;
private Map<Integer, String> headers; private Map<Integer, String> headers;
private Map<Integer, TagLine> flatModel = new HashMap<>(); private Map<Integer, TagLine> flatModel = new HashMap<>();
private Map<String, Integer> tag2No = new HashMap<>();
private Map<String, String> bscInfo; private Map<String, String> bscInfo;
protected SWFMessage() { protected SWFMessage() {
...@@ -136,7 +138,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -136,7 +138,7 @@ public class SWFMessage extends AbstractMessageArea {
} }
msg.setName(this.getName()); msg.setName(this.getName());
msg.setAnlyReg(this.getAnlyReg()); msg.setAnlyReg(this.getAnlyReg());
generateFlatModel(msg, msg.flatModel, null); generateFlatModel(msg, msg.flatModel, msg.tag2No, null, false);
return msg; return msg;
} }
...@@ -198,8 +200,8 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -198,8 +200,8 @@ public class SWFMessage extends AbstractMessageArea {
* @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分 * @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分
* @param val 待填充得数据 * @param val 待填充得数据
*/ */
public void setGeneric(String path, Object val) { public void setGenericByNo(String path, Object val) {
setGeneric(path, val, null); setGenericByNo(path, val, null);
} }
/** /**
...@@ -213,7 +215,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -213,7 +215,7 @@ public class SWFMessage extends AbstractMessageArea {
* @param val 待填充得数据 * @param val 待填充得数据
* @param tagName 域名称,对于多选域(譬如60a),需要提供该域具体选项(譬如60F) * @param tagName 域名称,对于多选域(譬如60a),需要提供该域具体选项(譬如60F)
*/ */
public void setGeneric(String path, Object val, String tagName) { public void setGenericByNo(String path, Object val, String tagName) {
checkPath(path); checkPath(path);
Assert.notNull(val, "对坐标[" + path + "]的赋值不能为空"); Assert.notNull(val, "对坐标[" + path + "]的赋值不能为空");
int index = path.indexOf("."); int index = path.indexOf(".");
...@@ -222,6 +224,13 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -222,6 +224,13 @@ public class SWFMessage extends AbstractMessageArea {
tagLine = this.flatModel.get(Integer.valueOf(path)); tagLine = this.flatModel.get(Integer.valueOf(path));
checkTagLine(tagLine, tagName); checkTagLine(tagLine, tagName);
if (tagLine.parent != null) { if (tagLine.parent != null) {
if (val instanceof String && tagLine.onlyOne) {
if (tagLine.onlyOne) {
val = Collections.singletonList(val);
} else {
throw new IllegalArgumentException("域" + tagLine.getName() + "需要填充List集合类型的数据");
}
}
setGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) val, 0); setGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) val, 0);
} else { } else {
tagLine.setValue((String) val); tagLine.setValue((String) val);
...@@ -229,16 +238,38 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -229,16 +238,38 @@ public class SWFMessage extends AbstractMessageArea {
} else { } else {
tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index))); tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index)));
checkTagLine(tagLine, tagName); checkTagLine(tagLine, tagName);
int part = Integer.parseInt(path.substring(index + 1)); int part = Integer.parseInt(path.substring(index + 1)) + 1;
Assert.state(part >= 0 && part < tagLine.cellList.size(), "索引[" + path + "]指定的域块不存在"); Assert.state(part > 0, "索引[" + path + "]指定的域块不存在");
if (tagLine.parent != null) { if (tagLine.parent != null) {
setGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) val, 0); setGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) val, 0);
} else { } else {
tagLine.cellList.get(part).value = (String) val; for (TagCell cell : tagLine.cellList) {
if (cell.cnt == part) {
cell.setValue((String) val);
break;
}
}
} }
} }
} }
/**
* 根据指定域名(.域块号),填充具体域或者域块的值
*
* @param tagExp 域名(.域块号)
* @param val 待填充得数据
* 待填充的数据类型有三种:<br/>
* 1.填充唯一域数据类型是String<br/>
* 2.填充循环域数据类型是List&lt;String&gt;<br/>
* 3.填充循环Sequence域数据类型是List&lt;List&gt;
*/
public void setGenericByTag(String tagExp, Object val) {
String path = checkTag(tagExp);
int index = tagExp.indexOf(".");
setGenericByNo(path, val, index == -1 ? tagExp : tagExp.substring(0, index));
}
private boolean setGenericRepetitive(AbstractMessageArea parent, int index, int ano, List<Object> rs, int cnt) { private boolean setGenericRepetitive(AbstractMessageArea parent, int index, int ano, List<Object> rs, int cnt) {
if (parent.getType() == MessageArea.CYC || parent.getType() == MessageArea.SEQ) { if (parent.getType() == MessageArea.CYC || parent.getType() == MessageArea.SEQ) {
for (int i = 0; i < parent.getFields().size(); i++) { for (int i = 0; i < parent.getFields().size(); i++) {
...@@ -248,7 +279,12 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -248,7 +279,12 @@ public class SWFMessage extends AbstractMessageArea {
if (index == -1) { if (index == -1) {
((TagLine) item).setValue((String) rs.get(cnt)); ((TagLine) item).setValue((String) rs.get(cnt));
} else { } else {
((TagLine) item).cellList.get(index).value = (String) rs.get(cnt); for (TagCell cell : ((TagLine) item).cellList) {
if (cell.cnt == index) {
cell.setValue((String) rs.get(cnt));
break;
}
}
} }
return true; return true;
} }
...@@ -306,16 +342,39 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -306,16 +342,39 @@ public class SWFMessage extends AbstractMessageArea {
} }
/** /**
* 根据指定域名(.域块号),获取域或者域块的值
*
* @param tagExp 域名(.域块号)
* @return 域或者域块的值
*/
public Object getGenericByTag(String tagExp) {
String path = checkTag(tagExp);
return getGenericByNo(path);
}
/**
* 根据指定域名(.域块号)和索引,获取具体域或者域块的具体成员
*
* @param tagExp 域名(.域块号)
* @param indexes 索引
* @return 返回具体成员
*/
public Object getGenericByTag(String tagExp, int... indexes) {
String path = checkTag(tagExp);
return getGenericByNo(path, indexes);
}
/**
* 根据指定坐标,获取具体域或者域块的值。举例:950的61域对应的坐标是5;而对应的第一域块是5.0 * 根据指定坐标,获取具体域或者域块的值。举例:950的61域对应的坐标是5;而对应的第一域块是5.0
* 调用getGeneric("5")会返回类型为List&lt;Object&gt;的所有域值<br/> * 调用getGeneric("5")会返回类型为List&lt;Object&gt;的所有域值<br/>
* 调用getGeneric("5.0")会返回类型为List&lt;Object&gt;的所有第一域块值<br/> * 调用getGeneric("5.1")会返回类型为List&lt;Object&gt;的所有第一域块值<br/>
* *
* @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分 * @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分
* @return 1.域不再Sequence中(如950报文的20,25域)或者在不可循环的Sequence中(如101报文的20域),返回值类型是String<br/> * @return 1.域不再Sequence中(如950报文的20,25域)或者在不可循环的Sequence中(如101报文的20域),返回值类型是String<br/>
* 2.域在循环中(如950报文的61域),返回类型List&lt;String&gt;<br/> * 2.域在循环中(如950报文的61域),返回类型List&lt;String&gt;<br/>
* 3.域在循环的Sequence中(如101报文的21域),返回类型List&lt;List&gt;,更复杂情况是嵌套N层循环域,则List也会嵌套N层<br/> * 3.域在循环的Sequence中(如101报文的21域),返回类型List&lt;List&gt;,更复杂情况是嵌套N层循环域,则List也会嵌套N层<br/>
*/ */
public Object getGeneric(String path) { public Object getGenericByNo(String path) {
checkPath(path); checkPath(path);
Object rs = genericCache.get(path); Object rs = genericCache.get(path);
if (rs != null) { if (rs != null) {
...@@ -333,33 +392,41 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -333,33 +392,41 @@ public class SWFMessage extends AbstractMessageArea {
} }
} else { } else {
tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index))); tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index)));
int part = Integer.parseInt(path.substring(index + 1)); int part = Integer.parseInt(path.substring(index + 1)) + 1;
Assert.state(part >= 0 && part < tagLine.cellList.size(), "索引[" + path + "]指定的域块不存在");
if (tagLine.parent != null) { if (tagLine.parent != null) {
rs = new LinkedList<Object>(); rs = new LinkedList<Object>();
getGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) rs); getGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) rs);
} else { } else {
rs = tagLine.cellList.get(part).value; for (TagCell cell : tagLine.cellList) {
if (cell.cnt == part) {
rs = cell.value;
break;
}
}
}
} }
if (rs instanceof List && tagLine.onlyOne) {
rs = ((List<Object>) rs).get(0);
} }
genericCache.put(path, rs); genericCache.put(path, rs);
return rs; return rs;
} }
/** /**
* 根据指定坐标和索引,获取具体域或者域块{@link com.brilliace.swifteditor.tag.message.SWFMessage#getGeneric(java.lang.String)} * 根据指定坐标和索引,获取具体域或者域块{@link com.brilliace.swifteditor.tag.message.SWFMessage#getGenericByNo(java.lang.String)}
* 的具体一个成员 * 的具体一个成员
*
* @param path 坐标 * @param path 坐标
* @param indexes 索引 * @param indexes 索引
* @return 返回具体成员 * @return 返回具体成员
*/ */
public Object getGenericByIndexes(String path, int... indexes) { public Object getGenericByNo(String path, int... indexes) {
Object generic = getGeneric(path); Object generic = getGenericByNo(path);
if (indexes == null || indexes.length == 0) { if (indexes == null || indexes.length == 0) {
return generic; return generic;
} }
for (int index : indexes) { for (int index : indexes) {
generic=((List<Object>)generic).get(index); generic = ((List<Object>) generic).get(index);
} }
return generic; return generic;
} }
...@@ -372,7 +439,12 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -372,7 +439,12 @@ public class SWFMessage extends AbstractMessageArea {
if (index == -1) { if (index == -1) {
rs.add(((TagLine) item).getSourceValue()); rs.add(((TagLine) item).getSourceValue());
} else { } else {
rs.add(((TagLine) item).cellList.get(index).value); for (TagCell cell : ((TagLine) item).cellList) {
if (cell.cnt == index) {
rs.add(cell.value);
break;
}
}
} }
break; break;
} else if (((TagLine) item).getTno() > ano) { } else if (((TagLine) item).getTno() > ano) {
...@@ -392,20 +464,49 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -392,20 +464,49 @@ public class SWFMessage extends AbstractMessageArea {
} }
} }
private void checkPath(String path) { private String checkTag(String tagEXp) {
String tag = tagEXp;
int index = tagEXp.indexOf(".");
if (index != -1) {
tag = tagEXp.substring(0, index);
}
Assert.state(tag != null && tag != "" && tag2No.containsKey(tag),
this.getMtType() + "类型报文不存在域[" + tag + "]");
return index == -1 ? tag2No.get(tag).toString() : (tag2No.get(tag) + tagEXp.substring(index));
}
private void checkPath(String pathExp) {
String path = pathExp;
int index = pathExp.indexOf(".");
if (index != -1) {
path = pathExp.substring(0, index);
}
Assert.state(path != null && path != "" && CHECKPATH.matcher(path).find(), "索引[" + path + "]不符合规范"); Assert.state(path != null && path != "" && CHECKPATH.matcher(path).find(), "索引[" + path + "]不符合规范");
Assert.state(flatModel.containsKey(Integer.valueOf(path)),
this.getMtType() + "类型报文不存在序号[" + path + "]对应的域");
} }
private void generateFlatModel(MessageArea area, Map<Integer, TagLine> flatModel, MessageArea parent) { private void generateFlatModel(MessageArea area, Map<Integer, TagLine> flatModel, Map<String, Integer> tag2No, MessageArea parent, boolean onlyOne) {
List<MessageArea> fieldList = ((AbstractMessageArea) area).getFields(); List<MessageArea> fieldList = ((AbstractMessageArea) area).getFields();
for (int i = 0; i < fieldList.size(); i++) { for (int i = 0; i < fieldList.size(); i++) {
MessageArea item = fieldList.get(i); MessageArea item = fieldList.get(i);
if (item.getType() == MessageArea.TAG) { if (item.getType() == MessageArea.TAG) {
TagLine tagLine = (TagLine) item; TagLine tagLine = (TagLine) item;
String tagNam = tagLine.getName();
tagLine.parent = parent; tagLine.parent = parent;
tagLine.onlyOne = onlyOne;
flatModel.put(tagLine.getTno(), tagLine); flatModel.put(tagLine.getTno(), tagLine);
if (tagNam.endsWith("a") && tagLine.getSuffix().size() > 0) {
for (String tgn : tagLine.getSuffix()) {
tag2No.put(tgn, tagLine.getTno());
}
} else {
tag2No.put(tagNam, tagLine.getTno());
}
} else if (item.getType() == MessageArea.CYCLIST || item.getType() == MessageArea.SEQLIST) { } else if (item.getType() == MessageArea.CYCLIST || item.getType() == MessageArea.SEQLIST) {
generateFlatModel(((AbstractMessageArea) item).getFields().get(0), flatModel, parent != null ? parent : item); onlyOne = item.getType() == MessageArea.CYCLIST ? false :
((item.getType() == MessageArea.SEQLIST && ((SEQList) item).getCyc() == 1) ? false : true);
generateFlatModel(((AbstractMessageArea) item).getFields().get(0), flatModel, tag2No, parent != null ? parent : item, onlyOne);
} else { } else {
System.err.println(item.getType() + " no match"); System.err.println(item.getType() + " no match");
continue; continue;
......
...@@ -21,47 +21,78 @@ public class ParseSwiftTest extends TestCase { ...@@ -21,47 +21,78 @@ public class ParseSwiftTest extends TestCase {
System.out.println(obj.getFlatModel()); System.out.println(obj.getFlatModel());
} }
public void testGetGeneric() { public void testGetGenericByNo() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg); SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取4域(60F)=" + swf.getGeneric("4")); System.out.println("获取4域(60F)=" + swf.getGenericByNo("4"));
System.out.println("获取4域第二部分(60F的<DATE2>部分)=" + swf.getGeneric("4.1")); System.out.println("获取4域第二部分(60F的<DATE2>部分)=" + swf.getGenericByNo("4.1"));
System.out.println("获取循环域5(61)=" + swf.getGeneric("5")); System.out.println("获取循环域5(61)=" + swf.getGenericByNo("5"));
System.out.println("获取循环域5第一域块(61的6!n)=" + swf.getGeneric("5.0")); System.out.println("获取循环域5第一域块(61的6!n)=" + swf.getGenericByNo("5.0"));
path = path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath(); path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
msg = MessageAnalyzer.readFull(path); msg = MessageAnalyzer.readFull(path);
swf = MessageAnalyzer.loadSwiftMessage(msg); swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取1域(不可循环的Sequence A的20域)=" + swf.getGeneric("1")); System.out.println("获取1域(不可循环的Sequence A的20域)=" + swf.getGenericByNo("1"));
System.out.println("获取10域(循环的Sequence B的21域)=" + swf.getGeneric("10")); System.out.println("获取3域第二部分(不可循环的Sequence A的28D域)=" + swf.getGenericByNo("3.1"));
System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)=" + swf.getGeneric("12")); System.out.println("获取10域(循环的Sequence B的21域)=" + swf.getGenericByNo("10"));
System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)=" + swf.getGenericByNo("12"));
} }
public void testGetGenericByIndexes() { public void testGetGenericByTag() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg); SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取循环域5(61)的第二个成员=" + swf.getGenericByIndexes("5", 1)); assertEquals(swf.getGenericByTag("60F"), swf.getGenericByNo("4"));
System.out.println("获取循环域5第一域块(61的6!n)的第二个成员=" + swf.getGenericByIndexes("5.0", 1)); assertEquals(swf.getGenericByTag("60F.1"), swf.getGenericByNo("4.1"));
path = path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath(); assertEquals(swf.getGenericByTag("61.0"), swf.getGenericByNo("5.0"));
path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
msg = MessageAnalyzer.readFull(path);
swf = MessageAnalyzer.loadSwiftMessage(msg);
assertEquals(swf.getGenericByTag("20"), swf.getGenericByNo("1"));
assertEquals(swf.getGenericByTag("21"), swf.getGenericByNo("10"));
assertEquals(swf.getGenericByTag("23E"), swf.getGenericByNo("12"));
assertEquals(swf.getGenericByTag("59"), swf.getGenericByNo("19"));
}
public void testGetGenericByNoWithIndexs() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取循环域5(61)的第二个成员=" + swf.getGenericByNo("5", 1));
System.out.println("获取循环域5第一域块(61的6!n)的第二个成员=" + swf.getGenericByNo("5.0", 1));
path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
msg = MessageAnalyzer.readFull(path); msg = MessageAnalyzer.readFull(path);
swf = MessageAnalyzer.loadSwiftMessage(msg); swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取10域(循环的Sequence B的21域)的第一个Sequence部分=" + swf.getGenericByNo("10", 0));
System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)的第二个sequence的第三个成员=" System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)的第二个sequence的第三个成员="
+ swf.getGenericByIndexes("12", 1, 2)); + swf.getGenericByNo("12", 1, 2));
}
public void testGetGenericByTagWithIndexs() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
assertEquals(swf.getGenericByTag("61",1), swf.getGenericByNo("5",1));
assertEquals(swf.getGenericByTag("61.0",1), swf.getGenericByNo("5.0",1));
path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
msg = MessageAnalyzer.readFull(path);
swf = MessageAnalyzer.loadSwiftMessage(msg);
assertEquals(swf.getGenericByTag("23E",1,2), swf.getGenericByNo("12",1,2));
} }
public void testSetGeneric() { public void testSetGenericByNo() {
SWFMessage swf = MessageFormat.getSWFMessage("950"); SWFMessage swf = MessageFormat.getSWFMessage("950");
//填充950的20域 //填充950的20域
swf.setGeneric("1", "STMMDL129058636E"); swf.setGenericByNo("1", "STMMDL129058636E");
assertEquals(swf.getGeneric("1"), "STMMDL129058636E"); assertEquals(swf.getGenericByNo("1"), "STMMDL129058636E");
//填充950的60a域 //填充950的60a域
swf.setGeneric("4", "C120330GBP94854,84", "60F"); swf.setGenericByNo("4", "C120330GBP94854,84", "60F");
assertEquals(swf.getGeneric("4"), "C120330GBP94854,84"); assertEquals(swf.getGenericByNo("4"), "C120330GBP94854,84");
//填充950的60a域的第二部分 //填充950的60a域的第二部分
swf.setGeneric("4.1", "120330", "60F"); swf.setGenericByNo("4.1", "120330", "60F");
assertEquals(swf.getGeneric("4.1"), "120330"); assertEquals(swf.getGenericByNo("4.1"), "120330");
//填充950的61循环域 //填充950的61循环域
List<String> sixtyone = new LinkedList<String>(); List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" + sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" +
...@@ -70,32 +101,96 @@ public class ParseSwiftTest extends TestCase { ...@@ -70,32 +101,96 @@ public class ParseSwiftTest extends TestCase {
"FENG ZZWE"); "FENG ZZWE");
sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" + sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" +
"FENG EFFE"); "FENG EFFE");
swf.setGeneric("5", sixtyone); swf.setGenericByNo("5", sixtyone);
assertEquals(swf.getGeneric("5"), sixtyone); assertEquals(swf.getGenericByNo("5"), sixtyone);
//填充950的61域第5部分,Amount //填充950的61域第5部分,Amount
swf = MessageFormat.getSWFMessage("950"); swf = MessageFormat.getSWFMessage("950");
List<String> sixtyone_amount = new LinkedList<String>(); List<String> sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000,25"); sixtyone_amount.add("10000,25");
sixtyone_amount.add("30000,55"); sixtyone_amount.add("30000,55");
sixtyone_amount.add("20115,"); sixtyone_amount.add("20115,");
swf.setGeneric("5.4", sixtyone_amount); swf.setGenericByNo("5.4", sixtyone_amount);
assertEquals(swf.getGeneric("5.4"), sixtyone_amount); sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000.25");
sixtyone_amount.add("30000.55");
sixtyone_amount.add("20115");
assertEquals(swf.getGenericByNo("5.4"), sixtyone_amount);
//填充101的不可循环的Sequence A的20域 //填充101的不可循环的Sequence A的20域
swf = MessageFormat.getSWFMessage("101"); swf = MessageFormat.getSWFMessage("101");
List<String> one = new LinkedList<>(); swf.setGenericByNo("1", "STMMDL129058636E");
one.add("STMMDL129058636E"); assertEquals(swf.getGenericByNo("1"), "STMMDL129058636E");
swf.setGeneric("1", one);
assertEquals(swf.getGeneric("1"), one);
//填充101的循环的Sequence B的21域 //填充101的循环的Sequence B的21域
List<Object> comList = new LinkedList<>(); List<Object> comList = new LinkedList<>();
List<String> one = new LinkedList<>();
one.add("101651ATT000005W");
comList.add(one);
one = new LinkedList<>();
one.add("321651ATT000005Z");
comList.add(one);
swf.setGenericByNo("10", comList);
assertEquals(swf.getGenericByNo("10"), comList);
//填充101的循环的Sequence B的23E循环域
comList = new LinkedList<>();
one = new LinkedList<>(); one = new LinkedList<>();
one.add("CHQB/HELLO");
one.add("CHQB/WORLD");
comList.add(one);
one = new LinkedList<>();
one.add("CHQB/MY");
one.add("CHQB/NAME");
one.add("CHQB/IS");
comList.add(one);
swf.setGenericByNo("12", comList);
assertEquals(swf.getGenericByNo("12"), comList);
}
public void testSetGenericByTag() {
SWFMessage swf = MessageFormat.getSWFMessage("950");
//填充950的20域
swf.setGenericByTag("20", "STMMDL129058636E");
assertEquals(swf.getGenericByTag("20"), "STMMDL129058636E");
//填充950的60a域
swf.setGenericByTag("60F", "C120330GBP94854,84");
assertEquals(swf.getGenericByTag("60F"), "C120330GBP94854,84");
//填充950的60a域的第二部分
swf.setGenericByTag("60F.1", "120330");
assertEquals(swf.getGenericByTag("60F.1"), "120330");
//填充950的61循环域
List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" +
"FENG XING");
sixtyone.add("1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS\n" +
"FENG ZZWE");
sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" +
"FENG EFFE");
swf.setGenericByTag("61", sixtyone);
assertEquals(swf.getGenericByTag("61"), sixtyone);
//填充950的61域第5部分,Amount
swf = MessageFormat.getSWFMessage("950");
List<String> sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000,25");
sixtyone_amount.add("30000,55");
sixtyone_amount.add("20115,");
swf.setGenericByTag("61.4", sixtyone_amount);
sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000.25");
sixtyone_amount.add("30000.55");
sixtyone_amount.add("20115");
assertEquals(swf.getGenericByTag("61.4"), sixtyone_amount);
//填充101的不可循环的Sequence A的20域
swf = MessageFormat.getSWFMessage("101");
swf.setGenericByTag("20", "STMMDL129058636E");
assertEquals(swf.getGenericByTag("20"), "STMMDL129058636E");
//填充101的循环的Sequence B的21域
List<Object> comList = new LinkedList<>();
List<String> one = new LinkedList<>();
one.add("101651ATT000005W"); one.add("101651ATT000005W");
comList.add(one); comList.add(one);
one = new LinkedList<>(); one = new LinkedList<>();
one.add("321651ATT000005Z"); one.add("321651ATT000005Z");
comList.add(one); comList.add(one);
swf.setGeneric("10", comList); swf.setGenericByTag("21", comList);
assertEquals(swf.getGeneric("10"), comList); assertEquals(swf.getGenericByTag("21"), comList);
//填充101的循环的Sequence B的23E循环域 //填充101的循环的Sequence B的23E循环域
comList = new LinkedList<>(); comList = new LinkedList<>();
one = new LinkedList<>(); one = new LinkedList<>();
...@@ -107,7 +202,7 @@ public class ParseSwiftTest extends TestCase { ...@@ -107,7 +202,7 @@ public class ParseSwiftTest extends TestCase {
one.add("CHQB/NAME"); one.add("CHQB/NAME");
one.add("CHQB/IS"); one.add("CHQB/IS");
comList.add(one); comList.add(one);
swf.setGeneric("12", comList); swf.setGenericByTag("23E", comList);
assertEquals(swf.getGeneric("12"), comList); assertEquals(swf.getGenericByTag("23E"), comList);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment