valepakh commented on code in PR #1147:
URL: https://github.com/apache/ignite-3/pull/1147#discussion_r985436940
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/decorators/TopologyDecorator.java:
##########
@@ -27,6 +27,9 @@
* Implementation of {@link Decorator} for the list of {@link ClusterNode}.
*/
public class TopologyDecorator implements Decorator<List<ClusterNode>,
TerminalOutput> {
+ /** List of headers to decorate topology. */
+ protected static final String[] headers = {"name", "host", "port",
"consistent id", "id"};
Review Comment:
From Google code style: "Constant names use UPPER_SNAKE_CASE"
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/util/PlainTableRenderer.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.util;
+
+import java.util.StringJoiner;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Utility class for the plain rendering of table structures.
+ */
+public class PlainTableRenderer {
+ /** Column delimiter for plain rendering. */
+ private static final String columnDelimiter = "\t";
+ /** Row delimiter for plain rendering. */
+ private static final String rowDelimiter = "\n";
+
+ /**
+ * Render {@code String[]} and {@code Object[][]} as a table using plain
formatting.
+ *
+ * @param hdr header of table.
+ * @param content header of table.
+ * @return Plain interpretation.
+ */
+ public static String render(String[] hdr, Object[][] content) {
+ StringJoiner sj = new StringJoiner(rowDelimiter);
+ sj.add(tableRowToString(hdr));
+ for (Object[] row : content) {
+ sj.add(tableRowToString(row));
+ }
+ return sj.toString();
+ }
+
+ /**
+ * Render {@code Object[]} using plain formatting.
+ *
+ * @param row row of table.
+ * @return Plain interpretation of row.
+ */
+ private static String tableRowToString(Object[] row) {
+ return
Stream.of(row).map(PlainTableRenderer::renderValue).collect(Collectors.joining(columnDelimiter));
+ }
+
+ private static String renderValue(Object val) {
+ return val != null ? val.toString() : "null";
+ }
Review Comment:
```suggestion
private static String tableRowToString(Object[] row) {
return
Stream.of(row).map(String::valueOf).collect(Collectors.joining(columnDelimiter));
}
```
##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/util/PlainTableRendererTest.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.util;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class PlainTableRendererTest {
+
+ @Test
+ void testRender() {
+ String[] header = new String[]{"id", "name", "address"};
+ Object[] row1 = new Object[]{1, "John", null};
+ Object[] row2 = new Object[]{2, "Jessica", "any address"};
+ Object[][] content = new Object[][]{row1, row2};
+ String render = PlainTableRenderer.render(header, content);
+ String[] renderedRows = render.split("\n");
Review Comment:
```suggestion
String[] renderedRows = render.split(System.lineSeparator());
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/util/PlainTableRenderer.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.util;
+
+import java.util.StringJoiner;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Utility class for the plain rendering of table structures.
+ */
+public class PlainTableRenderer {
+ /** Column delimiter for plain rendering. */
+ private static final String columnDelimiter = "\t";
+ /** Row delimiter for plain rendering. */
+ private static final String rowDelimiter = "\n";
Review Comment:
```suggestion
private static final String rowDelimiter = System.lineSeparator();
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/util/PlainTableRenderer.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.util;
+
+import java.util.StringJoiner;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Utility class for the plain rendering of table structures.
+ */
+public class PlainTableRenderer {
+ /** Column delimiter for plain rendering. */
+ private static final String columnDelimiter = "\t";
+ /** Row delimiter for plain rendering. */
+ private static final String rowDelimiter = "\n";
Review Comment:
These also should use UPPER_SNAKE_CASE for constants.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]