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

(-)src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (+14 lines)
Lines 293-296 Link Here
293
            setPropertyValue(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, property.getPropertyValue() & GROUP_SHAPE_NOT_HIDDEN_MASK));
293
            setPropertyValue(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, property.getPropertyValue() & GROUP_SHAPE_NOT_HIDDEN_MASK));
294
        }
294
        }
295
    }
295
    }
296
297
    @Override
298
    public boolean equals(Object obj) {
299
        if (!(o instanceof HSSFComment)) {
300
            return false;
301
        }
302
        HSSFComment other = (HSSFComment) obj;
303
        return getNoteRecord().equals(other.getNoteRecord());
304
    }
305
306
    @Override
307
    public int hashCode() {
308
        return (getRow() << 16) + getColumn();
309
    }
296
}
310
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (+15 lines)
Lines 222-225 Link Here
222
    protected CTShape getCTShape(){
222
    protected CTShape getCTShape(){
223
        return _vmlShape;
223
        return _vmlShape;
224
    }
224
    }
225
226
    @Override
227
    public boolean equals(Object o) {
228
        if (!(o instanceof XSSFComment)) {
229
            return false;
230
        }
231
        XSSFComment other = (XSSFComment) o;
232
        return ((getCTComment() == other.getCTComment()) &&
233
                (getCTShape() == other.getCTShape())); 
234
    }
235
236
    @Override
237
    public int hashCode() {
238
        return (getRow() << 8) + getColumn();
239
    }
225
}
240
}
(-)src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (-22 / +57 lines)
Lines 289-318 Link Here
289
        Row r = wb1.createSheet("Sheet1").createRow(0);
289
        Row r = wb1.createSheet("Sheet1").createRow(0);
290
        CreationHelper factory = wb1.getCreationHelper();
290
        CreationHelper factory = wb1.getCreationHelper();
291
291
292
        r.createCell(0).setCellValue(true);
292
        r.createCell(0).setCellValue(false);
293
        r.createCell(1).setCellValue(1.5);
293
        r.createCell(1).setCellValue(true);
294
        r.createCell(2).setCellValue(factory.createRichTextString("Astring"));
294
        r.createCell(2).setCellValue(1.5);
295
        r.createCell(3).setCellErrorValue(FormulaError.DIV0.getCode());
295
        r.createCell(3).setCellValue(factory.createRichTextString("Astring"));
296
        r.createCell(4).setCellFormula("A1+B1");
296
        r.createCell(4).setCellErrorValue(FormulaError.DIV0.getCode());
297
        r.createCell(5); // blank
297
        r.createCell(5).setCellFormula("A1+B1");
298
        r.createCell(6); // blank
298
299
299
        // create date-formatted cell
300
        // create date-formatted cell
300
        Calendar c = LocaleUtil.getLocaleCalendar();
301
        Calendar c = LocaleUtil.getLocaleCalendar();
301
        c.set(2010, 01, 02, 00, 00, 00);
302
        c.set(2010, 01, 02, 00, 00, 00);
302
        r.createCell(6).setCellValue(c);
303
        r.createCell(7).setCellValue(c);
303
        CellStyle dateStyle = wb1.createCellStyle();
304
        CellStyle dateStyle = wb1.createCellStyle();
304
        short formatId = wb1.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"); // any date format will do
305
        short formatId = wb1.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"); // any date format will do
305
        dateStyle.setDataFormat(formatId);
306
        dateStyle.setDataFormat(formatId);
306
        r.getCell(6).setCellStyle(dateStyle);
307
        r.getCell(7).setCellStyle(dateStyle);
307
308
308
        assertEquals("Boolean", "TRUE", r.getCell(0).toString());
309
        assertEquals("Boolean", "FALSE", r.getCell(0).toString());
309
        assertEquals("Numeric", "1.5", r.getCell(1).toString());
310
        assertEquals("Boolean", "TRUE", r.getCell(1).toString());
310
        assertEquals("String", "Astring", r.getCell(2).toString());
311
        assertEquals("Numeric", "1.5", r.getCell(2).toString());
311
        assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
312
        assertEquals("String", "Astring", r.getCell(3).toString());
312
        assertEquals("Formula", "A1+B1", r.getCell(4).toString());
313
        assertEquals("Error", "#DIV/0!", r.getCell(4).toString());
313
        assertEquals("Blank", "", r.getCell(5).toString());
314
        assertEquals("Formula", "A1+B1", r.getCell(5).toString());
315
        assertEquals("Blank", "", r.getCell(6).toString());
314
        // toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month
316
        // toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month
315
        String dateCell1 = r.getCell(6).toString();
317
        String dateCell1 = r.getCell(7).toString();
316
        assertTrue("Date (Day)", dateCell1.startsWith("02-"));
318
        assertTrue("Date (Day)", dateCell1.startsWith("02-"));
317
        assertTrue("Date (Year)", dateCell1.endsWith("-2010"));
319
        assertTrue("Date (Year)", dateCell1.endsWith("-2010"));
318
320
Lines 322-334 Link Here
322
        wb1.close();
324
        wb1.close();
323
325
324
        r = wb2.getSheetAt(0).getRow(0);
326
        r = wb2.getSheetAt(0).getRow(0);
325
        assertEquals("Boolean", "TRUE", r.getCell(0).toString());
327
        assertEquals("Boolean", "FALSE", r.getCell(0).toString());
326
        assertEquals("Numeric", "1.5", r.getCell(1).toString());
328
        assertEquals("Boolean", "TRUE", r.getCell(1).toString());
327
        assertEquals("String", "Astring", r.getCell(2).toString());
329
        assertEquals("Numeric", "1.5", r.getCell(2).toString());
328
        assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
330
        assertEquals("String", "Astring", r.getCell(3).toString());
329
        assertEquals("Formula", "A1+B1", r.getCell(4).toString());
331
        assertEquals("Error", "#DIV/0!", r.getCell(4).toString());
330
        assertEquals("Blank", "", r.getCell(5).toString());
332
        assertEquals("Formula", "A1+B1", r.getCell(5).toString());
331
        String dateCell2 = r.getCell(6).toString();
333
        assertEquals("Blank", "", r.getCell(6).toString());
334
        String dateCell2 = r.getCell(7).toString();
332
        assertEquals("Date", dateCell1, dateCell2);
335
        assertEquals("Date", dateCell1, dateCell2);
333
        wb2.close();
336
        wb2.close();
334
    }
337
    }
Lines 979-982 Link Here
979
        
982
        
980
        wb.close();
983
        wb.close();
981
    }
984
    }
985
986
987
    @Test
988
    public void getCellComment() throws IOException {
989
        Workbook wb = _testDataProvider.createWorkbook();
990
        Sheet sheet = wb.createSheet();
991
        CreationHelper factory = wb.getCreationHelper();
992
        Row row = sheet.createRow(0);
993
        Cell cell = row.createCell(1);
994
        
995
        // cell does not have a comment
996
        assertNull(cell.getCellComment());
997
 
998
        // add a cell comment
999
        ClientAnchor anchor = factory.createClientAnchor();
1000
        anchor.setCol1(cell.getColumnIndex());
1001
        anchor.setCol2(cell.getColumnIndex()+1);
1002
        anchor.setRow1(row.getRowNum());
1003
        anchor.setRow2(row.getRowNum()+3);
1004
1005
        Drawing drawing = sheet.createDrawingPatriarch();
1006
        Comment comment = drawing.createCellComment(anchor);
1007
        RichTextString str = factory.createRichTextString("Hello, World!");
1008
        comment.setString(str);
1009
        comment.setAuthor("Apache POI");
1010
        cell.setCellComment(comment);
1011
        // ideally assertSame, but XSSFCell creates a new XSSFCellComment wrapping the same bean for every call to getCellComment.
1012
        assertEquals(comment, cell.getCellComment());
1013
1014
        wb.close();
1015
   }
1016
982
}
1017
}

Return to bug 59279