Sample

int-a24776937e63-I13

Lower every eligible classic and enhanced for loop to a while loop

Matched original source

Lines79

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4090–1; higher is more readable
Dorn0.760–1; higher is more readable
Mi0.4420–1; higher is more readable
LLOC27Logical lines; fewer is more readable
DeepSeek V4 Pro130–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.4370–1; higher is more readable

Views

Source code

package org.apache.kafka.clients.admin; import org.apache.kafka.common.KafkaFuture; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.annotation.InterfaceAudience; import org.apache.kafka.common.errors.ApiException; import org.apache.kafka.common.internals.KafkaFutureImpl; import org.apache.kafka.common.protocol.Errors; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * The result of the {@link Admin#alterShareGroupOffsets(String, Map, AlterShareGroupOffsetsOptions)} call. */ @InterfaceAudience.Public public class AlterShareGroupOffsetsResult { private final KafkaFuture<Map<TopicPartition, ApiException>> future; AlterShareGroupOffsetsResult(KafkaFuture<Map<TopicPartition, ApiException>> future) { this.future = future; } /** * Return a future which can be used to check the result for a given partition. */ public KafkaFuture<Void> partitionResult(final TopicPartition partition) { final KafkaFutureImpl<Void> result = new KafkaFutureImpl<>(); this.future.whenComplete((topicPartitions, throwable) -> { if (throwable != null) { result.completeExceptionally(throwable); } else if (!topicPartitions.containsKey(partition)) { result.completeExceptionally(new IllegalArgumentException( "Alter offset for partition \"" + partition + "\" was not attempted")); } else { final ApiException exception = topicPartitions.get(partition); if (exception == null) { result.complete(null); } else { result.completeExceptionally(exception); } } }); return result; } /** * Return a future which succeeds if all the alter offsets succeed. * If not, the first topic error shall be returned. */ public KafkaFuture<Void> all() { return this.future.thenApply(topicPartitionErrorsMap -> { List<TopicPartition> partitionsFailed = topicPartitionErrorsMap.entrySet() .stream() .filter(e -> e.getValue() != null) .map(Map.Entry::getKey) .collect(Collectors.toList()); { java.util.Iterator<?> loopIterator = (topicPartitionErrorsMap.values()).iterator(); while (loopIterator.hasNext()) { ApiException exception = (ApiException) loopIterator.next(); if (exception != null) { String message = exception.getMessage(); if ((message != null) && !message.isEmpty()) { throw Errors.forException(exception).exception(message + " Failed altering group offsets for the following partitions: " + partitionsFailed); } else { throw Errors.forException(exception).exception( "Failed altering group offsets for the following partitions: " + partitionsFailed); } } } } return null; }); } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.3076.021−101.509
Source linesThe number of non-empty source lines.79+31.6
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.43−6.646

Intercept 8.87 + feature contributions = -67.684 (log-odds).
Score = sigmoid(-67.684) = 0.

Score0.409

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.80−1.796
Indentation frequencyHow rapidly indentation changes from line to line.72+1.753
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.111.975−1.078
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.111.975+1.002
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.78.858+0.692
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.112

Intercept 0.07 + feature contributions = 1.155 (log-odds).
Score = sigmoid(1.155) = 0.76.

Score0.442
Score27
Run 1

The code is generally readable but has some issues. The structure is logical, with clear separation between the two public methods. Nesting is moderate—the lambda callbacks add a level but are manageable. Clarity of intent is good in `partitionResult` but muddled in `all()`; the method awkwardly mixes declarative stream processing with an imperative loop, and contains a redundant standalone block. Code length is acceptable but `all()` is unnecessarily verbose. Action granularity is mostly one action per line, though the stream pipeline could be formatted more cleanly. Reading flow is interrupted by the abrupt shift from streams to a raw iterator loop—using `forEach` would be more natural. The `partitionResult` method is straightforward and well-documented, but `all()` has duplicated exception-handling logic and could be simplified.

Run 2

The code is generally readable with clear class structure and documented public methods. The `partitionResult` method is well-written, with flat nesting and clear intent. However, the `all()` method is problematic: it unnecessarily mixes stream-based collection with a manual iterator loop over the same data, creating redundant and confusing logic. The iterator declaration includes an unnecessary scope block, and the casting of `ApiException` is redundant. The logic for finding the first error is convoluted and could be simplified using streams or a simple loop. This hurts clarity of intent and reading flow. Overall, the structure is acceptable but the implementation of `all()` contains avoidable complexity.

Run 3

The code has a clear public API and decent documentation, but readability is hampered by the `all()` method. It mixes two distinct approaches for finding the first error: a stream to collect failed partitions, followed by a redundant manual iterator loop that duplicates the error-checking logic. This creates confusion about intent and unnecessarily increases length. The iterator code is awkward, using raw `Iterator<?>`, explicit casts, and a redundant block. The nested conditionals and exception-building logic reduce clarity, though the `partitionResult()` method is relatively straightforward with moderate nesting. Overall, the class structure is logical, but the implementation of `all()` lacks clarity and conciseness.

Run 1

Code Structure: The class is logically divided into a constructor and two focused result methods, but all() includes an unnecessary block and awkward iterator handling. Nesting: partitionResult() has moderate nesting; all() nests a loop, condition, and message check inside a callback, making it harder to scan. Clarity of intent: Method names, types, and documentation clearly communicate the purpose, although the wildcard iterator and explicit cast obscure a straightforward traversal. Code length: Mostly concise, but collecting failed partitions and then separately scanning errors adds reading overhead; duplicated exception-message construction is verbose. Action granularity: Statements generally perform one action each, and the stream pipeline is split into readable steps. Reading flow: The class progresses naturally, but inconsistent indentation, fully qualified iterator usage, redundant parentheses, and the extra block interrupt the flow.

Run 2

Code Structure: The class cleanly separates per-partition and aggregate results, but all() contains an unnecessary standalone block and an awkward iterator loop. Nesting: partitionResult() has manageable branching; all() is more deeply nested than necessary. Clarity of intent: Descriptive method names, types, and documentation explain the purpose, although loopIterator, a wildcard iterator, and a cast obscure otherwise straightforward error handling. Code length: Mostly concise, but the explicit iteration and duplicated exception construction add avoidable verbosity. Action granularity: Statements generally perform one action each, and the stream pipeline is clearly split across lines. Reading flow: partitionResult() reads naturally; inconsistent indentation, redundant parentheses, and switching from streams to manual iteration interrupt the flow in all().

Run 3

Code Structure: The class is logically organized around a stored future and two clearly separated result methods, but all() contains an unnecessary block and awkward iterator machinery. Nesting: partitionResult() has manageable branching, whereas all() nests a callback, block, loop, and multiple conditionals. Clarity of intent: Method names, types, and documentation clearly convey partition-level and aggregate outcomes; generic iterator typing and a cast obscure an otherwise simple traversal. Code length: Mostly concise, but the explicit iterator and duplicated error-message construction add avoidable verbosity. Action granularity: Statements generally perform one action per line, and the stream pipeline separates its operations clearly. Reading flow: partitionResult() reads naturally; all() is less smooth because of inconsistent indentation, redundant parentheses, fully qualified iterator typing, and the transition from streams to manual iteration.