EgorBaranovEnjoysTyping commented on code in PR #13262: URL: https://github.com/apache/ignite/pull/13262#discussion_r3481254060
########## modules/commons/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringArrayNode.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.util.tostring; + +import org.apache.ignite.internal.util.GridStringBuilder; + +import static org.apache.ignite.internal.util.tostring.GridToStringBuilder.COLLECTION_LIMIT; +import static org.apache.ignite.internal.util.tostring.GridToStringNodeFactory.getGridToStringNode; + +/** + * A node that represents an array in the string representation. + * It creates nodes for each element of the array and formats the output with square brackets. + */ +class GridToStringArrayNode extends NodeRecursionMonitor { + /** An array of child nodes, each representing an element of the source array. */ + private final GridToStringNode[] nodes; + + /** The rule for appending a hint about skipped elements if the array is too large. */ + private final LongSequenceSkipRule skipRule; + + /** The class object representing the type of the array. */ + private final Class<?> arrType; + + /** + * Constructs a new array node. + * Iterates over the input array, creates a node for each element, + * and populates the internal array up to the collection size limit. + * @param propName The property name. + * @param arr The source array. + * @param arrType The class object of the array's type. + */ + GridToStringArrayNode(String propName, Object[] arr, Class<?> arrType) { + super(propName, arr); + try { + aqcuireRecursionMonitor(this); + this.arrType = arrType; + skipRule = new LongSequenceSkipRule(() -> arr.length); + nodes = new GridToStringNode[Math.min(COLLECTION_LIMIT, arr.length)]; + for (int i = 0; i < nodes.length; i++) { + final int idx = i; + nodes[idx] = getGridToStringNode(null, () -> arr[idx], () -> arr[idx].getClass()); Review Comment: it is checked inside getGridToStringNode, if it is null, this lamba won't be called -- 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]
