Skip to content

Commit 2451d2e

Browse files
Fix the method realPutSign of AbstractCobolField (#100)
1 parent 766ca8a commit 2451d2e

File tree

1 file changed

+83
-91
lines changed

1 file changed

+83
-91
lines changed

libcobj/src/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java

Lines changed: 83 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,32 @@ public abstract class AbstractCobolField {
4040
static CobolDataStorage lastdata = null;
4141

4242
static final int[] cobExp10 = {
43-
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
43+
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
4444
};
4545

4646
/**
4747
* moveAlphanumericToNumericで使用 C言語のgotoの代替機能を提供する
4848
*
4949
* @author y-sakamoto
5050
*/
51-
protected class GotoException extends Exception {}
51+
protected class GotoException extends Exception {
52+
}
5253

5354
/**
5455
* コンストラクタ
5556
*
56-
* @param size データを格納するバイト配列の長さ
57+
* @param size データを格納するバイト配列の長さ
5758
* @param dataStorage データを格納するバイト配列を扱うオブジェクト
58-
* @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど)
59+
* @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど)
5960
*/
6061
public AbstractCobolField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) {
6162
this.size = size;
6263
this.dataStorage = dataStorage;
6364
this.attribute = attribute;
6465
}
6566

66-
public AbstractCobolField() {}
67+
public AbstractCobolField() {
68+
}
6769

6870
/**
6971
* メンバ変数dataStorageのgetter
@@ -129,7 +131,8 @@ public CobolDataStorage getFieldData() {
129131
}
130132

131133
/**
132-
* opensource COBOLのCOB_FIELD_DATAに相当するメソッド バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す opensource
134+
* opensource COBOLのCOB_FIELD_DATAに相当するメソッド
135+
* バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す opensource
133136
* COBOLではポインタを返しているが,このメソッドは添え字を返す
134137
*
135138
* @return SIGN_LEADINGかつSIGN_SEPARATEなら1,それ以外は0
@@ -139,13 +142,12 @@ public int getFirstDataIndex() {
139142
}
140143

141144
public byte[] getBytes() {
142-
CobolFieldAttribute attr =
143-
new CobolFieldAttribute(
144-
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
145-
9,
146-
0,
147-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
148-
null);
145+
CobolFieldAttribute attr = new CobolFieldAttribute(
146+
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
147+
9,
148+
0,
149+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
150+
null);
149151
CobolDataStorage n = new CobolDataStorage(new byte[4], 0);
150152
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr);
151153
temp.moveFrom(this);
@@ -163,13 +165,12 @@ public byte[] getBytes() {
163165
* @return
164166
*/
165167
public int getInt() {
166-
CobolFieldAttribute attr =
167-
new CobolFieldAttribute(
168-
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
169-
9,
170-
0,
171-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
172-
null);
168+
CobolFieldAttribute attr = new CobolFieldAttribute(
169+
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
170+
9,
171+
0,
172+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
173+
null);
173174
CobolDataStorage n = new CobolDataStorage(new byte[4], 0);
174175
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr);
175176
temp.moveFrom(this);
@@ -280,7 +281,7 @@ public void setZero() {
280281
* libcob/numeric.cのcob_addの実装 thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを加算する
281282
*
282283
* @param field 加算する数値を保持するフィールド
283-
* @param opt 加算に関するオプション.詳しくはopensourceCOBOLを参照
284+
* @param opt 加算に関するオプション.詳しくはopensourceCOBOLを参照
284285
* @return 加算後のthisの保持する数値データ
285286
*/
286287
public int add(AbstractCobolField field, int opt) throws CobolStopRunException {
@@ -294,7 +295,7 @@ public int add(AbstractCobolField field, int opt) throws CobolStopRunException {
294295
* libcob/numeric.cのcob_subの実装 thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを減算する
295296
*
296297
* @param field 減算する数値を保持するフィールド
297-
* @param opt 減算に関するオプション.詳しくはopensourceCOBOLを参照
298+
* @param opt 減算に関するオプション.詳しくはopensourceCOBOLを参照
298299
* @return 減算後のthisの保持する数値データ
299300
*/
300301
public int sub(AbstractCobolField field, int opt) throws CobolStopRunException {
@@ -619,13 +620,12 @@ public void moveFrom(String s) {
619620
CobolDataStorage storage = new CobolDataStorage(bytes.length);
620621
storage.memcpy(bytes);
621622

622-
CobolFieldAttribute attr =
623-
new CobolFieldAttribute(
624-
CobolFieldAttribute.COB_TYPE_ALPHANUMERIC,
625-
bytes.length,
626-
0,
627-
0,
628-
String.format("X(%d)", bytes.length));
623+
CobolFieldAttribute attr = new CobolFieldAttribute(
624+
CobolFieldAttribute.COB_TYPE_ALPHANUMERIC,
625+
bytes.length,
626+
0,
627+
0,
628+
String.format("X(%d)", bytes.length));
629629

630630
AbstractCobolField tmp = CobolFieldFactory.makeCobolField(bytes.length, storage, attr);
631631
this.moveFrom(tmp);
@@ -647,13 +647,12 @@ public void moveFrom(int number) {
647647
storage.setByte(length - 1, (byte) (storage.getByte(length - 1) + 0x40));
648648
}
649649

650-
CobolFieldAttribute attr =
651-
new CobolFieldAttribute(
652-
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
653-
length,
654-
0,
655-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
656-
"S9(10)");
650+
CobolFieldAttribute attr = new CobolFieldAttribute(
651+
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
652+
length,
653+
0,
654+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
655+
"S9(10)");
657656

658657
AbstractCobolField tmp = CobolFieldFactory.makeCobolField(length, storage, attr);
659658
this.moveFrom(tmp);
@@ -680,13 +679,12 @@ public void moveFrom(double number) {
680679
CobolDataStorage storage = new CobolDataStorage(ss.length());
681680
storage.memcpy(ss, ss.length());
682681

683-
CobolFieldAttribute attr =
684-
new CobolFieldAttribute(
685-
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
686-
ss.length(),
687-
scale,
688-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
689-
"");
682+
CobolFieldAttribute attr = new CobolFieldAttribute(
683+
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
684+
ss.length(),
685+
scale,
686+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
687+
"");
690688

691689
AbstractCobolField tmp = CobolFieldFactory.makeCobolField(ss.length(), storage, attr);
692690
if (number < 0) {
@@ -707,7 +705,8 @@ public void moveFrom(double number) {
707705
*
708706
* @param s
709707
*/
710-
public void checkNumeric(String s) {}
708+
public void checkNumeric(String s) {
709+
}
711710

712711
// TODO abstract指定
713712
/**
@@ -840,24 +839,22 @@ private AbstractCobolField numericFieldToNumericDisplayField(AbstractCobolField
840839
CobolDataStorage data = new CobolDataStorage(48);
841840
if (attr.isTypeNumeric()) {
842841
if (!attr.isTypeNumericDisplay()) {
843-
CobolFieldAttribute newAttr =
844-
new CobolFieldAttribute(
845-
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
846-
attr.getDigits(),
847-
attr.getScale(),
848-
attr.getFlags() & (~CobolFieldAttribute.COB_FLAG_HAVE_SIGN),
849-
attr.getPic());
842+
CobolFieldAttribute newAttr = new CobolFieldAttribute(
843+
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
844+
attr.getDigits(),
845+
attr.getScale(),
846+
attr.getFlags() & (~CobolFieldAttribute.COB_FLAG_HAVE_SIGN),
847+
attr.getPic());
850848
CobolNumericField temp = new CobolNumericField(attr.getDigits(), data, newAttr);
851849
temp.moveFrom(field);
852850
field = temp;
853851
} else if (attr.isFlagHaveSign()) {
854-
CobolFieldAttribute newAttr =
855-
new CobolFieldAttribute(
856-
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
857-
attr.getDigits(),
858-
attr.getScale(),
859-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
860-
attr.getPic());
852+
CobolFieldAttribute newAttr = new CobolFieldAttribute(
853+
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
854+
attr.getDigits(),
855+
attr.getScale(),
856+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
857+
attr.getPic());
861858
CobolNumericField temp = new CobolNumericField(attr.getDigits(), data, newAttr);
862859
temp.moveFrom(field);
863860
field = temp;
@@ -1021,7 +1018,8 @@ public String toString() {
10211018
}
10221019

10231020
/**
1024-
* libcob/common.cのcob_field_to_stringの実装 TODO CobolNationalFieldでオーバーライドしなくても済むように修正する.
1021+
* libcob/common.cのcob_field_to_stringの実装 TODO
1022+
* CobolNationalFieldでオーバーライドしなくても済むように修正する.
10251023
*
10261024
* @return this.dataの保持するデータを文字列にして返す.
10271025
*/
@@ -1038,13 +1036,12 @@ public String fieldToString() {
10381036

10391037
/** libcob/move.cのcob_set_intの実装 */
10401038
public void setInt(int n) {
1041-
CobolFieldAttribute attr =
1042-
new CobolFieldAttribute(
1043-
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
1044-
9,
1045-
0,
1046-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
1047-
null);
1039+
CobolFieldAttribute attr = new CobolFieldAttribute(
1040+
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
1041+
9,
1042+
0,
1043+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
1044+
null);
10481045
CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(4).putInt(n).array());
10491046
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, data, attr);
10501047
this.moveFrom(temp);
@@ -1062,10 +1059,8 @@ public void setInt(CobolDataStorage data) {
10621059
* @param size
10631060
*/
10641061
public void memcpy(byte[] src, int size) {
1065-
CobolFieldAttribute attr =
1066-
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
1067-
AbstractCobolField temp =
1068-
CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr);
1062+
CobolFieldAttribute attr = new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
1063+
AbstractCobolField temp = CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr);
10691064
this.moveFrom(temp);
10701065
}
10711066

@@ -1262,14 +1257,13 @@ public int cmpAll(AbstractCobolField other) {
12621257
int sign = 0;
12631258

12641259
if ((this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL
1265-
|| this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL)
1260+
|| this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL)
12661261
&& this.getSize() < other.getSize()) {
12671262
int size = other.getSize();
12681263
CobolDataStorage data = other.getDataStorage();
12691264
sign = other.getSign();
12701265
CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence;
1271-
OUTSIDE:
1272-
do {
1266+
OUTSIDE: do {
12731267
while (size >= this.getSize()) {
12741268
ret = comparator.compare(this.getDataStorage(), data, this.getSize(), s);
12751269
if (ret != 0) {
@@ -1287,8 +1281,7 @@ public int cmpAll(AbstractCobolField other) {
12871281
CobolDataStorage data = this.getDataStorage();
12881282
sign = this.getSign();
12891283
CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence;
1290-
OUTSIDE:
1291-
do {
1284+
OUTSIDE: do {
12921285
while (size >= other.getSize()) {
12931286
ret = comparator.compare(data, other.getDataStorage(), other.getSize(), s);
12941287
if (ret != 0) {
@@ -1330,15 +1323,13 @@ public int cmpSimpleStr(AbstractCobolField other) {
13301323
if (ret == 0) {
13311324
if (lf.getSize() > sf.getSize()) {
13321325
if ((lf.getAttribute().getType() & CobolFieldAttribute.COB_TYPE_NATIONAL) != 0) {
1333-
ret =
1334-
CobolUtil.isNationalPadding(
1335-
lf.getDataStorage().getSubDataStorage(sf.getSize()), lf.getSize() - sf.getSize());
1326+
ret = CobolUtil.isNationalPadding(
1327+
lf.getDataStorage().getSubDataStorage(sf.getSize()), lf.getSize() - sf.getSize());
13361328
} else {
1337-
ret =
1338-
CobolUtil.commonCmpc(
1339-
lf.getDataStorage().getSubDataStorage(sf.getSize()),
1340-
(byte) ' ',
1341-
lf.getSize() - sf.getSize());
1329+
ret = CobolUtil.commonCmpc(
1330+
lf.getDataStorage().getSubDataStorage(sf.getSize()),
1331+
(byte) ' ',
1332+
lf.getSize() - sf.getSize());
13421333
}
13431334
if (this.getSize() < other.getSize()) {
13441335
ret = -ret;
@@ -1454,6 +1445,7 @@ public void realPutSign(int sign) {
14541445
} else if (sign < 0) {
14551446
p.setByte(0, (byte) (b + 0x40));
14561447
}
1448+
return;
14571449
case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED:
14581450
p = this.getDataStorage().getSubDataStorage(this.size - 1);
14591451
if (sign < 0) {
@@ -1474,13 +1466,12 @@ public void realPutSign(int sign) {
14741466
*/
14751467
public long getLong() {
14761468
long n;
1477-
CobolFieldAttribute attr =
1478-
new CobolFieldAttribute(
1479-
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
1480-
18,
1481-
0,
1482-
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
1483-
null);
1469+
CobolFieldAttribute attr = new CobolFieldAttribute(
1470+
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
1471+
18,
1472+
0,
1473+
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
1474+
null);
14841475
byte[] data = new byte[8];
14851476
CobolDataStorage storage = new CobolDataStorage(data);
14861477
AbstractCobolField field = CobolFieldFactory.makeCobolField(8, storage, attr);
@@ -1492,7 +1483,8 @@ public long getLongValue() {
14921483
return 0;
14931484
}
14941485

1495-
public void setLongValue(long n) {}
1486+
public void setLongValue(long n) {
1487+
}
14961488

14971489
/**
14981490
* libcob/move.cのcob_hankaku_moveの実装

0 commit comments

Comments
 (0)