PivotUtils { static boolean cellValueEquals(Cell cell, Cell other) { if (cell != null && other != null && cell.getCellType() == other.getCellType()) { switch (cell.getCellType()) { case BLANK: if (other.getCellType()==CellType.BLANK) { return true; } break; case BOOLEAN: if (cell.getBooleanCellValue() == other.getBooleanCellValue()){ return true; } break; case ERROR: if (cell.getErrorCellValue() == other.getErrorCellValue()){ return true; } break; case FORMULA: break; case NUMERIC: if (cell.getNumericCellValue() == other.getNumericCellValue()){ return true; } break; case STRING: if (cell.getStringCellValue().equals(other.getStringCellValue())){ return true; } } } return false; }  static void createAnnotationRow(final Row annotationRow, final List<String> annotationList); static void createOrderRow(final Row orderRow, final List<Integer> orderList); static void createTypeRow(final Row typeRow, final List<AggregationType> typeList);  }
@Test public void cellValueEqualsTest() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); Row r = sheet.createRow(0); Cell c1 = r.createCell(0); Cell c2 = r.createCell(1); c1.setCellValue(1.000000000000001); c2.setCellValue(1); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1.setCellValue(1.0000000000000001); c2.setCellValue(1); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1.setCellValue(1); c2.setCellValue(0.9999999999999999); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1.setCellValue(1); c2.setCellValue(0.99999999999999999); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1 = r.createCell(0); c2 = r.createCell(1); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1 = r.createCell(0); c1.setCellType(CellType.BLANK); c2 = r.createCell(1); c2.setCellType(CellType.BOOLEAN); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1 = r.createCell(0); c2 = r.createCell(1); c1.setCellValue("a"); c2.setCellValue("a"); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1.setCellValue("a"); c2.setCellValue("A"); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1.setCellValue(""); c2.setCellValue(""); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1 = r.createCell(0); c2 = r.createCell(1); c1.setCellValue(""); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1 = r.createCell(0); c2 = r.createCell(1); c1.setCellValue("a"); c2.setCellType(CellType.NUMERIC); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1 = r.createCell(0); c2 = r.createCell(1); c1.setCellValue("a"); c2.setCellValue(0); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1.setCellValue(true); c2.setCellValue(true); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); c1.setCellValue(false); c2.setCellValue(true); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(false); c1.setCellValue(true); c2.setCellValue(1); c2.setCellType(CellType.BOOLEAN); Assertions.assertThat(PivotUtils.cellValueEquals(c1,c2)).isEqualTo(true); }