Skip to content

Commit 6f034ab

Browse files
ar3emiText-CI
authored andcommitted
Refactor according to findbugs
1 parent aa0c588 commit 6f034ab

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

kernel/findbugs-filter.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<FindBugsFilter>
3-
<Match>
4-
<Class name="com.itextpdf.kernel.pdf.PdfCatalog"/>
5-
<Or>
6-
<Method name="setPageLayout"/>
7-
<Method name="setPageMode"/>
8-
</Or>
9-
<Bug pattern="CBC_CONTAINS_BASED_CONDITIONAL"/>
10-
</Match>
113
<Match>
124
<Or>
135
<And>
6+
<!--This class is based on the C# open source freeware library Clipper.-->
7+
<!--We want to keep it as close as possible to the original code and therefore avoid refactoring.-->
148
<Class name="com.itextpdf.kernel.pdf.canvas.parser.clipper.DefaultClipper"/>
159
<Method name="intersectEdges"/>
1610
</And>

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfCatalog.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ This file is part of the iText (R) project.
5454
import org.slf4j.LoggerFactory;
5555

5656
import java.util.ArrayList;
57+
import java.util.Arrays;
5758
import java.util.HashMap;
59+
import java.util.HashSet;
5860
import java.util.List;
5961
import java.util.Map;
62+
import java.util.Set;
6063

6164
public class PdfCatalog extends PdfObjectWrapper<PdfDictionary> {
6265

@@ -74,6 +77,14 @@ public class PdfCatalog extends PdfObjectWrapper<PdfDictionary> {
7477
//This flag determines if Outline tree of the document has been built via calling getOutlines method. If this flag is false all outline operations will be ignored
7578
private boolean outlineMode;
7679

80+
private static final Set<PdfName> PAGE_MODES = new HashSet<>(
81+
Arrays.asList(PdfName.UseNone, PdfName.UseOutlines, PdfName.UseThumbs,
82+
PdfName.FullScreen, PdfName.UseOC, PdfName.UseAttachments));
83+
84+
private static final Set<PdfName> PAGE_LAYOUTS = new HashSet<>(
85+
Arrays.asList(PdfName.SinglePage, PdfName.OneColumn, PdfName.TwoColumnLeft,
86+
PdfName.TwoColumnRight, PdfName.TwoPageLeft, PdfName.TwoPageRight));
87+
7788
protected PdfCatalog(PdfDictionary pdfObject) {
7889
super(pdfObject);
7990
if (pdfObject == null) {
@@ -161,9 +172,7 @@ public PdfCatalog setAdditionalAction(PdfName key, PdfAction action) {
161172
* @return current instance of PdfCatalog
162173
*/
163174
public PdfCatalog setPageMode(PdfName pageMode) {
164-
if (pageMode.equals(PdfName.UseNone) || pageMode.equals(PdfName.UseOutlines) ||
165-
pageMode.equals(PdfName.UseThumbs) || pageMode.equals(PdfName.FullScreen) ||
166-
pageMode.equals(PdfName.UseOC) || pageMode.equals(PdfName.UseAttachments)) {
175+
if (PAGE_MODES.contains(pageMode)) {
167176
return put(PdfName.PageMode, pageMode);
168177
}
169178
return this;
@@ -179,9 +188,7 @@ public PdfName getPageMode() {
179188
* @param pageLayout
180189
*/
181190
public PdfCatalog setPageLayout(PdfName pageLayout) {
182-
if (pageLayout.equals(PdfName.SinglePage) || pageLayout.equals(PdfName.OneColumn) ||
183-
pageLayout.equals(PdfName.TwoColumnLeft) || pageLayout.equals(PdfName.TwoColumnRight) ||
184-
pageLayout.equals(PdfName.TwoPageLeft) || pageLayout.equals(PdfName.TwoPageRight)) {
191+
if (PAGE_LAYOUTS.contains(pageLayout)) {
185192
return put(PdfName.PageLayout, pageLayout);
186193
}
187194
return this;

0 commit comments

Comments
 (0)