diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDictionary.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDictionary.java index 53d48cb8c..40e98adab 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDictionary.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDictionary.java @@ -53,6 +53,7 @@ import java.io.OutputStream; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Set; /** @@ -102,7 +103,7 @@ public class PdfDictionary extends PdfObject { private PdfName dictionaryType = null; /** This is the hashmap that contains all the values and keys of the dictionary */ - protected HashMap hashMap; + protected Map hashMap; // CONSTRUCTORS @@ -111,7 +112,7 @@ public class PdfDictionary extends PdfObject { */ public PdfDictionary() { super(DICTIONARY); - hashMap = new HashMap(); + hashMap = new HashMap(); } /** @@ -139,14 +140,10 @@ public void toPdf(PdfWriter writer, OutputStream os) throws IOException { os.write('<'); os.write('<'); // loop over all the object-pairs in the HashMap - PdfName key; - PdfObject value; - int type = 0; - for (Iterator i = hashMap.keySet().iterator(); i.hasNext(); ) { - key = (PdfName) i.next(); - value = (PdfObject) hashMap.get(key); - key.toPdf(writer, os); - type = value.type(); + for (PdfName pdfName : hashMap.keySet()) { + PdfObject value = hashMap.get(pdfName); + pdfName.toPdf(writer, os); + int type = value.type(); if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING) os.write(' '); value.toPdf(writer, os); @@ -345,8 +342,7 @@ public void merge(PdfDictionary other) { } public void mergeDifferent(PdfDictionary other) { - for (Iterator i = other.hashMap.keySet().iterator(); i.hasNext();) { - Object key = i.next(); + for (PdfName key : other.hashMap.keySet()) { if (!hashMap.containsKey(key)) hashMap.put(key, other.hashMap.get(key)); } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java index 23f9e793e..0f5c26d56 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java @@ -256,17 +256,17 @@ static class PdfCatalog extends PdfDictionary { * @param documentFileAttachment the attached files * @param writer the writer the catalog applies to */ - void addNames(TreeMap localDestinations, HashMap documentLevelJS, HashMap documentFileAttachment, PdfWriter writer) { + void addNames(TreeMap localDestinations, HashMap documentLevelJS, HashMap documentFileAttachment, PdfWriter writer) { if (localDestinations.isEmpty() && documentLevelJS.isEmpty() && documentFileAttachment.isEmpty()) return; try { PdfDictionary names = new PdfDictionary(); if (!localDestinations.isEmpty()) { PdfArray ar = new PdfArray(); - for (Iterator i = localDestinations.entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - String name = (String) entry.getKey(); - Object obj[] = (Object[]) entry.getValue(); + for (Iterator> i = localDestinations.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = i.next(); + String name = entry.getKey(); + Object obj[] = entry.getValue(); if (obj[2] == null) //no destination continue; PdfIndirectReference ref = (PdfIndirectReference)obj[1]; @@ -1161,7 +1161,7 @@ protected void initPage() throws DocumentException { currentHeight = 0; // backgroundcolors, etc... - thisBoxSize = new HashMap(boxSize); + thisBoxSize = new HashMap(boxSize); if (pageSize.getBackgroundColor() != null || pageSize.hasBorders() || pageSize.getBorderColor() != null) { @@ -1202,8 +1202,9 @@ protected void initPage() throws DocumentException { /** The line that is currently being written. */ protected PdfLine line = null; + /** The lines that are written until now. */ - protected ArrayList lines = new ArrayList(); + protected ArrayList lines = new ArrayList<>(); /** * Adds the current line to the list of lines and also adds an empty line. @@ -1226,7 +1227,7 @@ protected void newLine() throws DocumentException { protected void carriageReturn() { // the arraylist with lines may not be null if (lines == null) { - lines = new ArrayList(); + lines = new ArrayList<>(); } // If the current line is not null if (line != null) { @@ -2062,11 +2063,11 @@ void setAction(PdfAction action, float llx, float lly, float urx, float ury) { * Stores the destinations keyed by name. Value is * Object[]{PdfAction,PdfIndirectReference,PdfDestintion}. */ - protected TreeMap localDestinations = new TreeMap(); + protected TreeMap localDestinations = new TreeMap<>(); PdfAction getLocalGotoAction(String name) { PdfAction action; - Object obj[] = (Object[])localDestinations.get(name); + Object obj[] = localDestinations.get(name); if (obj == null) obj = new Object[3]; if (obj[0] == null) { @@ -2093,7 +2094,7 @@ PdfAction getLocalGotoAction(String name) { * already existed */ boolean localDestination(String name, PdfDestination destination) { - Object obj[] = (Object[])localDestinations.get(name); + Object obj[] = localDestinations.get(name); if (obj == null) obj = new Object[3]; if (obj[2] != null) @@ -2109,7 +2110,7 @@ boolean localDestination(String name, PdfDestination destination) { * Stores a list of document level JavaScript actions. */ int jsCounter; - protected HashMap documentLevelJS = new HashMap(); + protected HashMap documentLevelJS = new HashMap(); protected static final DecimalFormat SIXTEEN_DIGITS = new DecimalFormat("0000000000000000"); void addJavaScript(PdfAction js) { if (js.get(PdfName.JS) == null) @@ -2132,11 +2133,11 @@ void addJavaScript(String name, PdfAction js) { } } - HashMap getDocumentLevelJS() { + HashMap getDocumentLevelJS() { return documentLevelJS; } - protected HashMap documentFileAttachment = new HashMap(); + protected HashMap documentFileAttachment = new HashMap(); void addFileAttachment(String description, PdfFileSpecification fs) throws IOException { if (description == null) { @@ -2160,7 +2161,7 @@ void addFileAttachment(String description, PdfFileSpecification fs) throws IOExc documentFileAttachment.put(fn, fs.getReference()); } - HashMap getDocumentFileAttachment() { + HashMap getDocumentFileAttachment() { return documentFileAttachment; } @@ -2247,11 +2248,11 @@ void incMarkPoint() { protected Rectangle nextPageSize = null; /** This is the size of the several boxes of the current Page. */ - protected HashMap thisBoxSize = new HashMap(); + protected HashMap thisBoxSize = new HashMap(); /** This is the size of the several boxes that will be used in * the next page. */ - protected HashMap boxSize = new HashMap(); + protected HashMap boxSize = new HashMap(); void setCropBoxSize(Rectangle crop) { setBoxSize("crop", crop); @@ -2289,7 +2290,7 @@ protected void setNewPageSizeAndMargins() { * @param boxName crop, trim, art or bleed */ Rectangle getBoxSize(String boxName) { - PdfRectangle r = (PdfRectangle)thisBoxSize.get(boxName); + PdfRectangle r = thisBoxSize.get(boxName); if (r != null) return r.getRectangle(); return null; } @@ -2551,8 +2552,11 @@ protected static class RenderingContext { float maxCellBottom; float maxCellHeight; - Map rowspanMap; - Map pageMap = new HashMap(); + Map rowspanMap = new HashMap<>(); + + // Possible keys and values are Set or Integer. Really? + Map pageMap = new HashMap<>(); + /** * A PdfPTable */ @@ -2568,7 +2572,7 @@ public int consumeRowspan(PdfCell c) { return 1; } - Integer i = (Integer) rowspanMap.get(c); + Integer i = rowspanMap.get(c); if (i == null) { i = new Integer(c.rowspan()); } @@ -2588,7 +2592,7 @@ public int consumeRowspan(PdfCell c) { * @return the current rowspan */ public int currentRowspan(PdfCell c) { - Integer i = (Integer) rowspanMap.get(c); + Integer i = rowspanMap.get(c); if (i == null) { return c.rowspan(); } else { @@ -2599,13 +2603,13 @@ public int currentRowspan(PdfCell c) { public int cellRendered(PdfCell cell, int pageNumber) { Integer i = (Integer) pageMap.get(cell); if (i == null) { - i = new Integer(1); + i = 1; } else { - i = new Integer(i.intValue() + 1); + i = i + 1; } pageMap.put(cell, i); - Integer pageInteger = new Integer(pageNumber); + Integer pageInteger = pageNumber; Set set = (Set) pageMap.get(pageInteger); if (set == null) { @@ -2615,19 +2619,19 @@ public int cellRendered(PdfCell cell, int pageNumber) { set.add(cell); - return i.intValue(); + return i; } public int numCellRendered(PdfCell cell) { Integer i = (Integer) pageMap.get(cell); if (i == null) { - i = new Integer(0); + i = 0; } - return i.intValue(); + return i; } public boolean isCellRenderedOnPage(PdfCell cell, int pageNumber) { - Integer pageInteger = new Integer(pageNumber); + Integer pageInteger = pageNumber; Set set = (Set) pageMap.get(pageInteger); if (set != null) { @@ -2653,7 +2657,7 @@ private void addPdfTable(Table t) throws DocumentException { ctx.pagetop = indentTop(); ctx.oldHeight = currentHeight; ctx.cellGraphics = new PdfContentByte(writer); - ctx.rowspanMap = new HashMap(); + ctx.rowspanMap = new HashMap<>(); ctx.table = table; // initialization of parameters @@ -2690,7 +2694,7 @@ private void addPdfTable(Table t) throws DocumentException { // compose cells array list for subsequent code cells.clear(); - Set opt = new HashSet(); + Set opt = new HashSet<>(); iterator = rows.iterator(); while (iterator.hasNext()) { ArrayList row = (ArrayList) iterator.next(); @@ -2914,7 +2918,7 @@ protected ArrayList extractRows(ArrayList cells, RenderingContext ctx) { PdfCell cell; PdfCell previousCell = null; ArrayList rows = new ArrayList(); - java.util.List rowCells = new ArrayList(); + java.util.List rowCells = new ArrayList<>(); Iterator iterator = cells.iterator(); while (iterator.hasNext()) { @@ -2939,7 +2943,6 @@ protected ArrayList extractRows(ArrayList cells, RenderingContext ctx) { if (isEndOfRow) { if (!rowCells.isEmpty()) { - // add to rowlist rows.add(rowCells); } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayer.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayer.java index 299562e9f..ef18666ca 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayer.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayer.java @@ -58,7 +58,7 @@ */ public class PdfLayer extends PdfDictionary implements PdfOCG { protected PdfIndirectReference ref; - protected ArrayList children; + protected ArrayList children; protected PdfLayer parent; protected String title; @@ -115,7 +115,7 @@ public void addChild(PdfLayer child) { throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.layer.1.already.has.a.parent", ((PdfString)child.get(PdfName.NAME)).toUnicodeString())); child.parent = this; if (children == null) - children = new ArrayList(); + children = new ArrayList<>(); children.add(child); } @@ -132,7 +132,7 @@ public PdfLayer getParent() { * Gets the children layers. * @return the children layers or null if the layer has no children */ - public ArrayList getChildren() { + public ArrayList getChildren() { return children; } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayerMembership.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayerMembership.java index 46aaa402e..46b14915f 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayerMembership.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfLayerMembership.java @@ -49,6 +49,7 @@ import java.util.Collection; import java.util.HashSet; +import java.util.Set; /** * Content typically belongs to a single optional content group, @@ -80,7 +81,7 @@ public class PdfLayerMembership extends PdfDictionary implements PdfOCG { PdfIndirectReference ref; PdfArray members = new PdfArray(); - HashSet layers = new HashSet(); + Set layers = new HashSet<>(); /** * Creates a new, empty, membership layer. diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java index 6ca805089..fafd248b2 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java @@ -252,7 +252,7 @@ public int hashCode() { // membervariables /** array containing the cross-reference table of the normal objects. */ - private TreeSet xrefs; + private TreeSet xrefs; private int refnum; /** the current byte position in the body. */ private int position; @@ -269,7 +269,7 @@ public int hashCode() { * @param writer */ PdfBody(PdfWriter writer) { - xrefs = new TreeSet(); + xrefs = new TreeSet<>(); xrefs.add(new PdfCrossReference(0, 0, GENERATION_MAX)); position = writer.getOs().getCounter(); refnum = 1; @@ -423,7 +423,7 @@ int offset() { */ int size() { - return Math.max(((PdfCrossReference)xrefs.last()).getRefnum() + 1, refnum); + return Math.max((xrefs.last()).getRefnum() + 1, refnum); } /** @@ -444,12 +444,12 @@ void writeCrossReferenceTable(OutputStream os, PdfIndirectReference root, PdfInd refNumber = getIndirectReferenceNumber(); xrefs.add(new PdfCrossReference(refNumber, position)); } - PdfCrossReference entry = (PdfCrossReference)xrefs.first(); + PdfCrossReference entry = xrefs.first(); int first = entry.getRefnum(); int len = 0; - ArrayList sections = new ArrayList(); - for (Iterator i = xrefs.iterator(); i.hasNext(); ) { - entry = (PdfCrossReference)i.next(); + ArrayList sections = new ArrayList<>(); + for (Iterator i = xrefs.iterator(); i.hasNext(); ) { + entry = i.next(); if (first + len == entry.getRefnum()) ++len; else { @@ -471,8 +471,8 @@ void writeCrossReferenceTable(OutputStream os, PdfIndirectReference root, PdfInd } ByteBuffer buf = new ByteBuffer(); - for (Iterator i = xrefs.iterator(); i.hasNext(); ) { - entry = (PdfCrossReference) i.next(); + for (Iterator i = xrefs.iterator(); i.hasNext(); ) { + entry = i.next(); entry.toPdf(mid, buf); } PdfStream xr = new PdfStream(buf.toByteArray()); @@ -491,7 +491,7 @@ void writeCrossReferenceTable(OutputStream os, PdfIndirectReference root, PdfInd xr.put(PdfName.TYPE, PdfName.XREF); PdfArray idx = new PdfArray(); for (int k = 0; k < sections.size(); ++k) - idx.add(new PdfNumber(((Integer)sections.get(k)).intValue())); + idx.add(new PdfNumber(sections.get(k))); xr.put(PdfName.INDEX, idx); if (prevxref > 0) xr.put(PdfName.PREV, new PdfNumber(prevxref)); @@ -503,16 +503,16 @@ void writeCrossReferenceTable(OutputStream os, PdfIndirectReference root, PdfInd } else { os.write(getISOBytes("xref\n")); - Iterator i = xrefs.iterator(); + Iterator i = xrefs.iterator(); for (int k = 0; k < sections.size(); k += 2) { - first = ((Integer)sections.get(k)).intValue(); - len = ((Integer)sections.get(k + 1)).intValue(); + first = sections.get(k); + len = sections.get(k + 1); os.write(getISOBytes(String.valueOf(first))); os.write(getISOBytes(" ")); os.write(getISOBytes(String.valueOf(len))); os.write('\n'); while (len-- > 0) { - entry = (PdfCrossReference) i.next(); + entry = i.next(); entry.toPdf(os); } } @@ -940,7 +940,7 @@ public PdfDictionary getExtraCatalog() { /** The root of the page tree. */ protected PdfPages root = new PdfPages(this); /** The PdfIndirectReference to the pages. */ - protected ArrayList pageReferences = new ArrayList(); + protected ArrayList pageReferences = new ArrayList(); /** The current page number. */ protected int currentPageNumber = 1; /** @@ -986,7 +986,7 @@ public PdfIndirectReference getPageReference(int page) { throw new IndexOutOfBoundsException(MessageLocalization.getComposedMessage("the.page.number.must.be.gt.eq.1")); PdfIndirectReference ref; if (page < pageReferences.size()) { - ref = (PdfIndirectReference)pageReferences.get(page); + ref = pageReferences.get(page); if (ref == null) { ref = body.getPdfIndirectReference(); pageReferences.set(page, ref); @@ -1247,13 +1247,13 @@ public void close() { protected void addSharedObjectsToBody() throws IOException { // [F3] add the fonts - for (Iterator it = documentFonts.values().iterator(); it.hasNext();) { - FontDetails details = (FontDetails)it.next(); + for (Iterator it = documentFonts.values().iterator(); it.hasNext();) { + FontDetails details = it.next(); details.writeFont(this); } // [F4] add the form XObjects - for (Iterator it = formXObjects.values().iterator(); it.hasNext();) { - Object objs[] = (Object[])it.next(); + for (Iterator it = formXObjects.values().iterator(); it.hasNext();) { + Object objs[] = it.next(); PdfTemplate template = (PdfTemplate)objs[1]; if (template != null && template.getIndirectReference() instanceof PRIndirectReference) continue; @@ -1262,43 +1262,43 @@ protected void addSharedObjectsToBody() throws IOException { } } // [F5] add all the dependencies in the imported pages - for (Iterator it = importedPages.values().iterator(); it.hasNext();) { - currentPdfReaderInstance = (PdfReaderInstance)it.next(); + for (Iterator it = importedPages.values().iterator(); it.hasNext();) { + currentPdfReaderInstance = it.next(); currentPdfReaderInstance.writeAllPages(); } currentPdfReaderInstance = null; // [F6] add the spotcolors - for (Iterator it = documentColors.values().iterator(); it.hasNext();) { - ColorDetails color = (ColorDetails)it.next(); + for (Iterator it = documentColors.values().iterator(); it.hasNext();) { + ColorDetails color = it.next(); addToBody(color.getSpotColor(this), color.getIndirectReference()); } // [F7] add the pattern - for (Iterator it = documentPatterns.keySet().iterator(); it.hasNext();) { - PdfPatternPainter pat = (PdfPatternPainter)it.next(); + for (Iterator it = documentPatterns.keySet().iterator(); it.hasNext();) { + PdfPatternPainter pat = it.next(); addToBody(pat.getPattern(compressionLevel), pat.getIndirectReference()); } // [F8] add the shading patterns - for (Iterator it = documentShadingPatterns.keySet().iterator(); it.hasNext();) { - PdfShadingPattern shadingPattern = (PdfShadingPattern)it.next(); + for (Iterator it = documentShadingPatterns.keySet().iterator(); it.hasNext();) { + PdfShadingPattern shadingPattern = it.next(); shadingPattern.addToBody(); } // [F9] add the shadings - for (Iterator it = documentShadings.keySet().iterator(); it.hasNext();) { - PdfShading shading = (PdfShading)it.next(); + for (Iterator it = documentShadings.keySet().iterator(); it.hasNext();) { + PdfShading shading = it.next(); shading.addToBody(); } // [F10] add the extgstate - for (Iterator it = documentExtGState.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - PdfDictionary gstate = (PdfDictionary) entry.getKey(); - PdfObject obj[] = (PdfObject[]) entry.getValue(); + for (Iterator> it = documentExtGState.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = it.next(); + PdfDictionary gstate = entry.getKey(); + PdfObject obj[] = entry.getValue(); addToBody(gstate, (PdfIndirectReference)obj[1]); } // [F11] add the properties - for (Iterator it = documentProperties.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); + for (Iterator> it = documentProperties.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = it.next(); Object prop = entry.getKey(); - PdfObject[] obj = (PdfObject[]) entry.getValue(); + PdfObject[] obj = entry.getValue(); if (prop instanceof PdfLayerMembership){ PdfLayerMembership layer = (PdfLayerMembership)prop; addToBody(layer.getPdfObject(), layer.getRef()); @@ -1509,17 +1509,17 @@ public void setPageLabels(PdfPageLabels pageLabels) { * use this method in combination with PdfCopy). * @since iText 5.0 */ - public void addNamedDestinations(Map map, int page_offset) { - Map.Entry entry; + public void addNamedDestinations(Map map, int page_offset) { + Map.Entry entry; int page; String dest; PdfDestination destination; - for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) { - entry = (Map.Entry)i.next(); - dest = (String)entry.getValue(); + for (Iterator> i = map.entrySet().iterator(); i.hasNext(); ) { + entry = i.next(); + dest = entry.getValue(); page = Integer.parseInt(dest.substring(0, dest.indexOf(" "))); destination = new PdfDestination(dest.substring(dest.indexOf(" ") + 1)); - addNamedDestination((String)entry.getKey(), page + page_offset, destination); + addNamedDestination(entry.getKey(), page + page_offset, destination); } } @@ -2125,7 +2125,7 @@ public void setCompressionLevel(int compressionLevel) { // [F3] adding fonts /** The fonts of this document */ - protected LinkedHashMap documentFonts = new LinkedHashMap(); + protected LinkedHashMap documentFonts = new LinkedHashMap<>(); /** The font number counter for the fonts in the document. */ protected int fontNumber = 1; @@ -2142,7 +2142,7 @@ FontDetails addSimple(BaseFont bf) { if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf); } - FontDetails ret = (FontDetails)documentFonts.get(bf); + FontDetails ret = documentFonts.get(bf); if (ret == null) { PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf); ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf); @@ -2152,8 +2152,8 @@ FontDetails addSimple(BaseFont bf) { } void eliminateFontSubset(PdfDictionary fonts) { - for (Iterator it = documentFonts.values().iterator(); it.hasNext();) { - FontDetails ft = (FontDetails)it.next(); + for (Iterator it = documentFonts.values().iterator(); it.hasNext();) { + FontDetails ft = it.next(); if (fonts.get(ft.getFontName()) != null) ft.setSubset(false); } @@ -2163,7 +2163,7 @@ void eliminateFontSubset(PdfDictionary fonts) { /** The form XObjects in this document. The key is the xref and the value is Object[]{PdfName, template}.*/ - protected HashMap formXObjects = new HashMap(); + protected HashMap formXObjects = new HashMap(); /** The name counter for the form XObjects name. */ protected int formXObjectsCounter = 1; @@ -2177,7 +2177,7 @@ void eliminateFontSubset(PdfDictionary fonts) { PdfName addDirectTemplateSimple(PdfTemplate template, PdfName forcedName) { PdfIndirectReference ref = template.getIndirectReference(); - Object obj[] = (Object[])formXObjects.get(ref); + Object obj[] = formXObjects.get(ref); PdfName name = null; try { if (obj == null) { @@ -2217,7 +2217,7 @@ PdfName addDirectTemplateSimple(PdfTemplate template, PdfName forcedName) { */ public void releaseTemplate(PdfTemplate tp) throws IOException { PdfIndirectReference ref = tp.getIndirectReference(); - Object[] objs = (Object[])formXObjects.get(ref); + Object[] objs = formXObjects.get(ref); if (objs == null || objs[1] == null) return; PdfTemplate template = (PdfTemplate)objs[1]; @@ -2231,7 +2231,7 @@ public void releaseTemplate(PdfTemplate tp) throws IOException { // [F5] adding pages imported form other PDF documents - protected HashMap importedPages = new HashMap(); + protected HashMap importedPages = new HashMap(); /** * Use this method to get a page from other PDF document. @@ -2243,7 +2243,7 @@ public void releaseTemplate(PdfTemplate tp) throws IOException { * @return the template representing the imported page */ public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber) { - PdfReaderInstance inst = (PdfReaderInstance)importedPages.get(reader); + PdfReaderInstance inst = importedPages.get(reader); if (inst == null) { inst = reader.getPdfReaderInstance(this); importedPages.put(reader, inst); @@ -2261,7 +2261,7 @@ public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber) { * @throws IOException on error */ public void freeReader(PdfReader reader) throws IOException { - currentPdfReaderInstance = (PdfReaderInstance)importedPages.get(reader); + currentPdfReaderInstance = importedPages.get(reader); if (currentPdfReaderInstance == null) return; currentPdfReaderInstance.writeAllPages(); @@ -2295,7 +2295,7 @@ RandomAccessFileOrArray getReaderFile(PdfReader reader) { // [F6] spot colors /** The colors of this document */ - protected HashMap documentColors = new HashMap(); + protected HashMap documentColors = new HashMap(); /** The color number counter for the colors in the document. */ protected int colorNumber = 1; @@ -2311,7 +2311,7 @@ PdfName getColorspaceName() { * and position 1 is an PdfIndirectReference */ ColorDetails addSimple(PdfSpotColor spc) { - ColorDetails ret = (ColorDetails)documentColors.get(spc); + ColorDetails ret = documentColors.get(spc); if (ret == null) { ret = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), spc); documentColors.put(spc, ret); @@ -2322,13 +2322,13 @@ ColorDetails addSimple(PdfSpotColor spc) { // [F7] document patterns /** The patterns of this document */ - protected HashMap documentPatterns = new HashMap(); + protected HashMap documentPatterns = new HashMap(); /** The pattern number counter for the colors in the document. */ protected int patternNumber = 1; PdfName addSimplePattern(PdfPatternPainter painter) { - PdfName name = (PdfName)documentPatterns.get(painter); + PdfName name = documentPatterns.get(painter); try { if ( name == null ) { name = new PdfName("P" + patternNumber); @@ -2343,7 +2343,7 @@ PdfName addSimplePattern(PdfPatternPainter painter) { // [F8] shading patterns - protected HashMap documentShadingPatterns = new HashMap(); + protected HashMap documentShadingPatterns = new HashMap<>(); void addSimpleShadingPattern(PdfShadingPattern shading) { if (!documentShadingPatterns.containsKey(shading)) { @@ -2356,7 +2356,7 @@ void addSimpleShadingPattern(PdfShadingPattern shading) { // [F9] document shadings - protected HashMap documentShadings = new HashMap(); + protected HashMap documentShadings = new HashMap<>(); void addSimpleShading(PdfShading shading) { if (!documentShadings.containsKey(shading)) { @@ -2367,26 +2367,26 @@ void addSimpleShading(PdfShading shading) { // [F10] extended graphics state (for instance for transparency) - protected HashMap documentExtGState = new HashMap(); + protected HashMap documentExtGState = new HashMap(); PdfObject[] addSimpleExtGState(PdfDictionary gstate) { if (!documentExtGState.containsKey(gstate)) { PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_GSTATE, gstate); documentExtGState.put(gstate, new PdfObject[]{new PdfName("GS" + (documentExtGState.size() + 1)), getPdfIndirectReference()}); } - return (PdfObject[])documentExtGState.get(gstate); + return documentExtGState.get(gstate); } // [F11] adding properties (OCG, marked content) - protected HashMap documentProperties = new HashMap(); + protected HashMap documentProperties = new HashMap<>(); PdfObject[] addSimpleProperty(Object prop, PdfIndirectReference refi) { if (!documentProperties.containsKey(prop)) { if (prop instanceof PdfOCG) PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_LAYER, null); documentProperties.put(prop, new PdfObject[]{new PdfName("Pr" + (documentProperties.size() + 1)), refi}); } - return (PdfObject[])documentProperties.get(prop); + return documentProperties.get(prop); } boolean propertyExists(Object prop) { @@ -2460,10 +2460,10 @@ public PdfOCProperties getOCProperties() { * ON, all others must be turned OFF. * @param group the radio group */ - public void addOCGRadioGroup(ArrayList group) { + public void addOCGRadioGroup(ArrayList group) { PdfArray ar = new PdfArray(); for (int k = 0; k < group.size(); ++k) { - PdfLayer layer = (PdfLayer)group.get(k); + PdfLayer layer = group.get(k); if (layer.getTitle() == null) ar.add(layer.getRef()); } @@ -2489,14 +2489,14 @@ private static void getOCGOrder(PdfArray order, PdfLayer layer) { return; if (layer.getTitle() == null) order.add(layer.getRef()); - ArrayList children = layer.getChildren(); + ArrayList children = layer.getChildren(); if (children == null) return; PdfArray kids = new PdfArray(); if (layer.getTitle() != null) kids.add(new PdfString(layer.getTitle(), PdfObject.TEXT_UNICODE)); for (int k = 0; k < children.size(); ++k) { - getOCGOrder(kids, (PdfLayer)children.get(k)); + getOCGOrder(kids, children.get(k)); } if (kids.size() > 0) order.add(kids); @@ -2856,7 +2856,7 @@ public void setDefaultColorspace(PdfName key, PdfObject cs) { // [M2] spot patterns - protected HashMap documentSpotPatterns = new HashMap(); + protected HashMap documentSpotPatterns = new HashMap<>(); protected ColorDetails patternColorspaceRGB; protected ColorDetails patternColorspaceGRAY; protected ColorDetails patternColorspaceCMYK; @@ -2893,7 +2893,7 @@ ColorDetails addSimplePatternColorspace(Color color) { return patternColorspaceGRAY; case ExtendedColor.TYPE_SEPARATION: { ColorDetails details = addSimple(((SpotColor)color).getPdfSpotColor()); - ColorDetails patternDetails = (ColorDetails)documentSpotPatterns.get(details); + ColorDetails patternDetails = documentSpotPatterns.get(details); if (patternDetails == null) { patternDetails = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null); PdfArray array = new PdfArray(PdfName.PATTERN); @@ -2944,7 +2944,7 @@ public void clearTextWrap() throws DocumentException { protected PdfDictionary imageDictionary = new PdfDictionary(); /** This is the list with all the images in the document. */ - private HashMap images = new HashMap(); + private HashMap images = new HashMap<>(); /** * Use this method to adds an image to the document @@ -2975,7 +2975,7 @@ public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) PdfName name; // if the images is already added, just retrieve the name if (images.containsKey(image.getMySerialId())) { - name = (PdfName) images.get(image.getMySerialId()); + name = images.get(image.getMySerialId()); } // if it's a new image, add it to the document else { @@ -3002,7 +3002,7 @@ public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) Image maskImage = image.getImageMask(); PdfIndirectReference maskRef = null; if (maskImage != null) { - PdfName mname = (PdfName)images.get(maskImage.getMySerialId()); + PdfName mname = images.get(maskImage.getMySerialId()); maskRef = getImageReference(mname); } PdfImage i = new PdfImage(image, "img" + images.size(), maskRef); @@ -3094,7 +3094,7 @@ protected PdfIndirectReference add(PdfICCBased icc) { * A HashSet with Stream objects containing JBIG2 Globals * @since 2.1.5 */ - protected HashMap JBIG2Globals = new HashMap(); + protected HashMap JBIG2Globals = new HashMap(); /** * Gets an indirect reference to a JBIG2 Globals stream. * Adds the stream if it hasn't already been added to the writer. @@ -3104,10 +3104,10 @@ protected PdfIndirectReference add(PdfICCBased icc) { protected PdfIndirectReference getReferenceJBIG2Globals(byte[] content) { if (content == null) return null; PdfStream stream; - for (Iterator i = JBIG2Globals.keySet().iterator(); i.hasNext(); ) { - stream = (PdfStream) i.next(); + for (Iterator i = JBIG2Globals.keySet().iterator(); i.hasNext(); ) { + stream = i.next(); if (Arrays.equals(content, stream.getBytes())) { - return (PdfIndirectReference) JBIG2Globals.get(stream); + return JBIG2Globals.get(stream); } } stream = new PdfStream(content);