Skip to content

Commit

Permalink
Merge pull request #15 from pauloruszel/develop
Browse files Browse the repository at this point in the history
refatorando o switch de tipos de células do Java 21
  • Loading branch information
pauloruszel committed Apr 17, 2024
2 parents 24cccca + 0e8e9ea commit 073fdb0
Showing 1 changed file with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,12 @@ public static boolean isRowComplete(final Row row) {
.mapToObj(i -> row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK))
.allMatch(cell -> {
int columnIndex = cell.getColumnIndex();
switch (columnIndex) {
case 8, 9, 14, 15 -> {
// Campos numéricos que devem ser long
return getCellValueAsLong(cell) != -1L;
}
case 13, 18 -> {
// Campos numéricos que devem ser inteiros
return getCellValueAsInteger(cell) != -1;
}
case 16, 17, 19 -> {
// Campos decimais
return getCellValueAsBigDecimal(cell).compareTo(BigDecimal.ZERO) != 0;
}
default -> {
// Campos de texto
return !getCellValueAsString(cell).isEmpty();
}
}
return switch (columnIndex) {
case 8, 9, 14, 15 -> getCellValueAsLong(cell) != -1L; // Campos numéricos que devem ser long
case 13, 18 -> getCellValueAsInteger(cell) != -1; // Campos numéricos que devem ser inteiros
case 16, 17, 19 -> getCellValueAsBigDecimal(cell).compareTo(BigDecimal.ZERO) != 0; // Campos decimais
default -> !getCellValueAsString(cell).isEmpty(); // Campos de texto
};
});
}

Expand Down Expand Up @@ -86,15 +74,15 @@ public static String criarNomeArquivoAleatorio() {
return UUID.randomUUID().toString();
}

private static String getCellValueAsString(Cell cell) {
private static String getCellValueAsString(final Cell cell) {
return switch (cell.getCellType()) {
case STRING -> cell.getStringCellValue().trim();
case NUMERIC -> NumberToTextConverter.toText(cell.getNumericCellValue());
default -> "";
};
}

private static BigDecimal getCellValueAsBigDecimal(Cell cell) {
private static BigDecimal getCellValueAsBigDecimal(final Cell cell) {
if (cell.getCellType() == CellType.NUMERIC) {
return BigDecimal.valueOf(cell.getNumericCellValue());
} else {
Expand All @@ -106,7 +94,7 @@ private static BigDecimal getCellValueAsBigDecimal(Cell cell) {
}
}

private static Long getCellValueAsLong(Cell cell) {
private static Long getCellValueAsLong(final Cell cell) {
try {
if (cell.getCellType() == CellType.NUMERIC) {
return (long) cell.getNumericCellValue();
Expand All @@ -118,7 +106,7 @@ private static Long getCellValueAsLong(Cell cell) {
}
}

private static Integer getCellValueAsInteger(Cell cell) {
private static Integer getCellValueAsInteger(final Cell cell) {
try {
if (cell.getCellType() == CellType.NUMERIC) {
return (int) cell.getNumericCellValue();
Expand Down

0 comments on commit 073fdb0

Please sign in to comment.