Bug 69935: Add short-based column setters to ClientAnchor (#1006)

* Bug 69935: Add short-based column setters to ClientAnchor

Introduce short-based column setters on ClientAnchor to complement the existing int-based setters and improve Kotlin property support.

- Add default short setters setCol1(short) and setCol2(short) that delegate to the existing int-based setters.
- Add TestClientAnchorShortSetter to verify both the new short-based setters and the existing int-based setters.

Tests:
- ./gradlew :poi:test --tests 'org.apache.poi.ss.usermodel.TestClientAnchorShortSetter'

* Replace @since TBD with 6.0.0

* Add license header to TestClieAdd ASF license header to TestClientAnchorShortSetterntAnchorShortSetter.java

Added license header to TestClientAnchorShortSetter.java
This commit is contained in:
Yongho Hwang 2026-02-14 17:50:52 +09:00 committed by GitHub
parent 62ae400993
commit 8d53613bcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 87 additions and 0 deletions

View File

@ -121,6 +121,16 @@ public interface ClientAnchor {
*/
public void setCol1(int col1);
/**
* Sets the column (0 based) of the first cell.
*
* @param col1 0-based column of the first cell.
* @since 6.0.0
*/
default void setCol1(short col1) {
setCol1((int) col1);
}
/**
* Returns the column (0 based) of the second cell, or -1 if there is no bottom-right anchor cell.
* This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE})
@ -137,12 +147,23 @@ public interface ClientAnchor {
*/
public void setCol2(int col2);
/**
* Sets the column (0 based) of the second cell.
*
* @param col2 0-based column of the second cell.
* @since 6.0.0
*/
default void setCol2(short col2) {
setCol2((int) col2);
}
/**
* Returns the row (0 based) of the first cell, or -1 if there is no bottom-right anchor cell.
* This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE}).
*
* @return 0-based row of the first cell or -1 if none.
*/
public int getRow1();
/**

View File

@ -0,0 +1,66 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for the short-based ClientAnchor column setters introduced for Bug 69935.
*/
public class TestClientAnchorShortSetter {
@Test
void shortSettersDelegateToIntSetters() throws Exception {
try (Workbook wb = new HSSFWorkbook()) {
CreationHelper helper = wb.getCreationHelper();
// The actual implementation returned here is HSSFClientAnchor
ClientAnchor anchor = helper.createClientAnchor();
// Use the new short-based overloads
anchor.setCol1((short) 2);
anchor.setCol2((short) 5);
// Setting rows is not strictly required, but keeps the anchor fully initialized
anchor.setRow1(1);
anchor.setRow2(3);
// getColX() still returns short; compare using int for convenience
assertEquals(2, anchor.getCol1());
assertEquals(5, anchor.getCol2());
}
}
@Test
void intSettersStillWorkAsBefore() throws Exception {
try (Workbook wb = new HSSFWorkbook()) {
CreationHelper helper = wb.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
// Verify that the existing int-based setters still behave as before
anchor.setCol1(3);
anchor.setCol2(7);
assertEquals(3, anchor.getCol1());
assertEquals(7, anchor.getCol2());
}
}
}