@Test public void testComputeColumnMaxOneRowInteger() { String columnName = "col"; int value = 5; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), equalTo(value)); }
@VisibleForTesting @Nullable static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column); logger.errorf("%s\n", message); throw new IllegalArgumentException(message); } Schema schema = columnMetadata.getSchema(); Function<Row, Integer> rowToInteger; if (schema.equals(Schema.INTEGER)) { rowToInteger = r -> r.getInteger(column); } else if (schema.equals(Schema.ISSUE)) { rowToInteger = r -> r.getIssue(column).getSeverity(); } else { return null; } return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) .orElse(null); }
AnswerMetadataUtil { @VisibleForTesting @Nullable static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column); logger.errorf("%s\n", message); throw new IllegalArgumentException(message); } Schema schema = columnMetadata.getSchema(); Function<Row, Integer> rowToInteger; if (schema.equals(Schema.INTEGER)) { rowToInteger = r -> r.getInteger(column); } else if (schema.equals(Schema.ISSUE)) { rowToInteger = r -> r.getIssue(column).getSeverity(); } else { return null; } return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) .orElse(null); } }
AnswerMetadataUtil { @VisibleForTesting @Nullable static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column); logger.errorf("%s\n", message); throw new IllegalArgumentException(message); } Schema schema = columnMetadata.getSchema(); Function<Row, Integer> rowToInteger; if (schema.equals(Schema.INTEGER)) { rowToInteger = r -> r.getInteger(column); } else if (schema.equals(Schema.ISSUE)) { rowToInteger = r -> r.getIssue(column).getSeverity(); } else { return null; } return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) .orElse(null); } private  AnswerMetadataUtil(); }
AnswerMetadataUtil { @VisibleForTesting @Nullable static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column); logger.errorf("%s\n", message); throw new IllegalArgumentException(message); } Schema schema = columnMetadata.getSchema(); Function<Row, Integer> rowToInteger; if (schema.equals(Schema.INTEGER)) { rowToInteger = r -> r.getInteger(column); } else if (schema.equals(Schema.ISSUE)) { rowToInteger = r -> r.getIssue(column).getSeverity(); } else { return null; } return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) .orElse(null); } private  AnswerMetadataUtil(); static @Nonnull AnswerMetadata computeAnswerMetadata(
      @Nonnull Answer answer, @Nonnull BatfishLogger logger); }
AnswerMetadataUtil { @VisibleForTesting @Nullable static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column); logger.errorf("%s\n", message); throw new IllegalArgumentException(message); } Schema schema = columnMetadata.getSchema(); Function<Row, Integer> rowToInteger; if (schema.equals(Schema.INTEGER)) { rowToInteger = r -> r.getInteger(column); } else if (schema.equals(Schema.ISSUE)) { rowToInteger = r -> r.getIssue(column).getSeverity(); } else { return null; } return table.getRows().getData().stream() .map(rowToInteger) .filter(Objects::nonNull) .max(Comparator.naturalOrder()) .orElse(null); } private  AnswerMetadataUtil(); static @Nonnull AnswerMetadata computeAnswerMetadata(
      @Nonnull Answer answer, @Nonnull BatfishLogger logger);  }