@@ -32,7 +32,9 @@ This file is part of the iText (R) project.
32
32
import java .util .ArrayList ;
33
33
import java .util .Collections ;
34
34
import java .util .Comparator ;
35
+ import java .util .HashMap ;
35
36
import java .util .List ;
37
+ import java .util .Map ;
36
38
37
39
class CollapsedTableBorders extends TableBorders {
38
40
/**
@@ -57,13 +59,17 @@ class CollapsedTableBorders extends TableBorders {
57
59
58
60
private static Comparator <Border > borderComparator = new BorderComparator ();
59
61
62
+ private final Map <Integer , List <Border >> verticalBorderComputationResult ;
63
+
60
64
// region constructors
61
65
public CollapsedTableBorders (List <CellRenderer []> rows , int numberOfColumns , Border [] tableBoundingBorders ) {
62
66
super (rows , numberOfColumns , tableBoundingBorders );
67
+ verticalBorderComputationResult = new HashMap <>();
63
68
}
64
69
65
70
public CollapsedTableBorders (List <CellRenderer []> rows , int numberOfColumns , Border [] tableBoundingBorders , int largeTableIndexOffset ) {
66
71
super (rows , numberOfColumns , tableBoundingBorders , largeTableIndexOffset );
72
+ verticalBorderComputationResult = new HashMap <>();
67
73
}
68
74
// endregion
69
75
@@ -133,16 +139,21 @@ public List<Border> getVerticalBordersCrossingTopHorizontalBorder() {
133
139
return borders ;
134
140
}
135
141
142
+
136
143
@ Override
137
144
public List <Border > getVerticalBorder (int index ) {
138
- if (index == 0 ) {
139
- List <Border > borderList = TableBorderUtil
140
- .createAndFillBorderList (null , tableBoundingBorders [3 ], verticalBorders .get (0 ).size ());
141
- return getCollapsedList (verticalBorders .get (0 ), borderList );
142
- } else if (index == numberOfColumns ) {
143
- List <Border > borderList = TableBorderUtil .createAndFillBorderList (null , tableBoundingBorders [1 ],
144
- verticalBorders .get (verticalBorders .size () - 1 ).size ());
145
- return getCollapsedList (verticalBorders .get (verticalBorders .size () - 1 ), borderList );
145
+ if (index == 0 || index == numberOfColumns ) {
146
+ if (verticalBorderComputationResult .containsKey (index )) {
147
+ return verticalBorderComputationResult .get (index );
148
+ }
149
+ final int tableBoundingBordersIndex = index == 0 ? 3 : 1 ;
150
+ List <Border > borderList = TableBorderUtil .createAndFillBorderList (
151
+ null ,
152
+ tableBoundingBorders [tableBoundingBordersIndex ],
153
+ verticalBorders .get (index ).size ());
154
+ List <Border > result = getCollapsedList (verticalBorders .get (index ), borderList );
155
+ verticalBorderComputationResult .put (index , result );
156
+ return result ;
146
157
} else {
147
158
return verticalBorders .get (index );
148
159
}
@@ -226,7 +237,7 @@ public CollapsedTableBorders setTopBorderCollapseWith(List<Border> topBorderColl
226
237
}
227
238
228
239
public CollapsedTableBorders setBottomBorderCollapseWith (List <Border > bottomBorderCollapseWith ,
229
- List <Border > verticalBordersCrossingBottomBorder ) {
240
+ List <Border > verticalBordersCrossingBottomBorder ) {
230
241
this .bottomBorderCollapseWith = new ArrayList <Border >();
231
242
if (null != bottomBorderCollapseWith ) {
232
243
this .bottomBorderCollapseWith .addAll (bottomBorderCollapseWith );
0 commit comments