Sample

int-385e590bb62e-I13

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

Matched original source

Lines93

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6710–1; higher is more readable
Dorn0.8430–1; higher is more readable
Mi0.3240–1; higher is more readable
LLOC22Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5930–1; higher is more readable

Views

Source code

package org.apache.kafka.controller; import org.apache.kafka.common.errors.ThrottlingQuotaExceededException; import org.apache.kafka.common.message.RequestHeaderData; import org.apache.kafka.common.security.auth.KafkaPrincipal; import org.apache.kafka.common.utils.Time; import org.apache.kafka.server.authorizer.AuthorizableRequestContext; import java.util.OptionalLong; import java.util.function.Consumer; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; public class ControllerRequestContext { public static OptionalLong requestTimeoutMsToDeadlineNs( Time time, int millisecondsOffset ) { return OptionalLong.of(time.nanoseconds() + NANOSECONDS.convert(millisecondsOffset, MILLISECONDS)); } private final KafkaPrincipal principal; private final OptionalLong deadlineNs; private final RequestHeaderData requestHeader; private final Consumer<Integer> partitionChangeQuotaApplier; public ControllerRequestContext( RequestHeaderData requestHeader, KafkaPrincipal principal, OptionalLong deadlineNs ) { this(requestHeader, principal, deadlineNs, __ -> { }); } public ControllerRequestContext( RequestHeaderData requestHeader, KafkaPrincipal principal, OptionalLong deadlineNs, Consumer<Integer> partitionChangeQuotaApplier ) { this.requestHeader = requestHeader; this.principal = principal; this.deadlineNs = deadlineNs; this.partitionChangeQuotaApplier = partitionChangeQuotaApplier; } public ControllerRequestContext( AuthorizableRequestContext requestContext, OptionalLong deadlineNs ) { this(requestContext, deadlineNs, __ -> { }); } public ControllerRequestContext( AuthorizableRequestContext requestContext, OptionalLong deadlineNs, Consumer<Integer> partitionChangeQuotaApplier ) { this( new RequestHeaderData() .setRequestApiKey((short) requestContext.requestType()) .setRequestApiVersion((short) requestContext.requestVersion()) .setCorrelationId(requestContext.correlationId()) .setClientId(requestContext.clientId()), requestContext.principal(), deadlineNs, partitionChangeQuotaApplier ); } public RequestHeaderData requestHeader() { return requestHeader; } public KafkaPrincipal principal() { return principal; } public OptionalLong deadlineNs() { return deadlineNs; } /** * Apply the partition change quota. * * @param requestedPartitionCount The value to apply. * @throws ThrottlingQuotaExceededException If recording this value moves a metric beyond its configured * maximum or minimum bound */ public void applyPartitionChangeQuota(int requestedPartitionCount) { partitionChangeQuotaApplier.accept(requestedPartitionCount); } }

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.2474.179−81.648
Source linesThe number of non-empty source lines.93+37.2
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.638−6.958

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

Score0.671

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.94−2.292
Indentation frequencyHow rapidly indentation changes from line to line.87+2.272
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.107.926+0.937
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.107.968−0.908
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.92.844+0.888
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.065+0.312

Intercept 0.07 + feature contributions = 1.677 (log-odds).
Score = sigmoid(1.677) = 0.843.

Score0.324
Score22
Run 1

The code is well-structured and readable. It uses a clean class layout with clear separation of constructors, static helpers, and instance methods. Nesting is minimal, with no deep conditional or logical blocks. The intent is mostly clear: representing a controller request context, converting timeouts to deadlines, and delegating quota application. Constructor overloads are concise and delegation via `this(...)` avoids duplication. Action granularity is mostly one action per line, though constructor chaining for `RequestHeaderData` is slightly dense but still readable. Naming is descriptive (`deadlineNs`, `partitionChangeQuotaApplier`) and the use of `OptionalLong` is appropriate. The static helper `requestTimeoutMsToDeadlineNs` is clear and concise. Minor reductions in readability come from the `__ -> { }` lambda (intent could be clearer with a named no-op) and the multiple delegating constructors, which may require a brief scan to understand. Overall, the code is maintainable and straightforward.

Run 2

The code is well-structured with clear separation of concerns: constants, fields, constructors, and methods are logically ordered. Nesting is minimal and constructors are chained cleanly. The intent of the class is clear — it encapsulates controller request context and quota application. Most lines perform a single action, and the use of method references and lambda for the no-op quota applier keeps the code concise. The Javadoc for `applyPartitionChangeQuota` enhances clarity. Minor deductions: the static method `requestTimeoutMsToDeadlineNs` could be better documented, and the multi-line `set` chain in the constructor slightly reduces readability, though it remains acceptable. Overall, this is highly readable production-grade code.

Run 3

The code is well-structured and readable. It follows a logical organization with fields, multiple constructors, accessor methods, and a clear public API. Nesting is minimal with flat constructor chains and no deep conditionals. Intent is clear through descriptive naming and Javadoc on the quota method. Code length is appropriate, though there is minor duplication between constructor overloads that could be consolidated. Action granularity is good—each line performs a single task, especially in the builder-style RequestHeaderData initialization. Reading flow is natural with constructors grouped logically and accessors following. Minor deductions: the lambda parameter '__' is slightly ambiguous, and the static imports for time conversion could be more explicit. Overall this is production-quality readable code.

Run 1

Code Structure: Logically organized into fields, constructor overloads, accessors, and quota application, with constructor delegation avoiding duplicated initialization. Nesting: Very shallow; no nested control flow. Clarity of intent: Descriptive names, explicit time units, and focused documentation make the purpose clear, though the no-op lambdas and injected quota consumer require some inference. Code length: Concise overall; constructor overloads and trivial accessors add necessary boilerplate rather than excessive complexity. Action granularity: Assignments and chained header setters are separated clearly, generally maintaining one action per line. Reading flow: Consistent formatting and related methods grouped together support natural reading. Minor drawbacks include the utility method appearing before fields, ungrouped imports, and the dense deadline conversion expression.

Run 2

Code Structure: Fields, constructors, accessors, and quota handling are logically organized, with constructor delegation avoiding duplicated initialization. Nesting: The code is flat, with no nested control flow; the fluent header construction remains easy to follow. Clarity of intent: Descriptive names, explicit time units, and quota documentation communicate purpose well, though the '__' no-op lambdas are less expressive. Code length: Concise overall; multiple constructor overloads add some verbosity but support distinct initialization paths. Action granularity: Assignments and fluent setter calls appear on separate lines, making individual operations clear. Reading flow: Consistent formatting and straightforward delegation create a natural progression, although placing the static utility before the fields and adding clearer separation among imports would slightly improve scanning.

Run 3

Code Structure: Fields, delegating constructors, accessors, and quota application are logically organized, though placing the static helper before fields slightly interrupts the layout. Nesting: Minimal nesting keeps the code easy to scan. Clarity of intent: Descriptive names, explicit time units, and quota documentation communicate purpose well; the '__' parameter and undocumented no-op callbacks are less obvious. Code length: Concise overall, with constructor delegation avoiding duplicated initialization; overloads add some necessary boilerplate. Action granularity: Assignments and builder calls generally occupy separate lines, making individual operations clear. Reading flow: Consistent formatting and straightforward delegation support natural reading, although the chained header construction within a constructor call requires slightly more attention.