Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swifteditor_java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fukai
swifteditor_java
Commits
df0f7758
Commit
df0f7758
authored
Nov 12, 2019
by
WeiCong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加基于域名的解析和组装
parent
30dcc426
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
251 additions
and
54 deletions
+251
-54
TagLine.java
src/main/java/com/brilliace/swifteditor/tag/TagLine.java
+1
-0
SWFMessage.java
...ava/com/brilliace/swifteditor/tag/message/SWFMessage.java
+122
-21
ParseSwiftTest.java
src/test/java/com/brilliace/swifteditor/ParseSwiftTest.java
+128
-33
No files found.
src/main/java/com/brilliace/swifteditor/tag/TagLine.java
View file @
df0f7758
...
...
@@ -12,6 +12,7 @@ public class TagLine implements MessageArea {
private
String
tagName
;
private
String
status
;
public
MessageArea
parent
;
public
boolean
onlyOne
;
public
String
getStatus
()
{
return
status
;
...
...
src/main/java/com/brilliace/swifteditor/tag/message/SWFMessage.java
View file @
df0f7758
package
com
.
brilliace
.
swifteditor
.
tag
.
message
;
import
com.brilliace.swifteditor.tag.TagCell
;
import
com.brilliace.swifteditor.tag.TagFormat
;
import
com.brilliace.swifteditor.tag.TagLine
;
import
com.brilliace.swifteditor.util.Assert
;
...
...
@@ -14,6 +15,7 @@ public class SWFMessage extends AbstractMessageArea {
private
String
mtType
;
private
Map
<
Integer
,
String
>
headers
;
private
Map
<
Integer
,
TagLine
>
flatModel
=
new
HashMap
<>();
private
Map
<
String
,
Integer
>
tag2No
=
new
HashMap
<>();
private
Map
<
String
,
String
>
bscInfo
;
protected
SWFMessage
()
{
...
...
@@ -136,7 +138,7 @@ public class SWFMessage extends AbstractMessageArea {
}
msg
.
setName
(
this
.
getName
());
msg
.
setAnlyReg
(
this
.
getAnlyReg
());
generateFlatModel
(
msg
,
msg
.
flatModel
,
null
);
generateFlatModel
(
msg
,
msg
.
flatModel
,
msg
.
tag2No
,
null
,
false
);
return
msg
;
}
...
...
@@ -198,8 +200,8 @@ public class SWFMessage extends AbstractMessageArea {
* @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分
* @param val 待填充得数据
*/
public
void
setGeneric
(
String
path
,
Object
val
)
{
setGeneric
(
path
,
val
,
null
);
public
void
setGeneric
ByNo
(
String
path
,
Object
val
)
{
setGeneric
ByNo
(
path
,
val
,
null
);
}
/**
...
...
@@ -213,7 +215,7 @@ public class SWFMessage extends AbstractMessageArea {
* @param val 待填充得数据
* @param tagName 域名称,对于多选域(譬如60a),需要提供该域具体选项(譬如60F)
*/
public
void
setGeneric
(
String
path
,
Object
val
,
String
tagName
)
{
public
void
setGeneric
ByNo
(
String
path
,
Object
val
,
String
tagName
)
{
checkPath
(
path
);
Assert
.
notNull
(
val
,
"对坐标["
+
path
+
"]的赋值不能为空"
);
int
index
=
path
.
indexOf
(
"."
);
...
...
@@ -222,6 +224,13 @@ public class SWFMessage extends AbstractMessageArea {
tagLine
=
this
.
flatModel
.
get
(
Integer
.
valueOf
(
path
));
checkTagLine
(
tagLine
,
tagName
);
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
);
}
else
{
tagLine
.
setValue
((
String
)
val
);
...
...
@@ -229,16 +238,38 @@ public class SWFMessage extends AbstractMessageArea {
}
else
{
tagLine
=
this
.
flatModel
.
get
(
Integer
.
valueOf
(
path
.
substring
(
0
,
index
)));
checkTagLine
(
tagLine
,
tagName
);
int
part
=
Integer
.
parseInt
(
path
.
substring
(
index
+
1
));
Assert
.
state
(
part
>
=
0
&&
part
<
tagLine
.
cellList
.
size
()
,
"索引["
+
path
+
"]指定的域块不存在"
);
int
part
=
Integer
.
parseInt
(
path
.
substring
(
index
+
1
))
+
1
;
Assert
.
state
(
part
>
0
,
"索引["
+
path
+
"]指定的域块不存在"
);
if
(
tagLine
.
parent
!=
null
)
{
setGenericRepetitive
((
AbstractMessageArea
)
tagLine
.
parent
,
part
,
tagLine
.
getTno
(),
(
List
<
Object
>)
val
,
0
);
}
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<String><br/>
* 3.填充循环Sequence域数据类型是List<List>
*/
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
)
{
if
(
parent
.
getType
()
==
MessageArea
.
CYC
||
parent
.
getType
()
==
MessageArea
.
SEQ
)
{
for
(
int
i
=
0
;
i
<
parent
.
getFields
().
size
();
i
++)
{
...
...
@@ -248,7 +279,12 @@ public class SWFMessage extends AbstractMessageArea {
if
(
index
==
-
1
)
{
((
TagLine
)
item
).
setValue
((
String
)
rs
.
get
(
cnt
));
}
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
;
}
...
...
@@ -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
* 调用getGeneric("5")会返回类型为List<Object>的所有域值<br/>
* 调用getGeneric("5.
0
")会返回类型为List<Object>的所有第一域块值<br/>
* 调用getGeneric("5.
1
")会返回类型为List<Object>的所有第一域块值<br/>
*
* @param path 坐标,格式为No(.part) No表示域的序号,part是可选部分表示获取域的某个部分
* @return 1.域不再Sequence中(如950报文的20,25域)或者在不可循环的Sequence中(如101报文的20域),返回值类型是String<br/>
* 2.域在循环中(如950报文的61域),返回类型List<String><br/>
* 3.域在循环的Sequence中(如101报文的21域),返回类型List<List>,更复杂情况是嵌套N层循环域,则List也会嵌套N层<br/>
*/
public
Object
getGeneric
(
String
path
)
{
public
Object
getGeneric
ByNo
(
String
path
)
{
checkPath
(
path
);
Object
rs
=
genericCache
.
get
(
path
);
if
(
rs
!=
null
)
{
...
...
@@ -333,33 +392,41 @@ public class SWFMessage extends AbstractMessageArea {
}
}
else
{
tagLine
=
this
.
flatModel
.
get
(
Integer
.
valueOf
(
path
.
substring
(
0
,
index
)));
int
part
=
Integer
.
parseInt
(
path
.
substring
(
index
+
1
));
Assert
.
state
(
part
>=
0
&&
part
<
tagLine
.
cellList
.
size
(),
"索引["
+
path
+
"]指定的域块不存在"
);
int
part
=
Integer
.
parseInt
(
path
.
substring
(
index
+
1
))
+
1
;
if
(
tagLine
.
parent
!=
null
)
{
rs
=
new
LinkedList
<
Object
>();
getGenericRepetitive
((
AbstractMessageArea
)
tagLine
.
parent
,
part
,
tagLine
.
getTno
(),
(
List
<
Object
>)
rs
);
}
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
);
return
rs
;
}
/**
* 根据指定坐标和索引,获取具体域或者域块{@link com.brilliace.swifteditor.tag.message.SWFMessage#getGeneric(java.lang.String)}
* 根据指定坐标和索引,获取具体域或者域块{@link com.brilliace.swifteditor.tag.message.SWFMessage#getGeneric
ByNo
(java.lang.String)}
* 的具体一个成员
*
* @param path 坐标
* @param indexes 索引
* @return 返回具体成员
*/
public
Object
getGenericBy
Indexes
(
String
path
,
int
...
indexes
)
{
Object
generic
=
getGeneric
(
path
);
public
Object
getGenericBy
No
(
String
path
,
int
...
indexes
)
{
Object
generic
=
getGeneric
ByNo
(
path
);
if
(
indexes
==
null
||
indexes
.
length
==
0
)
{
return
generic
;
}
for
(
int
index
:
indexes
)
{
generic
=((
List
<
Object
>)
generic
).
get
(
index
);
generic
=
((
List
<
Object
>)
generic
).
get
(
index
);
}
return
generic
;
}
...
...
@@ -372,7 +439,12 @@ public class SWFMessage extends AbstractMessageArea {
if
(
index
==
-
1
)
{
rs
.
add
(((
TagLine
)
item
).
getSourceValue
());
}
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
;
}
else
if
(((
TagLine
)
item
).
getTno
()
>
ano
)
{
...
...
@@ -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
(
flatModel
.
containsKey
(
Integer
.
valueOf
(
path
)),
this
.
getMtType
()
+
"类型报文不存在序号["
+
path
+
"]对应的域"
);
}
private
void
generateFlatModel
(
MessageArea
area
,
Map
<
Integer
,
TagLine
>
flatModel
,
M
essageArea
parent
)
{
private
void
generateFlatModel
(
MessageArea
area
,
Map
<
Integer
,
TagLine
>
flatModel
,
M
ap
<
String
,
Integer
>
tag2No
,
MessageArea
parent
,
boolean
onlyOne
)
{
List
<
MessageArea
>
fieldList
=
((
AbstractMessageArea
)
area
).
getFields
();
for
(
int
i
=
0
;
i
<
fieldList
.
size
();
i
++)
{
MessageArea
item
=
fieldList
.
get
(
i
);
if
(
item
.
getType
()
==
MessageArea
.
TAG
)
{
TagLine
tagLine
=
(
TagLine
)
item
;
String
tagNam
=
tagLine
.
getName
();
tagLine
.
parent
=
parent
;
tagLine
.
onlyOne
=
onlyOne
;
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
)
{
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
{
System
.
err
.
println
(
item
.
getType
()
+
" no match"
);
continue
;
...
...
src/test/java/com/brilliace/swifteditor/ParseSwiftTest.java
View file @
df0f7758
...
...
@@ -21,47 +21,78 @@ public class ParseSwiftTest extends TestCase {
System
.
out
.
println
(
obj
.
getFlatModel
());
}
public
void
testGetGeneric
()
{
public
void
testGetGeneric
ByNo
()
{
String
path
=
ParseSwiftTest
.
class
.
getClassLoader
().
getResource
(
"950.sf2"
).
getPath
();
String
msg
=
MessageAnalyzer
.
readFull
(
path
);
SWFMessage
swf
=
MessageAnalyzer
.
loadSwiftMessage
(
msg
);
System
.
out
.
println
(
"获取4域(60F)="
+
swf
.
getGeneric
(
"4"
));
System
.
out
.
println
(
"获取4域第二部分(60F的<DATE2>部分)="
+
swf
.
getGeneric
(
"4.1"
));
System
.
out
.
println
(
"获取循环域5(61)="
+
swf
.
getGeneric
(
"5"
));
System
.
out
.
println
(
"获取循环域5第一域块(61的6!n)="
+
swf
.
getGeneric
(
"5.0"
));
System
.
out
.
println
(
"获取4域(60F)="
+
swf
.
getGeneric
ByNo
(
"4"
));
System
.
out
.
println
(
"获取4域第二部分(60F的<DATE2>部分)="
+
swf
.
getGeneric
ByNo
(
"4.1"
));
System
.
out
.
println
(
"获取循环域5(61)="
+
swf
.
getGeneric
ByNo
(
"5"
));
System
.
out
.
println
(
"获取循环域5第一域块(61的6!n)="
+
swf
.
getGeneric
ByNo
(
"5.0"
));
path
=
path
=
ParseSwiftTest
.
class
.
getClassLoader
().
getResource
(
"101.sf2"
).
getPath
();
path
=
ParseSwiftTest
.
class
.
getClassLoader
().
getResource
(
"101.sf2"
).
getPath
();
msg
=
MessageAnalyzer
.
readFull
(
path
);
swf
=
MessageAnalyzer
.
loadSwiftMessage
(
msg
);
System
.
out
.
println
(
"获取1域(不可循环的Sequence A的20域)="
+
swf
.
getGeneric
(
"1"
));
System
.
out
.
println
(
"获取10域(循环的Sequence B的21域)="
+
swf
.
getGeneric
(
"10"
));
System
.
out
.
println
(
"获取12域(循环的Sequence B下的循环部分的23E域)="
+
swf
.
getGeneric
(
"12"
));
System
.
out
.
println
(
"获取1域(不可循环的Sequence A的20域)="
+
swf
.
getGenericByNo
(
"1"
));
System
.
out
.
println
(
"获取3域第二部分(不可循环的Sequence A的28D域)="
+
swf
.
getGenericByNo
(
"3.1"
));
System
.
out
.
println
(
"获取10域(循环的Sequence B的21域)="
+
swf
.
getGenericByNo
(
"10"
));
System
.
out
.
println
(
"获取12域(循环的Sequence B下的循环部分的23E域)="
+
swf
.
getGenericByNo
(
"12"
));
}
public
void
testGetGenericBy
Indexes
()
{
public
void
testGetGenericBy
Tag
()
{
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
.
getGenericByIndexes
(
"5"
,
1
));
System
.
out
.
println
(
"获取循环域5第一域块(61的6!n)的第二个成员="
+
swf
.
getGenericByIndexes
(
"5.0"
,
1
));
path
=
path
=
ParseSwiftTest
.
class
.
getClassLoader
().
getResource
(
"101.sf2"
).
getPath
();
assertEquals
(
swf
.
getGenericByTag
(
"60F"
),
swf
.
getGenericByNo
(
"4"
));
assertEquals
(
swf
.
getGenericByTag
(
"60F.1"
),
swf
.
getGenericByNo
(
"4.1"
));
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
);
swf
=
MessageAnalyzer
.
loadSwiftMessage
(
msg
);
System
.
out
.
println
(
"获取10域(循环的Sequence B的21域)的第一个Sequence部分="
+
swf
.
getGenericByNo
(
"10"
,
0
));
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
testSetGeneric
ByNo
()
{
SWFMessage
swf
=
MessageFormat
.
getSWFMessage
(
"950"
);
//填充950的20域
swf
.
setGeneric
(
"1"
,
"STMMDL129058636E"
);
assertEquals
(
swf
.
getGeneric
(
"1"
),
"STMMDL129058636E"
);
swf
.
setGeneric
ByNo
(
"1"
,
"STMMDL129058636E"
);
assertEquals
(
swf
.
getGeneric
ByNo
(
"1"
),
"STMMDL129058636E"
);
//填充950的60a域
swf
.
setGeneric
(
"4"
,
"C120330GBP94854,84"
,
"60F"
);
assertEquals
(
swf
.
getGeneric
(
"4"
),
"C120330GBP94854,84"
);
swf
.
setGeneric
ByNo
(
"4"
,
"C120330GBP94854,84"
,
"60F"
);
assertEquals
(
swf
.
getGeneric
ByNo
(
"4"
),
"C120330GBP94854,84"
);
//填充950的60a域的第二部分
swf
.
setGeneric
(
"4.1"
,
"120330"
,
"60F"
);
assertEquals
(
swf
.
getGeneric
(
"4.1"
),
"120330"
);
swf
.
setGeneric
ByNo
(
"4.1"
,
"120330"
,
"60F"
);
assertEquals
(
swf
.
getGeneric
ByNo
(
"4.1"
),
"120330"
);
//填充950的61循环域
List
<
String
>
sixtyone
=
new
LinkedList
<
String
>();
sixtyone
.
add
(
"1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n"
+
...
...
@@ -70,32 +101,96 @@ public class ParseSwiftTest extends TestCase {
"FENG ZZWE"
);
sixtyone
.
add
(
"1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n"
+
"FENG EFFE"
);
swf
.
setGeneric
(
"5"
,
sixtyone
);
assertEquals
(
swf
.
getGeneric
(
"5"
),
sixtyone
);
swf
.
setGeneric
ByNo
(
"5"
,
sixtyone
);
assertEquals
(
swf
.
getGeneric
ByNo
(
"5"
),
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
.
setGeneric
(
"5.4"
,
sixtyone_amount
);
assertEquals
(
swf
.
getGeneric
(
"5.4"
),
sixtyone_amount
);
swf
.
setGenericByNo
(
"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域
swf
=
MessageFormat
.
getSWFMessage
(
"101"
);
List
<
String
>
one
=
new
LinkedList
<>();
one
.
add
(
"STMMDL129058636E"
);
swf
.
setGeneric
(
"1"
,
one
);
assertEquals
(
swf
.
getGeneric
(
"1"
),
one
);
swf
.
setGenericByNo
(
"1"
,
"STMMDL129058636E"
);
assertEquals
(
swf
.
getGenericByNo
(
"1"
),
"STMMDL129058636E"
);
//填充101的循环的Sequence B的21域
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
.
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"
);
comList
.
add
(
one
);
one
=
new
LinkedList
<>();
one
.
add
(
"321651ATT000005Z"
);
comList
.
add
(
one
);
swf
.
setGeneric
(
"10
"
,
comList
);
assertEquals
(
swf
.
getGeneric
(
"10
"
),
comList
);
swf
.
setGeneric
ByTag
(
"21
"
,
comList
);
assertEquals
(
swf
.
getGeneric
ByTag
(
"21
"
),
comList
);
//填充101的循环的Sequence B的23E循环域
comList
=
new
LinkedList
<>();
one
=
new
LinkedList
<>();
...
...
@@ -107,7 +202,7 @@ public class ParseSwiftTest extends TestCase {
one
.
add
(
"CHQB/NAME"
);
one
.
add
(
"CHQB/IS"
);
comList
.
add
(
one
);
swf
.
setGeneric
(
"12
"
,
comList
);
assertEquals
(
swf
.
getGeneric
(
"12
"
),
comList
);
swf
.
setGeneric
ByTag
(
"23E
"
,
comList
);
assertEquals
(
swf
.
getGeneric
ByTag
(
"23E
"
),
comList
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment