@@ -44,21 +44,25 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .barcodes .dmcode ;
45
45
46
46
import java .util .Arrays ;
47
- import java .util .HashMap ;
48
47
import java .util .Map ;
48
+ import java .util .concurrent .ConcurrentHashMap ;
49
49
50
50
public class Placement {
51
- private int nrow ;
52
- private int ncol ;
53
- private short [] array ;
54
- private static final Map <Integer , short []> cache = new HashMap <>();
55
-
56
- private Placement () {
51
+ private final int nrow ;
52
+ private final int ncol ;
53
+ private final short [] array ;
54
+ private static final Map <Integer , short []> cache = new ConcurrentHashMap <>();
55
+
56
+ private Placement (int nrow , int ncol ) {
57
+ this .nrow = nrow ;
58
+ this .ncol = ncol ;
59
+ array = new short [nrow * ncol ];
57
60
}
58
61
59
62
60
63
/**
61
64
* Execute the placement
65
+ *
62
66
* @param nrow number of rows
63
67
* @param ncol number of columns
64
68
* @return array containing appropriate values for ECC200
@@ -68,10 +72,7 @@ public static short[] doPlacement(int nrow, int ncol) {
68
72
short [] pc = cache .get (key );
69
73
if (pc != null )
70
74
return pc ;
71
- Placement p = new Placement ();
72
- p .nrow = nrow ;
73
- p .ncol = ncol ;
74
- p .array = new short [nrow * ncol ];
75
+ Placement p = new Placement (nrow , ncol );
75
76
p .ecc200 ();
76
77
cache .put (key , p .array );
77
78
return p .array ;
@@ -150,19 +151,19 @@ private void corner4(int chr) {
150
151
/* "ECC200" fills an nrow x ncol array with appropriate values for ECC200 */
151
152
private void ecc200 () {
152
153
int row , col , chr ;
153
- /* First, fill the array[] with invalid entries */
154
+ /* First, fill the array[] with invalid entries */
154
155
Arrays .fill (array , (short ) 0 );
155
- /* Starting in the correct location for character #1, bit 8,... */
156
+ /* Starting in the correct location for character #1, bit 8,... */
156
157
chr = 1 ;
157
158
row = 4 ;
158
159
col = 0 ;
159
160
do {
160
- /* repeatedly first check for one of the special corner cases, then... */
161
+ /* repeatedly first check for one of the special corner cases, then... */
161
162
if (row == nrow && col == 0 ) corner1 (chr ++);
162
163
if (row == nrow - 2 && col == 0 && ncol % 4 != 0 ) corner2 (chr ++);
163
164
if (row == nrow - 2 && col == 0 && ncol % 8 == 4 ) corner3 (chr ++);
164
165
if (row == nrow + 4 && col == 2 && ncol % 8 == 0 ) corner4 (chr ++);
165
- /* sweep upward diagonally, inserting successive characters,... */
166
+ /* sweep upward diagonally, inserting successive characters,... */
166
167
do {
167
168
if (row < nrow && col >= 0 && array [row * ncol + col ] == 0 )
168
169
utah (row , col , chr ++);
@@ -171,7 +172,7 @@ private void ecc200() {
171
172
} while (row >= 0 && col < ncol );
172
173
row += 1 ;
173
174
col += 3 ;
174
- /* & then sweep downward diagonally, inserting successive characters,... */
175
+ /* & then sweep downward diagonally, inserting successive characters,... */
175
176
176
177
do {
177
178
if (row >= 0 && col < ncol && array [row * ncol + col ] == 0 )
@@ -181,9 +182,9 @@ private void ecc200() {
181
182
} while (row < nrow && col >= 0 );
182
183
row += 3 ;
183
184
col += 1 ;
184
- /* ... until the entire array is scanned */
185
+ /* ... until the entire array is scanned */
185
186
} while (row < nrow || col < ncol );
186
- /* Lastly, if the lower righthand corner is untouched, fill in fixed pattern */
187
+ /* Lastly, if the lower righthand corner is untouched, fill in fixed pattern */
187
188
if (array [nrow * ncol - 1 ] == 0 ) {
188
189
array [nrow * ncol - 1 ] = array [nrow * ncol - ncol - 2 ] = 1 ;
189
190
}
0 commit comments