diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-05-21 21:22:40 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-05-21 21:22:40 +0000 |
commit | 7eaca60a1a364ce6e232363d27823e971a992705 (patch) | |
tree | 718fc0e7ccd8c4ed50c2dcd579c4df10cc8b9581 /poi-ooxml | |
parent | cecab7f573f0cdf9ea74bedcf9b43dc535976e43 (diff) | |
download | poi-7eaca60a1a364ce6e232363d27823e971a992705.tar.gz poi-7eaca60a1a364ce6e232363d27823e971a992705.zip |
activate javadoc lint and fix errors
add signing and checksum generation
add slf4j-bridge for tests
add dependencies to ooxml-lite
fix complex enum classes
add override annotations
move gradle logic to root build
generate javadoc in its own dist directory, because JPMS complains about duplicate modules otherwise
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1890089 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
57 files changed, 421 insertions, 609 deletions
diff --git a/poi-ooxml/build.gradle b/poi-ooxml/build.gradle index fcc8d79470..0450e9464a 100644 --- a/poi-ooxml/build.gradle +++ b/poi-ooxml/build.gradle @@ -73,6 +73,11 @@ dependencies { testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.26' testImplementation 'com.google.guava:guava:30.0-jre' + // prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.30 dependency + // see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/ + testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1' + + broken "org.apache.xmlgraphics:batik-script:${batikVersion}" javadocs project(':poi') @@ -89,14 +94,6 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo final String OOXML_LITE_REPORT = '../build/ooxml-lite-report' final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)" -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - withJavadocJar() - withSourcesJar() -} - - compileJava { dependsOn 'fixBatik' } @@ -180,11 +177,6 @@ task testJar(type: Jar, dependsOn: testClasses) { } } -sourcesJar { - destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - exclude 'META-INF/services/**' -} - // based on https://github.com/moditect/moditect-gradle-plugin/issues/12 task fixBatik(type: Zip) { ant.mkdir(dir: "${buildDir}/brokenJars") @@ -223,41 +215,13 @@ test { dependsOn { testJar } - useJUnitPlatform() - doFirst { - jvmArgs = [ - '-Djava.io.tmpdir=build', - '-DPOI.testdata.path=../test-data', - '-Djava.awt.headless=true', - '-Djava.locale.providers=JRE,CLDR', - '-Duser.language=en', - '-Duser.country=US', - '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl', - "-Dversion.id=${project.version}", - '-ea', + jvmArgs += [ "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}", - - '-Djunit.jupiter.execution.parallel.enabled=true', - '-Djunit.jupiter.execution.parallel.config.strategy=fixed', - '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3' - // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM} ] if (JavaVersion.current() != JavaVersion.VERSION_1_8) { jvmArgs += [ - '-Dsun.reflect.debugModuleAccessChecks=true', - '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true', - '--illegal-access=warn', - '--add-modules', MODULE_NAME, - - // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97 - // opposed to the recommendation there, it doesn't work to add ... to the dependencies - // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1' - // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module - '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED', - '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED', - '--module-path', '../build/dist/maven/poi-ooxml-tests:' + files(TEST_MODULE_PATH).asPath, ] } @@ -267,10 +231,6 @@ test { publishing { publications { POI(MavenPublication) { - artifactId project.archivesBaseName - - from components.java - pom { name = 'Apache POI - API based on OPC and OOXML schemas' description = 'Apache POI - Java API To Access Microsoft Format Files' @@ -278,5 +238,3 @@ publishing { } } } - -generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom" diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java index 4696e71de9..7de36c588a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java @@ -196,6 +196,7 @@ public class POIXMLDocumentPart { * @throws IllegalStateException if there are more than one core document relations */ protected final void rebase(OPCPackage pkg) throws InvalidFormatException { + // TODO: check why pkg parameter is not used ??? PackageRelationshipCollection cores = packagePart.getRelationshipsByType(coreDocumentRel); if (cores.size() != 1) { @@ -240,10 +241,10 @@ public class POIXMLDocumentPart { } /** - * Returns the target {@link POIXMLDocumentPart}, where a + * Returns the target POIXMLDocumentPart, where a * {@link PackageRelationship} is set from the {@link PackagePart} of this - * {@link POIXMLDocumentPart} to the {@link PackagePart} of the target - * {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()} + * POIXMLDocumentPart to the {@link PackagePart} of the target + * POIXMLDocumentPart with a {@link PackageRelationship#getId()} * matching the given parameter value. * * @param id The relation id to look for @@ -257,8 +258,8 @@ public class POIXMLDocumentPart { /** * Returns the target {@link RelationPart}, where a * {@link PackageRelationship} is set from the {@link PackagePart} of this - * {@link POIXMLDocumentPart} to the {@link PackagePart} of the target - * {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()} + * POIXMLDocumentPart to the {@link PackagePart} of the target + * POIXMLDocumentPart with a {@link PackageRelationship#getId()} * matching the given parameter value. * * @param id The relation id to look for @@ -272,13 +273,13 @@ public class POIXMLDocumentPart { /** * Returns the first {@link PackageRelationship#getId()} of the * {@link PackageRelationship}, that sources from the {@link PackagePart} of - * this {@link POIXMLDocumentPart} to the {@link PackagePart} of the given - * parameter value.<p> + * this POIXMLDocumentPart to the {@link PackagePart} of the given + * parameter value. * <p> - * There can be multiple references to the given {@link POIXMLDocumentPart} + * There can be multiple references to the given POIXMLDocumentPart * and only the first in the order of creation is returned. * - * @param part The {@link POIXMLDocumentPart} for which the according + * @param part The POIXMLDocumentPart for which the according * relation-id shall be found. * @return The value of the {@link PackageRelationship#getId()} or null, if * parts are not related. @@ -326,7 +327,7 @@ public class POIXMLDocumentPart { /** * Remove the relation to the specified part in this package and remove the - * part, if it is no longer needed.<p> + * part, if it is no longer needed. * <p> * If there are multiple relationships to the same part, this will only * remove the first relationship in the order of creation. The removal @@ -340,7 +341,7 @@ public class POIXMLDocumentPart { /** * Remove the relation to the specified part in this package and remove the - * part, if it is no longer needed and flag is set to true.<p> + * part, if it is no longer needed and flag is set to true. * <p> * If there are multiple relationships to the same part, this will only * remove the first relationship in the order of creation. The removal @@ -358,7 +359,7 @@ public class POIXMLDocumentPart { /** * Remove the relation to the specified part in this package and remove the - * part, if it is no longer needed.<p> + * part, if it is no longer needed. * <p> * If there are multiple relationships to the same part, this will only * remove the first relationship in the order of creation. The removal @@ -413,7 +414,7 @@ public class POIXMLDocumentPart { /** * Returns the parent POIXMLDocumentPart. All parts except root have not-null parent. * - * @return the parent POIXMLDocumentPart or <code>null</code> for the root element. + * @return the parent POIXMLDocumentPart or {@code null} for the root element. */ public final POIXMLDocumentPart getParent() { return parent; @@ -719,8 +720,8 @@ public class POIXMLDocumentPart { /** * Internal method, do not use! - * <p> - * This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()} + * + * @deprecated This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()} * from {@link XWPFDocument} without reflection. It should be removed. * * @param part the part which is to be read diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/SignatureFacet.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/SignatureFacet.java index cc1a803ce6..9c82d86e4b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/SignatureFacet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/facets/SignatureFacet.java @@ -60,7 +60,6 @@ public interface SignatureFacet { * @param document the signature document to be used for imports * @param references list of reference definitions * @param objects objects to be signed/included in the signature document - * @throws XMLSignatureException */ default void preSign( SignatureInfo signatureInfo @@ -78,7 +77,6 @@ public interface SignatureFacet { * * @param signatureInfo the signature info object holding the OPCPackage and other document related data * @param document the signature document to be modified - * @throws MarshalException */ default void postSign(SignatureInfo signatureInfo, Document document) throws MarshalException { diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RevocationData.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RevocationData.java index e0bdc05623..24430c3ac1 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RevocationData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RevocationData.java @@ -48,8 +48,6 @@ public class RevocationData { /** * Adds a CRL to this revocation data set. - * - * @param encodedCrl */ public void addCRL(byte[] encodedCrl) { this.crls.add(encodedCrl); @@ -57,8 +55,6 @@ public class RevocationData { /** * Adds a CRL to this revocation data set. - * - * @param crl */ public void addCRL(X509CRL crl) { byte[] encodedCrl; @@ -73,8 +69,6 @@ public class RevocationData { /** * Adds an OCSP response to this revocation data set. - * - * @param encodedOcsp */ public void addOCSP(byte[] encodedOcsp) { this.ocsps.add(encodedOcsp); @@ -99,10 +93,10 @@ public class RevocationData { } /** - * Returns <code>true</code> if this revocation data set holds OCSP + * Returns {@code true} if this revocation data set holds OCSP * responses. * - * @return <code>true</code> if this revocation data set holds OCSP + * @return {@code true} if this revocation data set holds OCSP * responses. */ public boolean hasOCSPs() { @@ -110,18 +104,18 @@ public class RevocationData { } /** - * Returns <code>true</code> if this revocation data set holds CRLs. + * Returns {@code true} if this revocation data set holds CRLs. * - * @return <code>true</code> if this revocation data set holds CRLs. + * @return {@code true} if this revocation data set holds CRLs. */ public boolean hasCRLs() { return !this.crls.isEmpty(); } /** - * Returns <code>true</code> if this revocation data is not empty. + * Returns {@code true} if this revocation data is not empty. * - * @return <code>true</code> if this revocation data is not empty. + * @return {@code true} if this revocation data is not empty. */ public boolean hasRevocationDataEntries() { return hasOCSPs() || hasCRLs(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/TimeStampServiceValidator.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/TimeStampServiceValidator.java index e15fbd4f86..d7938e68b1 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/TimeStampServiceValidator.java +++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/TimeStampServiceValidator.java @@ -35,7 +35,6 @@ public interface TimeStampServiceValidator { /** * Validates the given certificate chain. * - * @param certificateChain * @param revocationData * the optional data container that should be filled with * revocation data that was used to validate the given diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java index 8ac25748d8..3a213bfe7f 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java @@ -141,7 +141,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * @param part * the package part holding the chart data, the content type must * be - * <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code> + * {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml} * @since POI 3.14-Beta1 */ protected XDDFChart(PackagePart part) throws IOException, XmlException { @@ -411,13 +411,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai series.plot(); XDDFDataSource<?> categoryDS = series.getCategoryData(); XDDFNumericalDataSource<? extends Number> valuesDS = series.getValuesData(); - if (categoryDS == null || valuesDS == null - || categoryDS.isCellRange() || valuesDS.isCellRange() - || categoryDS.isLiteral() || valuesDS.isLiteral()) { - // let's assume the data is already in the sheet - } else { + if (categoryDS != null && !categoryDS.isCellRange() && !categoryDS.isLiteral() && + valuesDS != null && !valuesDS.isCellRange() && !valuesDS.isLiteral()) { fillSheet(sheet, categoryDS, valuesDS); } + // otherwise let's assume the data is already in the sheet } } @@ -774,7 +772,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * @param chartFactory * factory object of POIXMLFactory (XWPFFactory/XSLFFactory) * @return return the new package part - * @throws InvalidFormatException * @since POI 4.0.0 */ private PackagePart createWorksheetPart(POIXMLRelation chartWorkbookRelation, POIXMLFactory chartFactory) @@ -787,10 +784,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai /** * this method write the XSSFWorkbook object data into embedded excel file * - * @param workbook - * XSSFworkbook object - * @throws IOException - * @throws InvalidFormatException + * @param workbook XSSFworkbook object * @since POI 4.0.0 */ public void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException { @@ -953,8 +947,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai } /** - * @param range - * @return * @since POI 4.0.0 */ public String formatRange(CellRangeAddress range) { @@ -969,12 +961,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * @since POI 4.0.0 */ private XSSFSheet getSheet() { - XSSFSheet sheet = null; try { - sheet = getWorkbook().getSheetAt(0); - } catch (InvalidFormatException | IOException ife) { + return getWorkbook().getSheetAt(0); + } catch (InvalidFormatException | IOException ignored) { + return null; } - return sheet; } /** @@ -983,7 +974,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * writing xssfworkbook object into output stream of embedded part * * @return returns the packagepart of embedded file - * @throws InvalidFormatException * @since POI 4.0.0 */ private PackagePart getWorksheetPart() throws InvalidFormatException { @@ -1006,8 +996,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai /** * @return returns the workbook object of embedded excel file - * @throws IOException - * @throws InvalidFormatException * @since POI 4.0.0 */ public XSSFWorkbook getWorkbook() throws IOException, InvalidFormatException { @@ -1087,8 +1075,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai public void replaceReferences(XSSFSheet newSheet) { for (XDDFChartData data : getChartSeries()) { for (XDDFChartData.Series series : data.series) { - XDDFDataSource newCategory = series.categoryData; - XDDFNumericalDataSource newValues = series.valuesData; + XDDFDataSource<?> newCategory = series.categoryData; + XDDFNumericalDataSource<? extends Number> newValues = series.valuesData; try { if (series.categoryData != null && series.categoryData.isReference()) { String ref = series.categoryData.getDataRangeReference(); @@ -1097,7 +1085,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai ? XDDFDataSourcesFactory.fromNumericCellRange(newSheet, rangeAddress) : XDDFDataSourcesFactory.fromStringCellRange(newSheet, rangeAddress); if (newCategory.isNumeric()) { - ((XDDFNumericalDataSource) newCategory).setFormatCode(series.categoryData.getFormatCode()); + ((XDDFNumericalDataSource<? extends Number>) newCategory).setFormatCode(series.categoryData.getFormatCode()); } } if (series.valuesData!= null && series.valuesData.isReference()) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java index 365d3f37fd..ead08bc197 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; import org.apache.poi.xddf.usermodel.XDDFFillProperties; import org.apache.poi.xddf.usermodel.XDDFLineProperties; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; @@ -81,7 +82,7 @@ public abstract class XDDFChartData { } /** - * Calls to <code>getSeries().add(series)</code> or to <code>getSeries().remove(series)</code> + * Calls to {@code getSeries().add(series)} or to {@code getSeries().remove(series)} * may corrupt the workbook. * * <p> @@ -94,9 +95,9 @@ public abstract class XDDFChartData { * </ul> * * @deprecated since POI 4.1.1 - * @return */ @Deprecated + @Removal(version = "5.3") public List<Series> getSeries() { return Collections.unmodifiableList(series); } @@ -119,18 +120,15 @@ public abstract class XDDFChartData { } /** - * This method should be implemented in every class that extends <code>XDDFChartData</code>. + * This method should be implemented in every class that extends {@code XDDFChartData}. * <p> * A typical implementation would be * - * <pre><code> - protected void removeCTSeries(int n) { - chart.removeSer(n); - } - - * </code></pre> - * - * @param n + * <pre>{@code + * protected void removeCTSeries(int n) { + * chart.removeSer(n); + * } + * }</pre> */ @Internal protected abstract void removeCTSeries(int n); @@ -195,7 +193,7 @@ public abstract class XDDFChartData { } if (cache.sizeOfPtArray() < 1) { cache.addNewPtCount().setVal(1); - cache.addNewPt().setIdx(0);; + cache.addNewPt().setIdx(0); } cache.getPtArray(0).setV(title); } @@ -255,7 +253,7 @@ public abstract class XDDFChartData { } /** - * If a data point definition with the given <code>index</code> exists, then remove it. + * If a data point definition with the given {@code index} exists, then remove it. * Otherwise do nothing. * * @param index @@ -267,19 +265,19 @@ public abstract class XDDFChartData { for (int i = 0; i < points.size(); i++) { if (points.get(i).getIdx().getVal() == index) { points.remove(i); - i = points.size(); + break; } } } /** - * If a data point definition with the given <code>index</code> exists, then return it. + * If a data point definition with the given {@code index} exists, then return it. * Otherwise create a new data point definition and return it. * * @param index * data point index. * @return - * the data point with the given <code>index</code>. + * the data point with the given {@code index}. * @since POI 5.0.1 */ public XDDFDataPoint getDataPoint(long index) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java index 0817f23592..40adadcc57 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java @@ -48,7 +48,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType; @Beta public class XDDFTextRun { - private XDDFTextParagraph _parent; + private final XDDFTextParagraph _parent; private XDDFRunProperties _properties; private CTTextLineBreak _tlb; private CTTextField _tf; @@ -320,9 +320,6 @@ public class XDDFTextRun { * <p> * The size is specified using a percentage. * Positive values indicate superscript, negative values indicate subscript. - * </p> - * - * @param offset */ public void setBaseline(Double offset) { if (offset == null) { @@ -336,9 +333,6 @@ public class XDDFTextRun { * Set whether the text in this run is formatted as superscript. * <p> * The size is specified using a percentage. - * </p> - * - * @param offset */ public void setSuperscript(Double offset) { setBaseline(offset == null ? null : Math.abs(offset)); @@ -348,9 +342,6 @@ public class XDDFTextRun { * Set whether the text in this run is formatted as subscript. * <p> * The size is specified using a percentage. - * </p> - * - * @param offset */ public void setSubscript(Double offset) { setBaseline(offset == null ? null : -Math.abs(offset)); @@ -407,7 +398,7 @@ public class XDDFTextRun { /** * @param size - * font size in points. The value <code>null</code> unsets the + * font size in points. The value {@code null} unsets the * size for this run. * <dl> * <dt>Minimum inclusive =</dt> @@ -432,7 +423,7 @@ public class XDDFTextRun { /** * Set the kerning of characters within a text run. * <p> - * The value <code>null</code> unsets the kerning for this run. + * The value {@code null} unsets the kerning for this run. * </p> * * @param kerning @@ -451,7 +442,7 @@ public class XDDFTextRun { /** * * @return the kerning of characters within a text run, - * If this attribute is omitted then returns <code>null</code>. + * If this attribute is omitted then returns {@code null}. */ public Double getCharacterKerning() { return findDefinedProperty( @@ -468,7 +459,7 @@ public class XDDFTextRun { * negative values to condense. * </p> * <p> - * The value <code>null</code> unsets the spacing for this run. + * The value {@code null} unsets the spacing for this run. * </p> * * @param spacing @@ -487,7 +478,7 @@ public class XDDFTextRun { /** * * @return the spacing between characters within a text run, - * If this attribute is omitted then returns <code>null</code>. + * If this attribute is omitted then returns {@code null}. */ public Double getCharacterSpacing() { return findDefinedProperty( diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java index 2d6f251bb4..a89e26c51e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java @@ -21,13 +21,10 @@ import java.util.Collections; import java.util.Iterator; import java.util.Map.Entry; import java.util.NoSuchElementException; -import java.util.Set; import java.util.SortedMap; /** * An iterator used to iterate over the base and master items - * - * @param <T> */ public class CombinedIterable<T> implements Iterable<T> { @@ -43,14 +40,8 @@ public class CombinedIterable<T> implements Iterable<T> { @Override public Iterator<T> iterator() { - final Iterator<Entry<Long, T>> vmasterI; - - if (_masterItems != null) { - vmasterI = _masterItems.entrySet().iterator(); - } else { - final Set<Entry<Long, T>> empty = Collections.emptySet(); - vmasterI = empty.iterator(); - } + final Iterator<Entry<Long, T>> vmasterI = (_masterItems == null) + ? Collections.emptyIterator() : _masterItems.entrySet().iterator(); return new Iterator<T>() { @@ -60,8 +51,8 @@ public class CombinedIterable<T> implements Iterable<T> { Entry<Long, T> currentMaster; // grab the iterator for both - Iterator<Entry<Long, T>> baseI = _baseItems.entrySet().iterator(); - Iterator<Entry<Long, T>> masterI = vmasterI; + final Iterator<Entry<Long, T>> baseI = _baseItems.entrySet().iterator(); + final Iterator<Entry<Long, T>> masterI = vmasterI; @Override public boolean hasNext() { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java index ba546e8f16..0fccb9e8ad 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -315,7 +315,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { /** * Walk up the inheritance tree and fetch shape properties.<p> * - * The following order of inheritance is assumed:<p> + * The following order of inheritance is assumed: * <ol> * <li>slide * <li>slideLayout diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java index 0e68bceacf..c5ec2bfd9b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java @@ -49,12 +49,12 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { HLINK(10,"Hlink"), FOLHLINK(11,"FolHlink"), UNKNOWN(-1,null); - + public static ThemeElement byId(int idx) { if (idx >= values().length || idx < 0) return UNKNOWN; return values()[idx]; } - private ThemeElement(int idx, String name) { + ThemeElement(int idx, String name) { this.idx = idx; this.name = name; } public final int idx; @@ -62,7 +62,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { } private IndexedColorMap colorMap; - private ThemeDocument theme; + private final ThemeDocument theme; /** * Create a new, empty ThemesTable @@ -72,23 +72,23 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { theme = ThemeDocument.Factory.newInstance(); theme.addNewTheme().addNewThemeElements(); } - + /** * Construct a ThemesTable. * @param part A PackagePart. - * + * * @since POI 3.14-Beta1 */ public ThemesTable(PackagePart part) throws IOException { super(part); - + try { theme = ThemeDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS); } catch(XmlException e) { throw new IOException(e.getLocalizedMessage(), e); } } - + /** * Construct a ThemesTable from an existing ThemeDocument. * @param theme A ThemeDocument. @@ -99,12 +99,11 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { /** * called from {@link StylesTable} when setting theme, used to adjust colors if a custom indexed mapping is defined - * @param colorMap */ protected void setColorMap(IndexedColorMap colorMap) { this.colorMap = colorMap; } - + /** * Convert a theme "index" (as used by fonts etc) into a color. * @param idx A theme "index" @@ -133,7 +132,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { default: return null; } - byte[] rgb = null; + byte[] rgb; if (ctColor.isSetSrgbClr()) { // Color is a regular one rgb = ctColor.getSrgbClr().getVal(); @@ -143,9 +142,9 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { } else { return null; } - return new XSSFColor(rgb, colorMap); + return new XSSFColor(rgb, colorMap); } - + /** * If the colour is based on a theme, then inherit * information (currently just colours) from it as @@ -170,10 +169,10 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes { // All done } - + /** * Write this table out as XML. - * + * * @param out The stream to write to. * @throws IOException if an error occurs while writing. */ diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java index 306b7eeb10..3f19893da8 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java @@ -49,6 +49,7 @@ final class SXSSFEvaluationSheet implements EvaluationSheet { * @see org.apache.poi.ss.formula.EvaluationSheet#isRowHidden(int) * @since POI 4.1.0 */ + @Override public boolean isRowHidden(int rowIndex) { SXSSFRow row = _xs.getRow(rowIndex); if (row == null) return false; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java index bbad20e518..c38dd70438 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java @@ -47,10 +47,11 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { * Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell */ protected abstract EvaluationCell toEvaluationCell(Cell cell); - + /** * Returns a CellValue wrapper around the supplied ValueEval instance. */ + @Override protected CellValue evaluateFormulaCellValue(Cell cell) { EvaluationCell evalCell = toEvaluationCell(cell); ValueEval eval = _bookEvaluator.evaluate(evalCell); @@ -71,7 +72,8 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator { } throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")"); } - + + @Override protected void setCellType(Cell cell, CellType cellType) { if (cell instanceof XSSFCell) { EvaluationWorkbook evaluationWorkbook = getEvaluationWorkbook(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/DefaultIndexedColorMap.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/DefaultIndexedColorMap.java index 0d2980b4b1..31865bb64b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/DefaultIndexedColorMap.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/DefaultIndexedColorMap.java @@ -23,15 +23,12 @@ import org.apache.poi.hssf.util.HSSFColor; */ public class DefaultIndexedColorMap implements IndexedColorMap { - /** - * @see org.apache.poi.xssf.usermodel.IndexedColorMap#getRGB(int) - */ + @Override public byte[] getRGB(int index) { return getDefaultRGB(index); } /** - * @param index * @return RGB bytes from HSSF default color by index */ public static byte[] getDefaultRGB(int index) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java index 5e65241e46..8364108723 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java @@ -18,7 +18,6 @@ package org.apache.poi.xssf.usermodel; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.EnumMap; @@ -343,7 +342,7 @@ public enum XSSFBuiltinTableStyle { */ private static final Map<XSSFBuiltinTableStyle, TableStyle> styleMap = new EnumMap<>(XSSFBuiltinTableStyle.class); - private XSSFBuiltinTableStyle() { + XSSFBuiltinTableStyle() { } /** @@ -357,7 +356,6 @@ public enum XSSFBuiltinTableStyle { /** * NOTE: only checks by name, not definition. * - * @param style * @return true if the style represents a built-in style, false if it is null or a custom style */ public static boolean isBuiltinStyle(TableStyle style) { @@ -423,22 +421,20 @@ public enum XSSFBuiltinTableStyle { } } - private static String styleXML(Node dxfsNode, Node tableStyleNode) throws IOException, TransformerException { + private static String styleXML(Node dxfsNode, Node tableStyleNode) throws TransformerException { // built-ins doc uses 1-based dxf indexing, Excel uses 0 based. // add a dummy node to adjust properly. dxfsNode.insertBefore(dxfsNode.getOwnerDocument().createElement("dxf"), dxfsNode.getFirstChild()); - StringBuilder sb = new StringBuilder(1024); - sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n") - .append("<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" ") - .append("xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" ") - .append("xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" ") - .append("xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" ") - .append("mc:Ignorable=\"x14ac x16r2\">\n"); - sb.append(writeToString(dxfsNode)); - sb.append(writeToString(tableStyleNode)); - sb.append("</styleSheet>"); - return sb.toString(); + return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + + "<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" " + + "xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" " + + "xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" " + + "xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" " + + "mc:Ignorable=\"x14ac x16r2\">\n" + + writeToString(dxfsNode) + + writeToString(tableStyleNode) + + "</styleSheet>"; } private static String writeToString(Node node) throws TransformerException { @@ -458,27 +454,27 @@ public enum XSSFBuiltinTableStyle { private final XSSFBuiltinTableStyle builtIn; private final TableStyle style; - /** - * @param builtIn - * @param style - */ protected XSSFBuiltinTypeStyleStyle(XSSFBuiltinTableStyle builtIn, TableStyle style) { this.builtIn = builtIn; this.style = style; } + @Override public String getName() { return style.getName(); } + @Override public int getIndex() { return builtIn.ordinal(); } + @Override public boolean isBuiltin() { return true; } + @Override public DifferentialStyleProvider getStyle(TableStyleType type) { return style.getStyle(type); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 67a7a3dbb8..1900d7705c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -49,10 +49,9 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.Removal; +import org.apache.poi.xssf.model.CalculationChain; import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.StylesTable; -import org.apache.poi.xssf.model.CalculationChain; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType; @@ -99,12 +98,12 @@ public final class XSSFCell extends CellBase { * Table of strings shared across this workbook. * If two cells contain the same string, then the cell value is the same index into SharedStringsTable */ - private SharedStringsTable _sharedStringSource; + private final SharedStringsTable _sharedStringSource; /** * Table of cell styles shared across all cells in a workbook. */ - private StylesTable _stylesSource; + private final StylesTable _stylesSource; /** * Construct a XSSFCell. @@ -127,9 +126,6 @@ public final class XSSFCell extends CellBase { _stylesSource = row.getSheet().getWorkbook().getStylesSource(); } - /** - * {@inheritDoc} - */ @Override protected SpreadsheetVersion getSpreadsheetVersion() { return SpreadsheetVersion.EXCEL2007; @@ -290,7 +286,7 @@ public final class XSSFCell extends CellBase { * </p> * @return the value of the cell as a number * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING} - * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. + * @exception NumberFormatException if the cell value isn't a parsable {@code double}. * @see DataFormatter for turning this number into a string similar to that which Excel would render this number as. */ @Override @@ -320,9 +316,6 @@ public final class XSSFCell extends CellBase { } } - /** - * {@inheritDoc} - */ @Override public void setCellValueImpl(double value) { _cell.setT(STCellType.N); @@ -385,10 +378,14 @@ public final class XSSFCell extends CellBase { } } break; - case FORMULA: - checkFormulaCachedValueType(CellType.STRING, getBaseCellType(false)); + case FORMULA: { + CellType cachedValueType = getBaseCellType(false); + if (cachedValueType != CellType.STRING) { + throw typeMismatch(CellType.STRING, cachedValueType, true); + } rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : ""); break; + } default: throw typeMismatch(CellType.STRING, cellType, false); } @@ -396,23 +393,11 @@ public final class XSSFCell extends CellBase { return rt; } - private static void checkFormulaCachedValueType(CellType expectedTypeCode, CellType cachedValueType) { - if (cachedValueType != expectedTypeCode) { - throw typeMismatch(expectedTypeCode, cachedValueType, true); - } - } - - /** - * {@inheritDoc} - */ @Override protected void setCellValueImpl(String value) { setCellValueImpl(new XSSFRichTextString(value)); } - /** - * {@inheritDoc} - */ @Override protected void setCellValueImpl(RichTextString str) { CellType cellType = getCellType(); @@ -434,7 +419,7 @@ public final class XSSFCell extends CellBase { } /** - * Return a formula for the cell, for example, <code>SUM(C4:E4)</code> + * Return a formula for the cell, for example, {@code SUM(C4:E4)} * * @return a formula for the cell * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not {@link CellType#FORMULA} @@ -517,8 +502,8 @@ public final class XSSFCell extends CellBase { * {@link FormulaEvaluator} instances based on this workbook. * </p> * - * @param formula the formula to set, e.g. <code>"SUM(C4:E4)"</code>. - * If the argument is <code>null</code> then the current formula is removed. + * @param formula the formula to set, e.g. {@code "SUM(C4:E4)"}. + * If the argument is {@code null} then the current formula is removed. * @throws org.apache.poi.ss.formula.FormulaParseException if the formula has incorrect syntax or is otherwise invalid * @throws IllegalStateException if the operation is not allowed, for example, * when the cell is a part of a multi-cell array formula @@ -657,10 +642,8 @@ public final class XSSFCell extends CellBase { * @return true if the cell is of a formula type POI can handle */ private boolean isFormulaCell() { - if ( (_cell.isSetF() && _cell.getF().getT() != STCellFormulaType.DATA_TABLE ) || getSheet().isCellInArrayFormulaContext(this)) { - return true; - } - return false; + return (_cell.isSetF() && _cell.getF().getT() != STCellFormulaType.DATA_TABLE) + || getSheet().isCellInArrayFormulaContext(this); } /** @@ -732,7 +715,7 @@ public final class XSSFCell extends CellBase { * </p> * @return the value of the cell as a date * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING} - * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. + * @exception NumberFormatException if the cell value isn't a parsable {@code double}. * @see DataFormatter for formatting this date into a string similar to how excel does. */ @Override @@ -753,7 +736,7 @@ public final class XSSFCell extends CellBase { * </p> * @return the value of the cell as a LocalDateTime * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING} - * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. + * @exception NumberFormatException if the cell value isn't a parsable {@code double}. * @see DataFormatter for formatting this date into a string similar to how excel does. */ @Override @@ -767,27 +750,18 @@ public final class XSSFCell extends CellBase { return DateUtil.getLocalDateTime(value, date1904); } - /** - * {@inheritDoc} - */ @Override protected void setCellValueImpl(Date value) { boolean date1904 = getSheet().getWorkbook().isDate1904(); setCellValue(DateUtil.getExcelDate(value, date1904)); } - /** - * {@inheritDoc} - */ @Override protected void setCellValueImpl(LocalDateTime value) { boolean date1904 = getSheet().getWorkbook().isDate1904(); setCellValue(DateUtil.getExcelDate(value, date1904)); } - /** - * {@inheritDoc} - */ @Override protected void setCellValueImpl(Calendar value) { boolean date1904 = getSheet().getWorkbook().isDate1904(); @@ -861,9 +835,6 @@ public final class XSSFCell extends CellBase { _cell.setV(error.getString()); } - /** - * {@inheritDoc} - */ @Override public void setAsActiveCell() { getSheet().setActiveCell(getAddress()); @@ -902,7 +873,6 @@ public final class XSSFCell extends CellBase { /** * Needed by bug #62834, which points out getCellFormula() expects an evaluation context or creates a new one, * so if there is one in use, it needs to be carried on through. - * @param cellType * @param evalWb BaseXSSFEvaluationWorkbook already in use, or null if a new implicit one should be used */ protected void setCellType(CellType cellType, BaseXSSFEvaluationWorkbook evalWb) { @@ -1003,7 +973,7 @@ public final class XSSFCell extends CellBase { * </p> * * @return the raw cell value as contained in the underlying CTCell bean, - * <code>null</code> for blank cells. + * {@code null} for blank cells. */ public String getRawValue() { return _cell.getV(); @@ -1034,7 +1004,7 @@ public final class XSSFCell extends CellBase { /** * Returns cell comment associated with this cell * - * @return the cell comment associated with this cell or <code>null</code> + * @return the cell comment associated with this cell or {@code null} */ @Override public XSSFComment getCellComment() { @@ -1074,7 +1044,7 @@ public final class XSSFCell extends CellBase { /** * Returns hyperlink associated with this cell * - * @return hyperlink associated with this cell or <code>null</code> if not found + * @return hyperlink associated with this cell or {@code null} if not found */ @Override public XSSFHyperlink getHyperlink() { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChart.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChart.java index e5646a41d6..0ca01fee96 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChart.java @@ -17,25 +17,31 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.xml.namespace.QName; + import org.apache.poi.ooxml.POIXMLFactory; import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.util.Removal; import org.apache.poi.xddf.usermodel.chart.XDDFChart; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.drawingml.x2006.chart.*; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrRef; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; -import javax.xml.namespace.QName; -import java.io.IOException; -import java.io.OutputStream; - -import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; - /** * Represents a SpreadsheetML Chart */ @@ -60,7 +66,7 @@ public final class XSSFChart extends XDDFChart { * @param part * the package part holding the chart data, the content type must * be - * <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code> + * {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml} * * @since POI 3.14-Beta1 */ @@ -204,8 +210,6 @@ public final class XSSFChart extends XDDFChart { /** * Set the formula expression to use for the chart title - * - * @param formula */ public void setTitleFormula(String formula) { CTTitle ctTitle; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java index 428a06ddf1..02299a2b31 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java @@ -191,8 +191,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { } /** - * @param sheet - * @param row * @return height in twips (1/20th of point) for row or default */ private static float getRowHeight(XSSFSheet sheet, int row) { @@ -208,54 +206,59 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { return cell2 != null ? cell2 : calcCell(getCell1(), size.getCx(), size.getCy()); } + @Override public short getCol1() { return (short)getCell1().getCol(); } /** * @throws NullPointerException if cell1 is null (fixed position) - * @see org.apache.poi.ss.usermodel.ClientAnchor#setCol1(int) */ + @Override public void setCol1(int col1) { cell1.setCol(col1); } + @Override public short getCol2() { return (short) getCell2().getCol(); } /** * @throws NullPointerException if cell2 is null (fixed size) - * @see org.apache.poi.ss.usermodel.ClientAnchor#setCol2(int) */ + @Override public void setCol2(int col2) { cell2.setCol(col2); } + @Override public int getRow1() { return getCell1().getRow(); } /** * @throws NullPointerException if cell1 is null (fixed position) - * @see org.apache.poi.ss.usermodel.ClientAnchor#setRow1(int) */ + @Override public void setRow1(int row1) { cell1.setRow(row1); } + @Override public int getRow2() { return getCell2().getRow(); } /** * @throws NullPointerException if cell2 is null (fixed size) - * @see org.apache.poi.ss.usermodel.ClientAnchor#setRow2(int) */ + @Override public void setRow2(int row2) { cell2.setRow(row2); } + @Override public int getDx1() { return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetColOff())); } @@ -264,10 +267,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @throws NullPointerException if cell1 is null (fixed position) * @see org.apache.poi.ss.usermodel.ChildAnchor#setDx1(int) */ + @Override public void setDx1(int dx1) { cell1.setColOff(dx1); } + @Override public int getDy1() { return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetRowOff())); } @@ -276,10 +281,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @throws NullPointerException if cell1 is null (fixed position) * @see org.apache.poi.ss.usermodel.ChildAnchor#setDy1(int) */ + @Override public void setDy1(int dy1) { cell1.setRowOff(dy1); } + @Override public int getDy2() { return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetRowOff())); } @@ -288,10 +295,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @throws NullPointerException if cell2 is null (fixed size) * @see org.apache.poi.ss.usermodel.ChildAnchor#setDy2(int) */ + @Override public void setDy2(int dy2) { cell2.setRowOff(dy2); } + @Override public int getDx2() { return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetColOff())); } @@ -300,13 +309,14 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @throws NullPointerException if cell2 is null (fixed size) * @see org.apache.poi.ss.usermodel.ChildAnchor#setDx2(int) */ + @Override public void setDx2(int dx2) { cell2.setColOff(dx2); } @Override public boolean equals(Object o) { - if (o == null || !(o instanceof XSSFClientAnchor)) return false; + if (!(o instanceof XSSFClientAnchor)) return false; XSSFClientAnchor anchor = (XSSFClientAnchor) o; return getDx1() == anchor.getDx1() && @@ -369,7 +379,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { /** * Sets the top-left absolute position of the object. To use this, "from" must be set to null. - * @param position * @since POI 3.17 beta 1 */ public void setPosition(CTPoint2D position) { @@ -387,7 +396,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { /** * Sets the size of the object. To use this, "to" must be set to null. - * @param size * @since POI 3.17 beta 1 */ public void setSize(CTPositiveSize2D size) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java index 829acbbd30..a6f21e5e7b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java @@ -51,10 +51,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType; */ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule { private final CTCfRule _cfRule; - private XSSFSheet _sh; + private final XSSFSheet _sh; - private static Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<>(); - private static Map<STCfType.Enum, ConditionFilterType> filterTypeLookup = new HashMap<>(); + private static final Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<>(); + private static final Map<STCfType.Enum, ConditionFilterType> filterTypeLookup = new HashMap<>(); static { typeLookup.put(STCfType.CELL_IS, ConditionType.CELL_VALUE_IS); typeLookup.put(STCfType.EXPRESSION, ConditionType.FORMULA); @@ -95,7 +95,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule /** * NOTE: does not set priority, so this assumes the rule will not be added to the sheet yet - * @param sh */ /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){ _cfRule = CTCfRule.Factory.newInstance(); @@ -126,12 +125,14 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule return dxf; } + @Override public int getPriority() { final int priority = _cfRule.getPriority(); // priorities start at 1, if it is less, it is undefined, use definition order in caller return priority >=1 ? priority : 0; } + @Override public boolean getStopIfTrue() { return _cfRule.getStopIfTrue(); } @@ -140,8 +141,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * Create a new border formatting structure if it does not exist, * otherwise just return existing object. * - * @return - border formatting object, never returns <code>null</code>. + * @return - border formatting object, never returns {@code null}. */ + @Override public XSSFBorderFormatting createBorderFormatting(){ CTDxf dxf = getDxf(true); CTBorder border; @@ -155,8 +157,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule } /** - * @return - border formatting object if defined, <code>null</code> otherwise + * @return - border formatting object if defined, {@code null} otherwise */ + @Override public XSSFBorderFormatting getBorderFormatting(){ CTDxf dxf = getDxf(false); if(dxf == null || !dxf.isSetBorder()) return null; @@ -168,8 +171,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * Create a new font formatting structure if it does not exist, * otherwise just return existing object. * - * @return - font formatting object, never returns <code>null</code>. + * @return - font formatting object, never returns {@code null}. */ + @Override public XSSFFontFormatting createFontFormatting(){ CTDxf dxf = getDxf(true); CTFont font; @@ -183,8 +187,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule } /** - * @return - font formatting object if defined, <code>null</code> otherwise + * @return - font formatting object if defined, {@code null} otherwise */ + @Override public XSSFFontFormatting getFontFormatting(){ CTDxf dxf = getDxf(false); if(dxf == null || !dxf.isSetFont()) return null; @@ -196,8 +201,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * Create a new pattern formatting structure if it does not exist, * otherwise just return existing object. * - * @return - pattern formatting object, never returns <code>null</code>. + * @return - pattern formatting object, never returns {@code null}. */ + @Override public XSSFPatternFormatting createPatternFormatting(){ CTDxf dxf = getDxf(true); CTFill fill; @@ -211,8 +217,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule } /** - * @return - pattern formatting object if defined, <code>null</code> otherwise + * @return - pattern formatting object if defined, {@code null} otherwise */ + @Override public XSSFPatternFormatting getPatternFormatting(){ CTDxf dxf = getDxf(false); if(dxf == null || !dxf.isSetFill()) return null; @@ -221,8 +228,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule } /** - * - * @param color * @return data bar formatting */ public XSSFDataBarFormatting createDataBarFormatting(XSSFColor color) { @@ -234,12 +239,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule _cfRule.setType(STCfType.DATA_BAR); // Ensure the right element - CTDataBar bar = null; - if (_cfRule.isSetDataBar()) { - bar = _cfRule.getDataBar(); - } else { - bar = _cfRule.addNewDataBar(); - } + CTDataBar bar = _cfRule.isSetDataBar() ? _cfRule.getDataBar() : _cfRule.addNewDataBar(); // Set the color bar.setColor(color.getCTColor()); @@ -252,6 +252,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule // Wrap and return return new XSSFDataBarFormatting(bar, _sh.getWorkbook().getStylesSource().getIndexedColors()); } + @Override public XSSFDataBarFormatting getDataBarFormatting() { if (_cfRule.isSetDataBar()) { CTDataBar bar = _cfRule.getDataBar(); @@ -270,12 +271,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule _cfRule.setType(STCfType.ICON_SET); // Ensure the right element - CTIconSet icons = null; - if (_cfRule.isSetIconSet()) { - icons = _cfRule.getIconSet(); - } else { - icons = _cfRule.addNewIconSet(); - } + CTIconSet icons = _cfRule.isSetIconSet() ? _cfRule.getIconSet() : _cfRule.addNewIconSet(); // Set the type of the icon set if (iconSet.name != null) { STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name); @@ -294,6 +290,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule // Wrap and return return new XSSFIconMultiStateFormatting(icons); } + @Override public XSSFIconMultiStateFormatting getMultiStateFormatting() { if (_cfRule.isSetIconSet()) { CTIconSet icons = _cfRule.getIconSet(); @@ -312,12 +309,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule _cfRule.setType(STCfType.COLOR_SCALE); // Ensure the right element - CTColorScale scale = null; - if (_cfRule.isSetColorScale()) { - scale = _cfRule.getColorScale(); - } else { - scale = _cfRule.addNewColorScale(); - } + CTColorScale scale = _cfRule.isSetColorScale() ? _cfRule.getColorScale() : _cfRule.addNewColorScale(); // Add a default set of thresholds and colors if (scale.sizeOfCfvoArray() == 0) { @@ -338,6 +330,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule // Wrap and return return new XSSFColorScaleFormatting(scale, _sh.getWorkbook().getStylesSource().getIndexedColors()); } + @Override public XSSFColorScaleFormatting getColorScaleFormatting() { if (_cfRule.isSetColorScale()) { CTColorScale scale = _cfRule.getColorScale(); @@ -349,8 +342,8 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule /** * Return the number format from the dxf style record if present, null if not - * @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getNumberFormat() */ + @Override public ExcelNumberFormat getNumberFormat() { CTDxf dxf = getDxf(false); if(dxf == null || !dxf.isSetNumFmt()) return null; @@ -369,12 +362,13 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule /** * Will return null if {@link #getConditionType()} != {@link ConditionType#FILTER} - * @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getConditionFilterType() */ + @Override public ConditionFilterType getConditionFilterType() { return filterTypeLookup.get(_cfRule.getType()); } + @Override public ConditionFilterData getFilterConfiguration() { return new XSSFConditionFilterData(_cfRule); } @@ -384,7 +378,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * {@link ConditionType#CELL_VALUE_IS} * <p> * MUST be a constant from {@link org.apache.poi.ss.usermodel.ComparisonOperator} - * </p> * * @return the conditional format operator */ @@ -413,13 +406,12 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * this field is the first operand of the comparison. * If type is {@link ConditionType#FORMULA}, this formula is used * to determine if the conditional formatting is applied. - * </p> * <p> * If comparison type is {@link ConditionType#FORMULA} the formula MUST be a Boolean function - * </p> * * @return the first formula */ + @Override public String getFormula1(){ return _cfRule.sizeOfFormulaArray() > 0 ? _cfRule.getFormulaArray(0) : null; } @@ -431,10 +423,12 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * * @return the second formula */ + @Override public String getFormula2(){ return _cfRule.sizeOfFormulaArray() == 2 ? _cfRule.getFormulaArray(1) : null; } + @Override public String getText() { return _cfRule.getText(); } @@ -443,6 +437,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule * Conditional format rules don't define stripes, so always 0 * @see org.apache.poi.ss.usermodel.DifferentialStyleProvider#getStripeSize() */ + @Override public int getStripeSize() { return 0; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConnector.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConnector.java index 6624d0aa27..f1d3ba8b38 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConnector.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConnector.java @@ -42,7 +42,7 @@ public final class XSSFConnector extends XSSFShape { private static CTConnector prototype; - private CTConnector ctShape; + private final CTConnector ctShape; /** * Construct a new XSSFConnector object. @@ -128,6 +128,7 @@ public final class XSSFConnector extends XSSFShape { ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type)); } + @Override protected CTShapeProperties getShapeProperties(){ return ctShape.getSpPr(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidationConstraint.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidationConstraint.java index 3dc04c2ed3..396b01d05c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidationConstraint.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidationConstraint.java @@ -36,7 +36,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { private String formula1; private String formula2; - private int validationType = -1; + private final int validationType; private int operator = -1; private String[] explicitListOfValues; @@ -73,10 +73,8 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /** * This is the constructor called using the OOXML raw data. Excel overloads formula1 to also encode explicit value lists, * so this constructor has to check for and parse that syntax. - * @param validationType - * @param operator * @param formula1 Overloaded: formula1 or list of explicit values - * @param formula2 (formula1 is a list of explicit values, this is ignored: use <code>null</code>) + * @param formula2 (formula1 is a list of explicit values, this is ignored: use {@code null}) */ public XSSFDataValidationConstraint(int validationType, int operator, String formula1, String formula2) { super(); @@ -101,6 +99,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#getExplicitListValues() */ + @Override public String[] getExplicitListValues() { return explicitListOfValues; } @@ -108,6 +107,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#getFormula1() */ + @Override public String getFormula1() { return formula1; } @@ -115,6 +115,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#getFormula2() */ + @Override public String getFormula2() { return formula2; } @@ -122,6 +123,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#getOperator() */ + @Override public int getOperator() { return operator; } @@ -129,6 +131,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#getValidationType() */ + @Override public int getValidationType() { return validationType; } @@ -136,6 +139,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[]) */ + @Override public void setExplicitListValues(String[] explicitListValues) { this.explicitListOfValues = explicitListValues; @@ -143,8 +147,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { // further, Excel has no escaping for commas in explicit lists, so we don't need to worry about that. if ( explicitListOfValues!=null && explicitListOfValues.length > 0 ) { StringBuilder builder = new StringBuilder(QUOTE); - for (int i = 0; i < explicitListValues.length; i++) { - String string = explicitListValues[i]; + for (String string : explicitListValues) { if (builder.length() > 1) { builder.append(LIST_SEPARATOR); } @@ -158,6 +161,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula1(java.lang.String) */ + @Override public void setFormula1(String formula1) { this.formula1 = removeLeadingEquals(formula1); } @@ -182,6 +186,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula2(java.lang.String) */ + @Override public void setFormula2(String formula2) { this.formula2 = removeLeadingEquals(formula2); } @@ -189,6 +194,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint { /* (non-Javadoc) * @see org.apache.poi.ss.usermodel.DataValidationConstraint#setOperator(int) */ + @Override public void setOperator(int operator) { this.operator = operator; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDxfStyleProvider.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDxfStyleProvider.java index 72fe8959a5..f161e8f65c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDxfStyleProvider.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDxfStyleProvider.java @@ -38,9 +38,7 @@ public class XSSFDxfStyleProvider implements DifferentialStyleProvider { private final int stripeSize; /** - * @param dxf * @param stripeSize 0 for non-stripe styles, > 1 for stripes - * @param colorMap */ public XSSFDxfStyleProvider(CTDxf dxf, int stripeSize, IndexedColorMap colorMap) { this.stripeSize = stripeSize; @@ -63,22 +61,27 @@ public class XSSFDxfStyleProvider implements DifferentialStyleProvider { } } + @Override public BorderFormatting getBorderFormatting() { return border; } + @Override public FontFormatting getFontFormatting() { return font; } + @Override public ExcelNumberFormat getNumberFormat() { return number; } + @Override public PatternFormatting getPatternFormatting() { return fill; } + @Override public int getStripeSize() { return stripeSize; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java index 18b663c2b3..53b9276751 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java @@ -51,17 +51,18 @@ final class XSSFEvaluationSheet implements EvaluationSheet { public int getLastRowNum() { return _xs.getLastRowNum(); } - + /* (non-Javadoc) * @see org.apache.poi.ss.formula.EvaluationSheet#isRowHidden(int) * @since POI 4.1.0 */ + @Override public boolean isRowHidden(int rowIndex) { final XSSFRow row = _xs.getRow(rowIndex); if (row == null) return false; return row.getZeroHeight(); } - + /* (non-JavaDoc), inherit JavaDoc from EvaluationWorkbook * @since POI 3.15 beta 3 */ @@ -69,7 +70,7 @@ final class XSSFEvaluationSheet implements EvaluationSheet { public void clearAllCachedResultValues() { _cellCache = null; } - + @Override public EvaluationCell getCell(int rowIndex, int columnIndex) { // shortcut evaluation if reference is outside the bounds of existing data @@ -91,10 +92,10 @@ final class XSSFEvaluationSheet implements EvaluationSheet { } } } - + final CellKey key = new CellKey(rowIndex, columnIndex); EvaluationCell evalcell = _cellCache.get(key); - + // If cache is stale, update cache with this one cell // This is a compromise between rebuilding the entire cache // (which would quickly defeat the benefit of the cache) @@ -115,17 +116,17 @@ final class XSSFEvaluationSheet implements EvaluationSheet { return evalcell; } - + private static class CellKey { private final int _row; private final int _col; private int _hash = -1; //lazily computed - + protected CellKey(int row, int col) { _row = row; _col = col; } - + @Override public int hashCode() { if ( _hash == -1 ) { @@ -133,7 +134,7 @@ final class XSSFEvaluationSheet implements EvaluationSheet { } return _hash; } - + @Override public boolean equals(Object obj) { if (!(obj instanceof CellKey)) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java index 8234793c3e..8e27980b78 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenFooter.java @@ -23,32 +23,31 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; /** * <p> - * Even page footer value. Corresponds to even printed pages. - * Even page(s) in the sheet may not be printed, for example, if the print area is specified to be - * a range such that it falls outside an even page's scope. - * If no even footer is specified, then the odd footer's value is assumed for even page footers. + * Even page footer value. Corresponds to even printed pages. + * Even page(s) in the sheet may not be printed, for example, if the print area is specified to be + * a range such that it falls outside an even page's scope. + * If no even footer is specified, then the odd footer's value is assumed for even page footers. * </p><p> * The even footer is activated by the "Different Even/Odd" Header/Footer property for the sheet. * If this property is not set, the even footer is ignored, and the odd footer is used instead. * </p><p> * Creating an even header or footer sets this property by default, so all you need to do to * get an even header or footer to display is to create one. Likewise, if both the even header - * and footer are usnset, then this property is unset, and the odd header and footer are used + * and footer are usnset, then this property is unset, and the odd header and footer are used * for even pages. * </p> */ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{ - + /** * Create an instance of XSSFEvenFooter from the supplied XML bean * @see XSSFSheet#getEvenFooter() - * @param headerFooter */ protected XSSFEvenFooter(CTHeaderFooter headerFooter) { super(headerFooter); headerFooter.setDifferentOddEven(true); } - + /** * Get the content text representing the footer * @return text @@ -57,14 +56,14 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{ public String getText() { return getHeaderFooter().getEvenFooter(); } - + /** * Set a text for the footer. If null, unset the value. If unsetting and there is no * Even Header for this sheet, the "DifferentEvenOdd" property for this sheet is * unset. - * + * * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax - * @param text - a string representing the footer. + * @param text - a string representing the footer. */ @Override public void setText(String text) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java index dfd9d179b8..45600cfc9d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFEvenHeader.java @@ -42,9 +42,8 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header { /** * Create an instance of XSSFEvenHeader from the supplied XML bean. If an even * header is created, The property "DifferentOddEven" is set for this sheet as well. - * + * * @see XSSFSheet#getEvenHeader() - * @param headerFooter */ protected XSSFEvenHeader(CTHeaderFooter headerFooter) { super(headerFooter); @@ -53,7 +52,7 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header { /** * Get the content text representing this header - * + * * @return text */ @Override @@ -65,7 +64,7 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header { * Set a text for the header. If null, unset the value. If unsetting and there is no * Even Footer for this sheet, the "DifferentEvenOdd" property for this sheet is * unset. - * + * * @see XSSFHeaderFooter to see how to create a string with Header/Footer * Formatting Syntax * @param text diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java index 4bccf9ef1e..3ce5cd5dd9 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java @@ -23,8 +23,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; /** * <p> - * First page footer content. Corresponds to first printed page. - * The first logical page in the sheet may not be printed, for example, if the print area is specified to + * First page footer content. Corresponds to first printed page. + * The first logical page in the sheet may not be printed, for example, if the print area is specified to * be a range such that it falls outside the first page's scope. * </p><p> * The first page footer is activated by the "Different First" Header/Footer property for the sheet. @@ -41,13 +41,12 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{ /** * Create an instance of XSSFFirstFooter from the supplied XML bean * @see XSSFSheet#getFirstFooter() - * @param headerFooter */ protected XSSFFirstFooter(CTHeaderFooter headerFooter) { super(headerFooter); headerFooter.setDifferentFirst(true); } - + /** * Get the content text representing the footer * @return text @@ -56,13 +55,13 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{ public String getText() { return getHeaderFooter().getFirstFooter(); } - + /** - * Set a text for the footer. If null unset the value. If unsetting this header results + * Set a text for the footer. If null unset the value. If unsetting this header results * in no First Header, or footer for the sheet, the 'differentFirst' property is unset as well. - * + * * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax - * @param text - a string representing the footer. + * @param text - a string representing the footer. */ @Override public void setText(String text) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java index 4cb2254d2f..9d7d69c370 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java @@ -22,32 +22,29 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; /** - * <p> * First page header content. Corresponds to first printed page. - * The first logical page in the sheet may not be printed, for example, if the print area is specified to + * The first logical page in the sheet may not be printed, for example, if the print area is specified to * be a range such that it falls outside the first page's scope. - * </p><p> + * <p> * The first page header is activated by the "Different First" Header/Footer property for the sheet. * If this property is not set, the first page header is ignored. - * </p><p> + * <p> * Creating a first page header or footer sets this property by default, so all you need to do to * get an first page header or footer to display is to create one. Likewise, if both the first page * header and footer are usnset, then this property is unset, and the first page header and footer * are ignored. - * </p> */ public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{ /** * Create an instance of XSSFFirstHeader from the supplied XML bean * @see XSSFSheet#getFirstHeader() - * @param headerFooter */ protected XSSFFirstHeader(CTHeaderFooter headerFooter) { super(headerFooter); headerFooter.setDifferentFirst(true); } - + /** * Get the content text representing this header * @return text @@ -56,13 +53,13 @@ public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{ public String getText() { return getHeaderFooter().getFirstHeader(); } - + /** - * Set a text for the header. If null unset the value. If unsetting this header results + * Set a text for the header. If null unset the value. If unsetting this header results * in no First Header, or footer for the sheet, the 'differentFirst' property is unset as well. - * + * * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax - * @param text - a string representing the header. + * @param text - a string representing the header. */ @Override public void setText(String text) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java index 02bfd2e9de..b39e8b7b1e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -64,7 +64,7 @@ public class XSSFFont implements Font { private IndexedColorMap _indexedColorMap; private ThemesTable _themes; - private CTFont _ctFont; + private final CTFont _ctFont; private int _index; /** @@ -113,6 +113,7 @@ public class XSSFFont implements Font { * * @return boolean - bold */ + @Override public boolean getBold() { CTBooleanProperty bold = _ctFont.sizeOfBArray() == 0 ? null : _ctFont.getBArray(0); return (bold != null && bold.getVal()); @@ -124,6 +125,7 @@ public class XSSFFont implements Font { * @return int - character-set (0-255) * @see FontCharset */ + @Override public int getCharSet() { CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0); return charset == null ? FontCharset.ANSI.getNativeId() : FontCharset.valueOf(charset.getVal()).getNativeId(); @@ -137,6 +139,7 @@ public class XSSFFont implements Font { * @return short - indexed color to use * @see IndexedColors */ + @Override public short getColor() { CTColor color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0); if (color == null) return IndexedColors.BLACK.getIndex(); @@ -194,6 +197,7 @@ public class XSSFFont implements Font { * @return short - height in 1/20ths of a point * @see #getFontHeightInPoints() */ + @Override public short getFontHeight() { return (short)(getFontHeightRaw()*Font.TWIPS_PER_POINT); } @@ -206,6 +210,7 @@ public class XSSFFont implements Font { * @return short - height in the familiar unit of measure - points * @see #getFontHeight() */ + @Override public short getFontHeightInPoints() { return (short)getFontHeightRaw(); } @@ -227,6 +232,7 @@ public class XSSFFont implements Font { * * @return String - a string representing the name of the font to use */ + @Override public String getFontName() { CTFontName name = _ctFont.sizeOfNameArray() == 0 ? null : _ctFont.getNameArray(0); return name == null ? DEFAULT_FONT_NAME : name.getVal(); @@ -237,6 +243,7 @@ public class XSSFFont implements Font { * * @return boolean - value for italic */ + @Override public boolean getItalic() { CTBooleanProperty italic = _ctFont.sizeOfIArray() == 0 ? null : _ctFont.getIArray(0); return italic != null && italic.getVal(); @@ -247,6 +254,7 @@ public class XSSFFont implements Font { * * @return boolean - value for strikeout */ + @Override public boolean getStrikeout() { CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? null : _ctFont.getStrikeArray(0); return strike != null && strike.getVal(); @@ -260,6 +268,7 @@ public class XSSFFont implements Font { * @see Font#SS_SUPER * @see Font#SS_SUB */ + @Override public short getTypeOffset() { CTVerticalAlignFontProperty vAlign = _ctFont.sizeOfVertAlignArray() == 0 ? null : _ctFont.getVertAlignArray(0); if (vAlign == null) { @@ -284,6 +293,7 @@ public class XSSFFont implements Font { * @return byte - underlining type * @see org.apache.poi.ss.usermodel.FontUnderline */ + @Override public byte getUnderline() { CTUnderlineProperty underline = _ctFont.sizeOfUArray() == 0 ? null : _ctFont.getUArray(0); if (underline != null) { @@ -298,6 +308,7 @@ public class XSSFFont implements Font { * * @param bold - boldness to use */ + @Override public void setBold(boolean bold) { if(bold){ CTBooleanProperty ctBold = _ctFont.sizeOfBArray() == 0 ? _ctFont.addNewB() : _ctFont.getBArray(0); @@ -313,6 +324,7 @@ public class XSSFFont implements Font { * @param charset - charset * @see FontCharset */ + @Override public void setCharSet(byte charset) { int cs = charset & 0xff; setCharSet(cs); @@ -324,6 +336,7 @@ public class XSSFFont implements Font { * @param charset - charset * @see FontCharset */ + @Override public void setCharSet(int charset) { FontCharset fontCharset = FontCharset.valueOf(charset); if(fontCharset != null) { @@ -336,7 +349,6 @@ public class XSSFFont implements Font { /** * set character-set to use. * - * @param charSet * @deprecated use {@link #setCharSet(FontCharset)} instead */ @Deprecated @@ -356,7 +368,6 @@ public class XSSFFont implements Font { /** * set character-set to use. * - * @param charSet * @since 5.0.0 */ public void setCharSet(FontCharset charSet) { @@ -378,6 +389,7 @@ public class XSSFFont implements Font { * @see #DEFAULT_FONT_COLOR - Note: default font color * @see IndexedColors */ + @Override public void setColor(short color) { CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0); switch (color) { @@ -415,6 +427,7 @@ public class XSSFFont implements Font { * * @param height - height in points */ + @Override public void setFontHeight(short height) { setFontHeight((double) height/Font.TWIPS_PER_POINT); } @@ -434,6 +447,7 @@ public class XSSFFont implements Font { * * @see #setFontHeight */ + @Override public void setFontHeightInPoints(short height) { setFontHeight((double)height); } @@ -459,6 +473,7 @@ public class XSSFFont implements Font { * @param name - value representing the name of the font to use * @see #DEFAULT_FONT_NAME */ + @Override public void setFontName(String name) { CTFontName fontName = _ctFont.sizeOfNameArray() == 0 ? _ctFont.addNewName() : _ctFont.getNameArray(0); fontName.setVal(name == null ? DEFAULT_FONT_NAME : name); @@ -471,6 +486,7 @@ public class XSSFFont implements Font { * * @param italic - value for italics or not */ + @Override public void setItalic(boolean italic) { if(italic){ CTBooleanProperty bool = _ctFont.sizeOfIArray() == 0 ? _ctFont.addNewI() : _ctFont.getIArray(0); @@ -487,6 +503,7 @@ public class XSSFFont implements Font { * * @param strikeout - value for strikeout or not */ + @Override public void setStrikeout(boolean strikeout) { if(strikeout) { CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? _ctFont.addNewStrike() : _ctFont.getStrikeArray(0); @@ -506,15 +523,13 @@ public class XSSFFont implements Font { * @see #SS_SUPER * @see #SS_SUB */ + @Override public void setTypeOffset(short offset) { if(offset == Font.SS_NONE){ _ctFont.setVertAlignArray(null); } else { CTVerticalAlignFontProperty offsetProperty = _ctFont.sizeOfVertAlignArray() == 0 ? _ctFont.addNewVertAlign() : _ctFont.getVertAlignArray(0); switch (offset) { - case Font.SS_NONE: - offsetProperty.setVal(STVerticalAlignRun.BASELINE); - break; case Font.SS_SUB: offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT); break; @@ -534,6 +549,7 @@ public class XSSFFont implements Font { * @param underline - underline type to use * @see FontUnderline */ + @Override public void setUnderline(byte underline) { setUnderline(FontUnderline.valueOf(underline)); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java index ccd1799955..6a6e6e1a52 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java @@ -103,6 +103,7 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { /** * Turns a XSSFCell into a XSSFEvaluationCell */ + @Override protected EvaluationCell toEvaluationCell(Cell cell) { if (!(cell instanceof XSSFCell)){ throw new IllegalArgumentException("Unexpected type of cell: " + cell.getClass() + "." + diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java index 2892e93f0d..9d53abd5dc 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java @@ -43,7 +43,7 @@ public final class XSSFGraphicFrame extends XSSFShape { private static CTGraphicalObjectFrame prototype; - private CTGraphicalObjectFrame graphicFrame; + private final CTGraphicalObjectFrame graphicFrame; /** * Construct a new XSSFGraphicFrame object. @@ -145,7 +145,8 @@ public final class XSSFGraphicFrame extends XSSFShape { * Returns the frame anchor. * @return the XSSFClientAnchor anchor this frame is attached to */ - public XSSFClientAnchor getAnchor() { + @Override + public XSSFClientAnchor getAnchor() { return (XSSFClientAnchor) anchor; } @@ -174,7 +175,7 @@ public final class XSSFGraphicFrame extends XSSFShape { /** * The low level code to insert {@code <c:chart>} tag into - * {@code<a:graphicData>}. + * {@code <a:graphicData>}. * * Here is the schema (ECMA-376): * <pre> diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java index af3f8c29fc..338d9b31f5 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHeaderFooterProperties.java @@ -25,16 +25,14 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; * All Header/Footer properties for a sheet are scoped to the sheet. This includes Different First Page, * and Different Even/Odd. These properties can be set or unset explicitly in this class. Note that while * Scale With Document and Align With Margins default to unset, Different First, and Different Even/Odd - * are updated automatically as headers and footers are added and removed. + * are updated automatically as headers and footers are added and removed. * </p> */ public class XSSFHeaderFooterProperties { - private CTHeaderFooter headerFooter; + private final CTHeaderFooter headerFooter; /** * Create an instance of XSSFHeaderFooterProperties from the supplied XML bean - * - * @param headerFooter */ public XSSFHeaderFooterProperties(CTHeaderFooter headerFooter) { this.headerFooter = headerFooter; @@ -54,58 +52,58 @@ public class XSSFHeaderFooterProperties { * returns alignWithMargins attribute */ public boolean getAlignWithMargins() { - return getHeaderFooter().isSetAlignWithMargins() ? getHeaderFooter().getAlignWithMargins() : false; + return getHeaderFooter().isSetAlignWithMargins() && getHeaderFooter().getAlignWithMargins(); } - + /** * returns differentFirst attribute */ public boolean getDifferentFirst() { - return getHeaderFooter().isSetDifferentFirst() ? getHeaderFooter().getDifferentFirst() : false; + return getHeaderFooter().isSetDifferentFirst() && getHeaderFooter().getDifferentFirst(); } - + /** * returns differentOddEven attribute */ public boolean getDifferentOddEven() { - return getHeaderFooter().isSetDifferentOddEven() ? getHeaderFooter().getDifferentOddEven() : false; + return getHeaderFooter().isSetDifferentOddEven() && getHeaderFooter().getDifferentOddEven(); } - + /** * returns scaleWithDoc attribute */ public boolean getScaleWithDoc() { - return getHeaderFooter().isSetScaleWithDoc() ? getHeaderFooter().getScaleWithDoc() : false; + return getHeaderFooter().isSetScaleWithDoc() && getHeaderFooter().getScaleWithDoc(); } - + /** * set alignWithMargins attribute */ public void setAlignWithMargins(boolean flag) { getHeaderFooter().setAlignWithMargins(flag); } - + /** * set differentFirst attribute */ public void setDifferentFirst(boolean flag) { getHeaderFooter().setDifferentFirst(flag); } - + /** * set differentOddEven attribute */ public void setDifferentOddEven(boolean flag) { getHeaderFooter().setDifferentOddEven(flag); } - + /** * set scaleWithDoc attribute */ public void setScaleWithDoc(boolean flag) { getHeaderFooter().setScaleWithDoc(flag); } - + /** * remove alignWithMargins attribute */ @@ -114,7 +112,7 @@ public class XSSFHeaderFooterProperties { getHeaderFooter().unsetAlignWithMargins(); } } - + /** * remove differentFirst attribute */ @@ -123,7 +121,7 @@ public class XSSFHeaderFooterProperties { getHeaderFooter().unsetDifferentFirst(); } } - + /** * remove differentOddEven attribute */ @@ -132,7 +130,7 @@ public class XSSFHeaderFooterProperties { getHeaderFooter().unsetDifferentOddEven(); } } - + /** * remove scaleWithDoc attribute */ diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFLineBreak.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFLineBreak.java index 99596992b9..0887656553 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFLineBreak.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFLineBreak.java @@ -38,6 +38,7 @@ class XSSFLineBreak extends XSSFTextRun { /** * Always throws IllegalStateException. You cannot change text of a line break. */ + @Override public void setText(String text){ throw new IllegalStateException("You cannot change text of a line break, it is always '\\n'"); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java index 1e2239d8d3..5cacff490e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddFooter.java @@ -23,7 +23,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; /** * Odd page footer value. Corresponds to odd printed pages. - * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be + * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be * a range such that it falls outside an odd page's scope. * */ @@ -32,12 +32,11 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{ /** * Create an instance of XSSFOddFooter from the supplied XML bean * @see XSSFSheet#getOddFooter() - * @param headerFooter */ protected XSSFOddFooter(CTHeaderFooter headerFooter) { super(headerFooter); } - + /** * Get the content text representing the footer * @return text @@ -46,11 +45,11 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{ public String getText() { return getHeaderFooter().getOddFooter(); } - + /** * Set a text for the footer. If null unset the value. * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax - * @param text - a string representing the footer. + * @param text - a string representing the footer. */ @Override public void setText(String text) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java index 1cce6e59be..d4133a94cd 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java @@ -22,8 +22,8 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; /** - * Odd page header value. Corresponds to odd printed pages. - * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be + * Odd page header value. Corresponds to odd printed pages. + * Odd page(s) in the sheet may not be printed, for example, if the print area is specified to be * a range such that it falls outside an odd page's scope. * */ @@ -32,12 +32,11 @@ public class XSSFOddHeader extends XSSFHeaderFooter implements Header{ /** * Create an instance of XSSFOddHeader from the supplied XML bean * @see XSSFSheet#getOddHeader() - * @param headerFooter */ protected XSSFOddHeader(CTHeaderFooter headerFooter) { super(headerFooter); } - + /** * Get the content text representing this header * @return text @@ -46,11 +45,11 @@ public class XSSFOddHeader extends XSSFHeaderFooter implements Header{ public String getText() { return getHeaderFooter().getOddHeader(); } - + /** * Set a text for the header. If null unset the value * @see XSSFHeaderFooter to see how to create a string with Header/Footer Formatting Syntax - * @param text - a string representing the header. + * @param text - a string representing the header. */ @Override public void setText(String text) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPicture.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPicture.java index a3fcd66719..077d21e2e4 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPicture.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPicture.java @@ -46,7 +46,7 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPictureNo public final class XSSFPicture extends XSSFShape implements Picture { private static final Logger LOG = LogManager.getLogger(XSSFPicture.class); - /** + /* * Column width measured as the number of characters of the maximum digit width of the * numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin * padding (two on each side), plus 1 pixel padding for the gridlines. @@ -63,7 +63,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { /** * This object specifies a picture object and all its properties */ - private CTPicture ctPicture; + private final CTPicture ctPicture; /** * Construct a new XSSFPicture object. This constructor is called from @@ -140,6 +140,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { * * @see #resize(double, double) */ + @Override public void resize(){ resize(Double.MAX_VALUE); } @@ -149,6 +150,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { * * @see #resize(double, double) */ + @Override public void resize(double scale) { resize(scale, scale); } @@ -159,19 +161,18 @@ public final class XSSFPicture extends XSSFShape implements Picture { * Please note, that this method works correctly only for workbooks * with the default font size (Calibri 11pt for .xlsx). * If the default font is changed the resized image can be streched vertically or horizontally. - * </p> * <p> - * <code>resize(1.0,1.0)</code> keeps the original size,<br> - * <code>resize(0.5,0.5)</code> resize to 50% of the original,<br> - * <code>resize(2.0,2.0)</code> resizes to 200% of the original.<br> + * {@code resize(1.0,1.0)} keeps the original size,<br> + * {@code resize(0.5,0.5)} resize to 50% of the original,<br> + * {@code resize(2.0,2.0)} resizes to 200% of the original.<br> * <code>resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE})</code> resizes to the dimension of the embedded image. - * </p> * * @param scaleX the amount by which the image width is multiplied relative to the original width, * when set to {@link Double#MAX_VALUE} the width of the embedded image is used * @param scaleY the amount by which the image height is multiplied relative to the original height, * when set to {@link Double#MAX_VALUE} the height of the embedded image is used */ + @Override public void resize(double scaleX, double scaleY){ XSSFClientAnchor anchor = getClientAnchor(); XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY); @@ -197,6 +198,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { * * @return XSSFClientAnchor with the preferred size for this image */ + @Override public XSSFClientAnchor getPreferredSize(){ return getPreferredSize(1); } @@ -218,6 +220,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { * @param scaleY the amount by which image height is multiplied relative to the original height. * @return XSSFClientAnchor with the preferred size for this image */ + @Override public XSSFClientAnchor getPreferredSize(double scaleX, double scaleY){ Dimension dim = ImageUtils.setPreferredSize(this, scaleX, scaleY); CTPositiveSize2D size2d = ctPicture.getSpPr().getXfrm().getExt(); @@ -250,6 +253,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { * * @return image dimension in pixels */ + @Override public Dimension getImageDimension() { XSSFPictureData picData = getPictureData(); return getImageDimension(picData.getPackagePart(), picData.getPictureType()); @@ -260,11 +264,13 @@ public final class XSSFPicture extends XSSFShape implements Picture { * * @return picture data for this shape */ + @Override public XSSFPictureData getPictureData() { String blipId = ctPicture.getBlipFill().getBlip().getEmbed(); return (XSSFPictureData)getDrawing().getRelationById(blipId); } + @Override protected CTShapeProperties getShapeProperties(){ return ctPicture.getSpPr(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFShape.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFShape.java index 8f7489434c..caf3699fb3 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFShape.java @@ -125,8 +125,6 @@ public abstract class XSSFShape implements Shape { /** * Sets the line style. - * - * @param lineStyle */ public void setLineStyle( int lineStyle ) { CTShapeProperties props = getShapeProperties(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java index f8b8486ac4..dfe5a51e59 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -32,14 +32,12 @@ import java.util.Locale; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.ss.SpreadsheetVersion; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Table; import org.apache.poi.ss.usermodel.TableStyleInfo; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Internal; -import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr; import org.apache.xmlbeans.XmlException; @@ -358,6 +356,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @return the name of the Table, if set */ + @Override public String getName() { if (name == null && ctTable.getName() != null) { setName(ctTable.getName()); @@ -383,6 +382,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * @return the table style name, if set * @since 3.17 beta 1 */ + @Override public String getStyleName() { if (styleName == null && ctTable.isSetTableStyleInfo()) { setStyleName(ctTable.getTableStyleInfo().getName()); @@ -628,7 +628,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * and {@link #getEndCellReference()}. * The next call to {@link #getStartCellReference()} and * {@link #getEndCellReference()} will synchronize the - * cell references with the underlying <code>CTTable</code>. + * cell references with the underlying {@code CTTable}. * Thus this method is inexpensive. * * @since POI 3.15 beta 3 @@ -645,7 +645,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * {@linkplain #getTotalsRowCount() totals rows}. (Note: in this version * autofiltering is ignored) * - * Returns <code>0</code> if the start or end cell references are not set. + * Returns {@code 0} if the start or end cell references are not set. * * Does not track updates to underlying changes to CTTable To synchronize * with changes to the underlying CTTable, call {@link #updateReferences()}. @@ -667,7 +667,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * Get the number of data rows in this table. This does not include any * header rows or totals rows. * - * Returns <code>0</code> if the start or end cell references are not set. + * Returns {@code 0} if the start or end cell references are not set. * * Does not track updates to underlying changes to CTTable To synchronize * with changes to the underlying CTTable, call {@link #updateReferences()}. @@ -821,9 +821,9 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { } /** - * Gets the relative column index of a column in this table having the header name <code>column</code>. + * Gets the relative column index of a column in this table having the header name {@code column}. * The column index is relative to the left-most column in the table, 0-indexed. - * Returns <code>-1</code> if <code>column</code> is not a header name in table. + * Returns {@code -1} if {@code column} is not a header name in table. * * Column Header names are case-insensitive * @@ -832,6 +832,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * * @since 3.15 beta 2 */ + @Override public int findColumnIndex(String columnHeader) { if (columnHeader == null) return -1; if (columnMap == null) { @@ -849,12 +850,13 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { // Table column names with special characters need a single quote escape // but the escape is not present in the column definition Integer idx = columnMap.get(caseInsensitive(columnHeader.replace("'", ""))); - return idx == null ? -1 : idx.intValue(); + return idx == null ? -1 : idx; } /** * @since 3.15 beta 2 */ + @Override public String getSheetName() { return getXSSFSheet().getSheetName(); } @@ -866,6 +868,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * @since 3.15 beta 2 * @see #getTotalsRowCount() */ + @Override public boolean isHasTotalsRow() { return ctTable.getTotalsRowShown(); } @@ -876,6 +879,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * doesn't define how they would be implemented. * @since 3.17 beta 1 */ + @Override public int getTotalsRowCount() { return (int) ctTable.getTotalsRowCount(); } @@ -885,6 +889,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * Values > 1 might be used by Excel for pivot tables? * @since 3.17 beta 1 */ + @Override public int getHeaderRowCount() { return (int) ctTable.getHeaderRowCount(); } @@ -892,6 +897,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @since 3.15 beta 2 */ + @Override public int getStartColIndex() { return getStartCellReference().getCol(); } @@ -899,6 +905,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @since 3.15 beta 2 */ + @Override public int getStartRowIndex() { return getStartCellReference().getRow(); } @@ -906,6 +913,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @since 3.15 beta 2 */ + @Override public int getEndColIndex() { return getEndCellReference().getCol(); } @@ -913,6 +921,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @since 3.15 beta 2 */ + @Override public int getEndRowIndex() { return getEndCellReference().getRow(); } @@ -920,6 +929,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @since 3.17 beta 1 */ + @Override public TableStyleInfo getStyle() { if (! ctTable.isSetTableStyleInfo()) return null; return new XSSFTableStyleInfo(((XSSFSheet) getParent()).getWorkbook().getStylesSource(), ctTable.getTableStyleInfo()); @@ -929,18 +939,16 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * @see org.apache.poi.ss.usermodel.Table#contains(org.apache.poi.ss.usermodel.Cell) * @since 3.17 beta 1 */ + @Override public boolean contains(CellReference cell) { if (cell == null) return false; // check if cell is on the same sheet as the table if ( ! getSheetName().equals(cell.getSheetName())) return false; // check if the cell is inside the table - if (cell.getRow() >= getStartRowIndex() + return cell.getRow() >= getStartRowIndex() && cell.getRow() <= getEndRowIndex() && cell.getCol() >= getStartColIndex() - && cell.getCol() <= getEndColIndex()) { - return true; - } - return false; + && cell.getCol() <= getEndColIndex(); } /** diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java index 852f91c62d..6497f727b4 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java @@ -49,8 +49,6 @@ public class XSSFTableStyle implements TableStyle { /** * @param index style definition index or built-in ordinal depending on use - * @param dxfs - * @param tableStyle * @param colorMap indexed color map - default or custom * @see TableStyle#getIndex() */ @@ -99,10 +97,12 @@ public class XSSFTableStyle implements TableStyle { } } + @Override public String getName() { return name; } + @Override public int getIndex() { return index; } @@ -110,10 +110,12 @@ public class XSSFTableStyle implements TableStyle { /** * Always false for these, these are user defined styles */ + @Override public boolean isBuiltin() { return false; } + @Override public DifferentialStyleProvider getStyle(TableStyleType type) { return elementMap.get(type); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyleInfo.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyleInfo.java index fc515e6edb..39b7991e8f 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyleInfo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTableStyleInfo.java @@ -33,11 +33,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { private boolean rowStripes; private boolean firstColumn; private boolean lastColumn; - - /** - * @param stylesTable - * @param tableStyleInfo - */ + public XSSFTableStyleInfo(StylesTable stylesTable, CTTableStyleInfo tableStyleInfo) { this.columnStripes = tableStyleInfo.getShowColumnStripes(); this.rowStripes = tableStyleInfo.getShowRowStripes(); @@ -48,6 +44,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { this.styleInfo = tableStyleInfo; } + @Override public boolean isShowColumnStripes() { return columnStripes; } @@ -56,6 +53,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { styleInfo.setShowColumnStripes(show); } + @Override public boolean isShowRowStripes() { return rowStripes; } @@ -64,6 +62,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { styleInfo.setShowRowStripes(show); } + @Override public boolean isShowFirstColumn() { return firstColumn; } @@ -72,6 +71,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { styleInfo.setShowFirstColumn(showFirstColumn); } + @Override public boolean isShowLastColumn() { return lastColumn; } @@ -80,6 +80,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { styleInfo.setShowLastColumn(showLastColumn); } + @Override public String getName() { return style.getName(); } @@ -88,6 +89,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo { style = stylesTable.getTableStyle(name); } + @Override public TableStyle getStyle() { return style; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java index 1809e16cd5..0dfa82149e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java @@ -91,7 +91,7 @@ public class XSSFTextRun { /** * * @param fontSize font size in points. - * The value of <code>-1</code> unsets the Sz attribute from the underlying xml bean + * The value of {@code -1} unsets the Sz attribute from the underlying xml bean */ public void setFontSize(double fontSize){ CTTextCharacterProperties rPr = getRPr(); @@ -158,7 +158,7 @@ public class XSSFTextRun { * Specifies the typeface, or name of the font that is to be used for this text run. * * @param typeface the font to apply to this text run. - * The value of <code>null</code> unsets the Typeface attribute from the underlying xml. + * The value of {@code null} unsets the Typeface attribute from the underlying xml. */ public void setFont(String typeface){ setFontFamily(typeface, (byte)-1, (byte)-1, false); @@ -241,9 +241,6 @@ public class XSSFTextRun { * <p> * The size is specified using a percentage. * Positive values indicate superscript, negative values indicate subscript. - * </p> - * - * @param baselineOffset */ public void setBaselineOffset(double baselineOffset){ getRPr().setBaseline((int) baselineOffset * 1000); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVBAPart.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVBAPart.java index b5efa0951a..8aeb3a689b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVBAPart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVBAPart.java @@ -33,18 +33,19 @@ public class XSSFVBAPart extends POIXMLDocumentPart { * Construct XSSFVBAPart from a package part * * @param part the package part holding the VBA data, - * + * * @since POI 3.14-Beta1 */ protected XSSFVBAPart(PackagePart part) { super(part); } - + /** * Like *PictureData, VBA objects store the actual content in the part * directly without keeping a copy like all others therefore we need to * handle them differently. */ + @Override protected void prepareForCommit() { // do not clear the part here } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java index b404ac4618..2872c3ff16 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.java @@ -121,15 +121,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; * */ public abstract class XSSFHeaderFooter implements HeaderFooter { - private HeaderFooterHelper helper; - private CTHeaderFooter headerFooter; + private final HeaderFooterHelper helper; + private final CTHeaderFooter headerFooter; private boolean stripFields; /** * Create an instance of XSSFAbstractHeaderFooter from the supplied XML bean - * - * @param headerFooter */ public XSSFHeaderFooter(CTHeaderFooter headerFooter) { this.headerFooter = headerFooter; @@ -160,7 +158,7 @@ public abstract class XSSFHeaderFooter implements HeaderFooter { /** * Are fields currently being stripped from the text that this - * {@link XSSFHeaderFooter} returns? Default is false, but can be changed + * XSSFHeaderFooter returns? Default is false, but can be changed */ public boolean areFieldsStripped() { return stripFields; @@ -169,8 +167,6 @@ public abstract class XSSFHeaderFooter implements HeaderFooter { /** * Should fields (eg macros) be stripped from the text that this class * returns? Default is not to strip. - * - * @param stripFields */ public void setAreFieldsStripped(boolean stripFields) { this.stripFields = stripFields; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java index 3799f6c6d7..36ed86d912 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java @@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel.helpers; -import java.util.Iterator; import java.util.List; import org.apache.poi.ooxml.POIXMLDocumentPart; @@ -59,11 +58,9 @@ public final class XSSFFormulaUtils { * Update sheet name in all charts, formulas and named ranges. * Called from {@link XSSFWorkbook#setSheetName(int, String)} * <p> - * <p> * The idea is to parse every formula and render it back to string * with the updated sheet name. This is done by parsing into Ptgs, * looking for ones with sheet references in them, and changing those - * </p> * * @param sheetIndex the 0-based index of the sheet being changed * @param oldName the old sheet name @@ -93,9 +90,7 @@ public final class XSSFFormulaUtils { for (POIXMLDocumentPart r : rels) { if (r instanceof XSSFDrawing) { XSSFDrawing dg = (XSSFDrawing) r; - Iterator<XSSFChart> it = dg.getCharts().iterator(); - while (it.hasNext()) { - XSSFChart chart = it.next(); + for (XSSFChart chart : dg.getCharts()) { Node dom = chart.getCTChartSpace().getDomNode(); updateDomSheetReference(dom, oldName, newName); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IBody.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IBody.java index 3c8be00a0f..dd80502fe5 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IBody.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/IBody.java @@ -41,7 +41,7 @@ public interface IBody { * * @return the Part, to which the body belongs */ - public POIXMLDocumentPart getPart(); + POIXMLDocumentPart getPart(); /** * get the PartType of the body, for example @@ -49,26 +49,26 @@ public interface IBody { * * @return the PartType of the body */ - public BodyType getPartType(); + BodyType getPartType(); /** * Returns an Iterator with paragraphs and tables, * in the order that they occur in the text. */ - public List<IBodyElement> getBodyElements(); + List<IBodyElement> getBodyElements(); /** * Returns the paragraph(s) that holds * the text of the header or footer. */ - public List<XWPFParagraph> getParagraphs(); + List<XWPFParagraph> getParagraphs(); /** * Return the table(s) that holds the text * of the IBodyPart, for complex cases * where a paragraph isn't used. */ - public List<XWPFTable> getTables(); + List<XWPFTable> getTables(); /** * Returns the paragraph corresponding to the provided {@link CTP}. @@ -77,58 +77,47 @@ public interface IBody { * @return The paragraph corresponding to the {@link CTP}, or {@code null} if there is no corresponding paragraph in * this body. */ - public XWPFParagraph getParagraph(CTP p); + XWPFParagraph getParagraph(CTP p); /** * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header * the method will return this table * if there is no corresponding {@link XWPFTable} the method will return null - * - * @param ctTable */ - public XWPFTable getTable(CTTbl ctTable); + XWPFTable getTable(CTTbl ctTable); /** * Returns the paragraph that of position pos */ - public XWPFParagraph getParagraphArray(int pos); + XWPFParagraph getParagraphArray(int pos); /** * Returns the table at position pos */ - public XWPFTable getTableArray(int pos); + XWPFTable getTableArray(int pos); /** * inserts a new paragraph at position of the cursor - * - * @param cursor */ - public XWPFParagraph insertNewParagraph(XmlCursor cursor); + XWPFParagraph insertNewParagraph(XmlCursor cursor); /** * inserts a new Table at the cursor position. - * - * @param cursor */ - public XWPFTable insertNewTbl(XmlCursor cursor); + XWPFTable insertNewTbl(XmlCursor cursor); /** * inserts a new Table at position pos - * - * @param pos - * @param table */ void insertTable(int pos, XWPFTable table); /** * returns the TableCell to which the Table belongs - * - * @param cell */ - public XWPFTableCell getTableCell(CTTc cell); + XWPFTableCell getTableCell(CTTc cell); /** * Return XWPFDocument */ - public XWPFDocument getXWPFDocument(); + XWPFDocument getXWPFDocument(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/ISDTContent.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/ISDTContent.java index d0c185e888..5536043c82 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/ISDTContent.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/ISDTContent.java @@ -17,18 +17,17 @@ package org.apache.poi.xwpf.usermodel; +import org.apache.poi.util.Beta; + /** * Experimental interface to offer rudimentary read-only processing of * of the contentblock of an SDT/ContentControl. - * <p> - * <p> - * <p> - * WARNING - APIs expected to change rapidly */ +@Beta public interface ISDTContent { - public String getText(); + String getText(); - public String toString(); + String toString(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java index 495cde1bf9..126a553f36 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java @@ -68,7 +68,7 @@ public class XWPFChart extends XDDFChart { * Construct a chart from a package part. * * @param part the package part holding the chart data, - * the content type must be <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code> + * the content type must be {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml} * @since POI 4.0.0 */ protected XWPFChart(PackagePart part) throws IOException, XmlException { @@ -105,30 +105,7 @@ public class XWPFChart extends XDDFChart { @Override public boolean equals(Object obj) { - /** - * In case two objects ARE equal, but its not the same instance, this - * implementation will always run through the whole - * byte-array-comparison before returning true. If this will turn into a - * performance issue, two possible approaches are available:<br> - * a) Use the checksum only and take the risk that two images might have - * the same CRC32 sum, although they are not the same.<br> - * b) Use a second (or third) checksum algorithm to minimise the chance - * that two images have the same checksums but are not equal (e.g. - * CRC32, MD5 and SHA-1 checksums, additionally compare the - * data-byte-array lengths). - */ - if (obj == this) { - return true; - } - - if (obj == null) { - return false; - } - - if (!(obj instanceof XWPFChart)) { - return false; - } - return false; + return obj == this; } @Override @@ -141,8 +118,6 @@ public class XWPFChart extends XDDFChart { * * @param chartRelId the relation id of this chart in its parent document. * @param run the text run to which this chart will be inlined. - * @throws InvalidFormatException - * @throws IOException * @since POI 4.0.0 */ protected void attach(String chartRelId, XWPFRun run) @@ -215,7 +190,6 @@ public class XWPFChart extends XDDFChart { /** * get margin from Top * - * @param margin * @since POI 4.0.0 */ public long getChartTopMargin(long margin) { @@ -235,7 +209,6 @@ public class XWPFChart extends XDDFChart { /** * get margin from Bottom * - * @param margin * @since POI 4.0.0 */ public long getChartBottomMargin(long margin) { @@ -255,7 +228,6 @@ public class XWPFChart extends XDDFChart { /** * get margin from left * - * @param margin * @since POI 4.0.0 */ public long getChartLeftMargin(long margin) { @@ -275,7 +247,6 @@ public class XWPFChart extends XDDFChart { /** * get margin from Right * - * @param margin * @since POI 4.0.0 */ public long getChartRightMargin(long margin) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java index 49cbb08976..2d5fea4fbb 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java @@ -47,8 +47,8 @@ import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; public class XWPFComments extends POIXMLDocumentPart { XWPFDocument document; - private List<XWPFComment> comments = new ArrayList<>(); - private List<XWPFPictureData> pictures = new ArrayList<>(); + private final List<XWPFComment> comments = new ArrayList<>(); + private final List<XWPFPictureData> pictures = new ArrayList<>(); private CTComments ctComments; /** @@ -192,8 +192,6 @@ public class XWPFComments extends POIXMLDocumentPart { /** * Get the list of {@link XWPFComment} in the Comments part. - * - * @return */ public List<XWPFComment> getComments() { return comments; @@ -203,7 +201,6 @@ public class XWPFComments extends POIXMLDocumentPart { * Get the specified comment by position * * @param pos Array position of the comment - * @return */ public XWPFComment getComment(int pos) { if (pos >= 0 && pos < ctComments.sizeOfCommentArray()) { @@ -229,14 +226,11 @@ public class XWPFComments extends POIXMLDocumentPart { /** * Get the specified comment by ctComment - * - * @param ctComment - * @return */ public XWPFComment getComment(CTComment ctComment) { - for (int i = 0; i < comments.size(); i++) { - if (comments.get(i).getCtComment() == ctComment) { - return comments.get(i); + for (XWPFComment comment : comments) { + if (comment.getCtComment() == ctComment) { + return comment; } } return null; @@ -246,7 +240,6 @@ public class XWPFComments extends POIXMLDocumentPart { * Create a new comment and add it to the document. * * @param cid comment Id - * @return */ public XWPFComment createComment(BigInteger cid) { CTComment ctComment = ctComments.addNewComment(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java index 07375a223b..c6a5cf2201 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java @@ -89,7 +89,7 @@ public class XWPFFooter extends XWPFHeaderFooter { @Override protected void onDocumentRead() throws IOException { super.onDocumentRead(); - FtrDocument ftrDocument = null; + FtrDocument ftrDocument; try (InputStream is = getPackagePart().getInputStream()) { ftrDocument = FtrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); headerFooter = ftrDocument.getFtr(); @@ -125,6 +125,7 @@ public class XWPFFooter extends XWPFHeaderFooter { * * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() */ + @Override public BodyType getPartType() { return BodyType.FOOTER; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java index fe12c8df70..5d7bc2885a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java @@ -86,13 +86,11 @@ public class XWPFHeader extends XWPFHeaderFooter { /** * reads the document - * - * @throws IOException */ @Override protected void onDocumentRead() throws IOException { super.onDocumentRead(); - HdrDocument hdrDocument = null; + HdrDocument hdrDocument; try (InputStream is = getPackagePart().getInputStream()) { hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); headerFooter = hdrDocument.getHdr(); @@ -128,6 +126,7 @@ public class XWPFHeader extends XWPFHeaderFooter { * * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() */ + @Override public BodyType getPartType() { return BodyType.HEADER; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java index 292c831b03..53ff91fe77 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java @@ -68,7 +68,7 @@ public class XWPFNumbering extends POIXMLDocumentPart { */ @Override protected void onDocumentRead() throws IOException { - NumberingDocument numberingDoc = null; + NumberingDocument numberingDoc; InputStream is; is = getPackagePart().getInputStream(); try { @@ -105,8 +105,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * Sets the ctNumbering - * - * @param numbering */ public void setNumbering(CTNumbering numbering) { ctNumbering = numbering; @@ -116,7 +114,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * Checks whether number with numID exists * - * @param numID * @return boolean true if num exist, false if num not exist */ public boolean numExist(BigInteger numID) { @@ -129,8 +126,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * add a new number to the numbering document - * - * @param num */ public BigInteger addNum(XWPFNum num) { ctNumbering.addNewNum(); @@ -157,9 +152,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * Add a new num with an abstractNumID and a numID - * - * @param abstractNumID - * @param numID */ public void addNum(BigInteger abstractNumID, BigInteger numID) { CTNum ctNum = this.ctNumbering.addNewNum(); @@ -173,7 +165,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * get Num by NumID * - * @param numID * @return abstractNum with NumId if no Num exists with that NumID * null will be returned */ @@ -188,7 +179,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * get AbstractNum by abstractNumID * - * @param abstractNumID * @return abstractNum with abstractNumId if no abstractNum exists with that abstractNumID * null will be returned */ @@ -207,7 +197,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { * the BigInteger Value of it will be returned. * If no equal abstractNum is existing null will be returned * - * @param abstractNum * @return BigInteger */ public BigInteger getIdOfAbstractNum(XWPFAbstractNum abstractNum) { @@ -227,8 +216,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * add a new AbstractNum and return its AbstractNumID - * - * @param abstractNum */ public BigInteger addAbstractNum(XWPFAbstractNum abstractNum) { int pos = abstractNums.size(); @@ -246,7 +233,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { /** * remove an existing abstractNum * - * @param abstractNumID * @return true if abstractNum with abstractNumID exists in NumberingArray, * false if abstractNum with abstractNumID not exists */ @@ -268,7 +254,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { * If the AbstractNumID not exists * return null * - * @param numID * @return abstractNumID */ public BigInteger getAbstractNumID(BigInteger numID) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java index 5449c3bfd7..da22abe359 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java @@ -25,9 +25,9 @@ import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture; public class XWPFPicture { - private CTPicture ctPic; - private String description; - private XWPFRun run; + private final CTPicture ctPic; + private final String description; + private final XWPFRun run; public XWPFPicture(CTPicture ctPic, XWPFRun run) { this.run = run; @@ -37,8 +37,6 @@ public class XWPFPicture { /** * Link Picture with PictureData - * - * @param rel */ public void setPictureReference(PackageRelationship rel) { ctPic.getBlipFill().getBlip().setEmbed(rel.getId()); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java index eaaf94d873..74ab5de4ac 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java @@ -19,6 +19,7 @@ package org.apache.poi.xwpf.usermodel; import java.util.ArrayList; import java.util.List; +import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; @@ -26,11 +27,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; /** * Experimental class to offer rudimentary read-only processing of * of the contentblock of an SDT/ContentControl. - * <p> - * <p> - * <p> - * WARNING - APIs expected to change rapidly */ +@Beta public class XWPFSDTContent implements ISDTContent { // private final IBody part; @@ -39,7 +37,7 @@ public class XWPFSDTContent implements ISDTContent { // private List<XWPFTable> tables = new ArrayList<>(); // private List<XWPFRun> runs = new ArrayList<>(); // private List<XWPFSDT> contentControls = new ArrayList<>(); - private List<ISDTContents> bodyElements = new ArrayList<>(); + private final List<ISDTContents> bodyElements = new ArrayList<>(); public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) { if (sdtRun == null) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java index c141d8c2c8..70f6d4de47 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java @@ -25,21 +25,10 @@ public class XWPFStyle { protected XWPFStyles styles; private CTStyle ctStyle; - /** - * constructor - * - * @param style - */ public XWPFStyle(CTStyle style) { this(style, null); } - /** - * constructor - * - * @param style - * @param styles - */ public XWPFStyle(CTStyle style, XWPFStyles styles) { this.ctStyle = style; this.styles = styles; @@ -56,8 +45,6 @@ public class XWPFStyle { /** * set styleID - * - * @param styleId */ public void setStyleId(String styleId) { ctStyle.setStyleId(styleId); @@ -74,8 +61,6 @@ public class XWPFStyle { /** * set styleType - * - * @param type */ public void setType(STStyleType.Enum type) { ctStyle.setType(type); @@ -83,8 +68,6 @@ public class XWPFStyle { /** * set style - * - * @param style */ public void setStyle(CTStyle style) { this.ctStyle = style; @@ -144,8 +127,6 @@ public class XWPFStyle { /** * compares the names of the Styles - * - * @param compStyle */ public boolean hasSameName(XWPFStyle compStyle) { CTStyle ctCompStyle = compStyle.getCTStyle(); @@ -153,4 +134,4 @@ public class XWPFStyle { return name.equals(ctStyle.getName().getVal()); } -}//end class +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java index e95057f342..7721609879 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java @@ -141,7 +141,7 @@ public class XWPFTable implements IBodyElement, ISDTContents { // Unused: UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD //protected List<String> styleIDs; protected IBody part; - private CTTbl ctTbl; + private final CTTbl ctTbl; public XWPFTable(CTTbl table, IBody part, int row, int col) { this(table, part); @@ -243,8 +243,8 @@ public class XWPFTable implements IBodyElement, ISDTContents { if (tableRows.size() == 0) { createRow(); } - for (int i = 0; i < tableRows.size(); i++) { - tableRows.get(i).createCell(); + for (XWPFTableRow tableRow : tableRows) { + tableRow.createCell(); } } @@ -1046,7 +1046,6 @@ public class XWPFTable implements IBodyElement, ISDTContents { /** * inserts a new tablerow * - * @param pos * @return the inserted row */ public XWPFTableRow insertNewTableRow(int pos) { @@ -1081,8 +1080,6 @@ public class XWPFTable implements IBodyElement, ISDTContents { /** * returns the type of the BodyElement Table - * - * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType() */ @Override public BodyElementType getElementType() { @@ -1195,14 +1192,12 @@ public class XWPFTable implements IBodyElement, ISDTContents { switch (typeValue.intValue()) { case STTblWidth.INT_NIL: return TableWidthType.NIL; - case STTblWidth.INT_AUTO: - return TableWidthType.AUTO; case STTblWidth.INT_DXA: return TableWidthType.DXA; case STTblWidth.INT_PCT: return TableWidthType.PCT; default: - // Should never get here + case STTblWidth.INT_AUTO: return TableWidthType.AUTO; } } @@ -1284,11 +1279,9 @@ public class XWPFTable implements IBodyElement, ISDTContents { if (!currentType.equals(widthType)) { STTblWidth.Enum stWidthType = widthType.getStWidthType(); ctWidth.setType(stWidthType); - switch (stWidthType.intValue()) { - case STTblWidth.INT_PCT: + if (stWidthType.intValue() == STTblWidth.INT_PCT) { setWidthPercentage(ctWidth, DEFAULT_PERCENTAGE_WIDTH); - break; - default: + } else { ctWidth.setW(BigInteger.ZERO); } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java index 4c4cfd7820..0f014c45da 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java @@ -119,9 +119,8 @@ public class XWPFTableCell implements IBody, ICell { /** * returns an Iterator with paragraphs and tables - * - * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements() */ + @Override public List<IBodyElement> getBodyElements() { return Collections.unmodifiableList(bodyElements); } @@ -136,6 +135,7 @@ public class XWPFTableCell implements IBody, ICell { /** * returns a list of paragraphs */ + @Override public List<XWPFParagraph> getParagraphs() { return Collections.unmodifiableList(paragraphs); } @@ -221,7 +221,7 @@ public class XWPFTableCell implements IBody, ICell { /** * Get the vertical alignment of the cell. * - * @return the cell alignment enum value or <code>null</code> + * @return the cell alignment enum value or {@code null} * if no vertical alignment is set. */ public XWPFVertAlign getVerticalAlignment() { @@ -253,6 +253,7 @@ public class XWPFTableCell implements IBody, ICell { * @param cursor The XmlCursor structure created with XmlBeans * @return the inserted paragraph */ + @Override public XWPFParagraph insertNewParagraph(final XmlCursor cursor) { if (!isCursorInTableCell(cursor)) { return null; @@ -291,6 +292,7 @@ public class XWPFTableCell implements IBody, ICell { return newP; } + @Override public XWPFTable insertNewTbl(final XmlCursor cursor) { if (isCursorInTableCell(cursor)) { String uri = CTTbl.type.getName().getNamespaceURI(); @@ -339,9 +341,7 @@ public class XWPFTableCell implements IBody, ICell { return result; } - /** - * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) - */ + @Override public XWPFParagraph getParagraphArray(int pos) { if (pos >= 0 && pos < paragraphs.size()) { return paragraphs.get(pos); @@ -351,25 +351,21 @@ public class XWPFTableCell implements IBody, ICell { /** * get the to which the TableCell belongs - * - * @see org.apache.poi.xwpf.usermodel.IBody#getPart() */ + @Override public POIXMLDocumentPart getPart() { return tableRow.getTable().getPart(); } - /** - * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() - */ + @Override public BodyType getPartType() { return BodyType.TABLECELL; } /** * get a table by its CTTbl-Object - * - * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) */ + @Override public XWPFTable getTable(CTTbl ctTable) { for (int i = 0; i < tables.size(); i++) { if (getTables().get(i).getCTTbl() == ctTable) return getTables().get(i); @@ -377,9 +373,7 @@ public class XWPFTableCell implements IBody, ICell { return null; } - /** - * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) - */ + @Override public XWPFTable getTableArray(int pos) { if(pos >= 0 && pos < tables.size()) { return tables.get(pos); @@ -387,18 +381,15 @@ public class XWPFTableCell implements IBody, ICell { return null; } - /** - * @see org.apache.poi.xwpf.usermodel.IBody#getTables() - */ + @Override public List<XWPFTable> getTables() { return Collections.unmodifiableList(tables); } /** * inserts an existing XWPFTable to the arrays bodyElements and tables - * - * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable) */ + @Override public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; @@ -482,6 +473,7 @@ public class XWPFTableCell implements IBody, ICell { /** * get the TableCell which belongs to the TableCell */ + @Override public XWPFTableCell getTableCell(CTTc cell) { XmlCursor cursor = cell.newCursor(); cursor.toParent(); @@ -508,6 +500,7 @@ public class XWPFTableCell implements IBody, ICell { return tr.getTableCell(cell); } + @Override public XWPFDocument getXWPFDocument() { return part.getXWPFDocument(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java index 838688ffa9..da96c8320b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java @@ -41,8 +41,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule; * the child {@link XWPFTableCell}s */ public class XWPFTableRow { - private CTRow ctRow; - private XWPFTable table; + private final CTRow ctRow; + private final XWPFTable table; private List<XWPFTableCell> tableCells; public XWPFTableRow(CTRow row, XWPFTable table) { @@ -123,8 +123,6 @@ public class XWPFTableRow { * its attribute values). If omitted, then the table row shall automatically * resize its height to the height required by its contents (the equivalent * of an hRule value of auto). - * - * @param height */ public void setHeight(int height) { CTTrPr properties = getTrPr(); @@ -221,9 +219,9 @@ public class XWPFTableRow { * if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned */ public XWPFTableCell getTableCell(CTTc cell) { - for (int i = 0; i < tableCells.size(); i++) { - if (tableCells.get(i).getCTTc() == cell) - return tableCells.get(i); + for (XWPFTableCell tableCell : tableCells) { + if (tableCell.getCTTc() == cell) + return tableCell; } return null; } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xdgf/usermodel/section/TestCombinedIterator.java b/poi-ooxml/src/test/java/org/apache/poi/xdgf/usermodel/section/TestCombinedIterator.java index 5679c28cd9..6232cfd62f 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xdgf/usermodel/section/TestCombinedIterator.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xdgf/usermodel/section/TestCombinedIterator.java @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test; class TestCombinedIterator { - void testIteration(CombinedIterable<String> iterable, String... expected) { + void testIteration(Iterable<String> iterable, String... expected) { Iterator<String> iter = iterable.iterator(); @@ -49,8 +49,7 @@ class TestCombinedIterator { base.put(2L, "B2"); base.put(3L, "B3"); - testIteration(new CombinedIterable<>(base, null), "B1", "B2", - "B3"); + testIteration(createIter(base, null), "B1", "B2", "B3"); } @Test @@ -66,8 +65,7 @@ class TestCombinedIterator { master.put(5L, "M5"); master.put(6L, "M6"); - testIteration(new CombinedIterable<>(base, master), "B1", "B2", - "B3", "M4", "M5", "M6"); + testIteration(createIter(base, master), "B1", "B2", "B3", "M4", "M5", "M6"); } @Test @@ -83,8 +81,7 @@ class TestCombinedIterator { master.put(2L, "M2"); master.put(3L, "M3"); - testIteration(new CombinedIterable<>(base, master), "M1", "M2", - "M3", "B4", "B5", "B6"); + testIteration(createIter(base, master), "M1", "M2", "M3", "B4", "B5", "B6"); } @Test @@ -100,8 +97,7 @@ class TestCombinedIterator { master.put(4L, "M4"); master.put(6L, "M6"); - testIteration(new CombinedIterable<>(base, master), "B1", "M2", - "B3", "M4", "B5", "M6"); + testIteration(createIter(base, master), "B1", "M2", "B3", "M4", "B5", "M6"); } @Test @@ -119,8 +115,7 @@ class TestCombinedIterator { master.put(7L, "M7"); master.put(8L, "M8"); - testIteration(new CombinedIterable<>(base, master), "B1", "B2", - "M3", "M4", "B5", "B6", "M7", "M8"); + testIteration(createIter(base, master), "B1", "B2", "M3", "M4", "B5", "B6", "M7", "M8"); } @Test @@ -136,8 +131,7 @@ class TestCombinedIterator { master.put(2L, "M2"); master.put(3L, "M3"); - testIteration(new CombinedIterable<>(base, master), "B1", "B2", - "B3"); + testIteration(createIter(base, master), "B1", "B2", "B3"); } @Test @@ -154,7 +148,12 @@ class TestCombinedIterator { master.put(3L, "M3"); master.put(4L, "M4"); - testIteration(new CombinedIterable<>(base, master), "B1", "B2", - "B3", "M4"); + testIteration(createIter(base, master), "B1", "B2", "B3", "M4"); + } + + + private static <T> Iterable<T> createIter(SortedMap<Long, T> map1, SortedMap<Long, T> map2) { + // TODO: try to use commons collection and remove CombinedIterable + return new CombinedIterable<>(map1, map2); } } |