Move switch expression to its own method to get around checkstyle...

This commit is contained in:
Darin Kelkhoff
2022-05-04 08:21:01 -05:00
parent 156bb033df
commit 41346ec667

View File

@ -30,7 +30,6 @@ public class MockQueryAction implements QueryInterface
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
@SuppressWarnings("checkstyle:Indentation") // for switch expression
public QueryResult execute(QueryRequest queryRequest) throws QException public QueryResult execute(QueryRequest queryRequest) throws QException
{ {
try try
@ -47,19 +46,7 @@ public class MockQueryAction implements QueryInterface
for(String field : table.getFields().keySet()) for(String field : table.getFields().keySet())
{ {
Serializable value = switch (table.getField(field).getType()) Serializable value = getValue(table, field);
{
case STRING -> "Foo";
case INTEGER -> 42;
case DECIMAL -> new BigDecimal("3.14159");
case DATE -> LocalDate.of(1970, Month.JANUARY, 1);
case DATE_TIME -> LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0);
case TEXT -> "Four score and seven years ago...";
case HTML -> "<b>BOLD</b>";
case PASSWORD -> "abc***234";
default -> throw new IllegalStateException("Unexpected value: " + table.getField(field).getType());
};
record.setValue(field, value); record.setValue(field, value);
} }
@ -72,4 +59,28 @@ public class MockQueryAction implements QueryInterface
} }
} }
/*******************************************************************************
** Get a mock value to use, based on its type.
**
*******************************************************************************/
private Serializable getValue(QTableMetaData table, String field)
{
// @formatter:off // IJ can't do new-style switch correctly yet...
return switch(table.getField(field).getType())
{
case STRING -> "Foo";
case INTEGER -> 42;
case DECIMAL -> new BigDecimal("3.14159");
case DATE -> LocalDate.of(1970, Month.JANUARY, 1);
case DATE_TIME -> LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0);
case TEXT -> "Four score and seven years ago...";
case HTML -> "<b>BOLD</b>";
case PASSWORD -> "abc***234";
default -> throw new IllegalStateException("Unexpected value: " + table.getField(field).getType());
};
// @formatter:on
}
} }