View | Details | Raw Unified | Return to bug 65453
Collapse All | Expand All

(-)a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java (+22 lines)
Lines 79-84 Link Here
79
            assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
79
            assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
80
                                        CellType.FORMULA, CellType.ERROR);
80
                                        CellType.FORMULA, CellType.ERROR);
81
81
82
            cell.setCellValue(Integer.valueOf(42));
83
            assertEquals(42, cell.getNumericCellValue(), 0.0001);
84
            assertEquals(CellType.NUMERIC, cell.getCellType());
85
            assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING,
86
                                        CellType.FORMULA, CellType.ERROR);
87
82
            cell.setCellValue(false);
88
            cell.setCellValue(false);
83
            assertFalse(cell.getBooleanCellValue());
89
            assertFalse(cell.getBooleanCellValue());
84
            assertEquals(CellType.BOOLEAN, cell.getCellType());
90
            assertEquals(CellType.BOOLEAN, cell.getCellType());
Lines 86-91 Link Here
86
            assertTrue(cell.getBooleanCellValue());
92
            assertTrue(cell.getBooleanCellValue());
87
            assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN,
93
            assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN,
88
                                        CellType.FORMULA, CellType.ERROR);
94
                                        CellType.FORMULA, CellType.ERROR);
95
96
            cell.setCellValue(Boolean.valueOf(false));
97
            assertFalse(cell.getBooleanCellValue());
98
            assertEquals(CellType.BOOLEAN, cell.getCellType());
99
            cell.setCellValue(Boolean.valueOf(true));
100
            assertTrue(cell.getBooleanCellValue());
101
            assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN,
102
                                        CellType.FORMULA, CellType.ERROR);
89
103
90
            cell.setCellValue(factory.createRichTextString("Foo"));
104
            cell.setCellValue(factory.createRichTextString("Foo"));
91
            assertEquals("Foo", cell.getRichStringCellValue().getString());
105
            assertEquals("Foo", cell.getRichStringCellValue().getString());
Lines 138-143 Link Here
138
            cell.setCellValue((String)null);
152
            cell.setCellValue((String)null);
139
            assertEquals("", cell.getStringCellValue());
153
            assertEquals("", cell.getStringCellValue());
140
            assertEquals(CellType.BLANK, cell.getCellType());
154
            assertEquals(CellType.BLANK, cell.getCellType());
155
156
            cell.setCellValue((Number)null);
157
            assertEquals("", cell.getStringCellValue());
158
            assertEquals(CellType.BLANK, cell.getCellType());
159
160
            cell.setCellValue((Boolean)null);
161
            assertEquals("", cell.getStringCellValue());
162
            assertEquals(CellType.BLANK, cell.getCellType());
141
163
142
            cell.setCellValue((LocalDate)null);
164
            cell.setCellValue((LocalDate)null);
143
            assertNull(cell.getLocalDateTimeCellValue());
165
            assertNull(cell.getLocalDateTimeCellValue());
(-)a/poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java (+34 lines)
Lines 130-135 Link Here
130
     */
130
     */
131
    void setCellValue(double value);
131
    void setCellValue(double value);
132
132
133
    /**
134
     * Set a numeric value for the cell.
135
     *
136
     * Allows usage of boxed java types for numeric values and will convert the value using {@link Number#doubleValue()}
137
     * to call {@link Cell#setCellValue(double)}.
138
     *
139
     * @param value if null, then {@link Cell#setBlank()} is called.
140
     * @see Cell#setCellValue(double)
141
     * */
142
    default void setCellValue(Number value) {
143
        if (null == value) {
144
            setBlank();
145
            return;
146
        }
147
        setCellValue(value.doubleValue());
148
    }
149
133
    /**
150
    /**
134
     * <p>Converts the supplied date to its equivalent Excel numeric value and sets
151
     * <p>Converts the supplied date to its equivalent Excel numeric value and sets
135
     * that into the cell.</p>
152
     * that into the cell.</p>
Lines 325-330 Link Here
325
     */
342
     */
326
     void setCellValue(boolean value);
343
     void setCellValue(boolean value);
327
344
345
    /**
346
     * Set a boolean value for the cell.
347
     *
348
     * Allows usage of boxed java type {@link Boolean}  and will convert the value using {@link Boolean#booleanValue()}
349
     * to call {@link Cell#setCellValue(boolean)}.
350
     *
351
     * @param value if null, then {@link Cell#setBlank()} is called.
352
     * @see Cell#setCellValue(boolean)
353
     * */
354
    default void setCellValue(Boolean value) {
355
        if (null == value) {
356
            setBlank();
357
            return;
358
        }
359
        setCellValue(value.booleanValue());
360
    }
361
328
    /**
362
    /**
329
     * Set a error value for the cell
363
     * Set a error value for the cell
330
     *
364
     *

Return to bug 65453