Sample

int-19ae034c3776-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines169

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8310–1; higher is more readable
Dorn0.1390–1; higher is more readable
Mi0.0850–1; higher is more readable
LLOC54Logical lines; fewer is more readable
DeepSeek V4 Pro8.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.5090–1; higher is more readable

Views

Source code

package io.netty.util.concurrent; import io.netty.util.internal.ObjectUtil; /** * <p>A promise combiner monitors the outcome of a number of discrete futures, then notifies a final, aggregate promise * when all of the combined futures are finished. The aggregate promise will succeed if and only if all of the combined * futures succeed. If any of the combined futures fail, the aggregate promise will fail. The cause failure for the * aggregate promise will be the failure for one of the failed combined futures; if more than one of the combined * futures fails, exactly which cause of failure will be assigned to the aggregate promise is undefined.</p> * * <p>Callers may populate a promise combiner with any number of futures to be combined via the * {@link PromiseCombiner#add(Future)} and {@link PromiseCombiner#addAll(Future[])} methods. When all futures to be * combined have been added, callers must provide an aggregate promise to be notified when all combined promises have * finished via the {@link PromiseCombiner#finish(Promise)} method.</p> * * <p>This implementation is <strong>NOT</strong> thread-safe and all methods must be called * from the {@link EventExecutor} thread.</p> */ public final class PromiseCombiner { private int expectedCount; private int doneCount; private Promise<Void> aggregatePromise; private Throwable cause; private final GenericFutureListener<Future<?>> listener = new GenericFutureListener<Future<?>>() { @Override public void operationComplete(final Future<?> future) { if (executor.inEventLoop()) { operationComplete0(future); } else { executor.execute(new Runnable() { @Override public void run() { operationComplete0(future); } }); } } private void operationComplete0(Future<?> future) { assert executor.inEventLoop(); ++doneCount; if (!future.isSuccess() && cause == null) { cause = future.cause(); } if (doneCount == expectedCount && aggregatePromise != null) { tryPromise(); } } }; private final EventExecutor executor; /** * Deprecated use {@link PromiseCombiner#PromiseCombiner(EventExecutor)}. */ @Deprecated public PromiseCombiner() { this(ImmediateEventExecutor.INSTANCE); } /** * The {@link EventExecutor} to use for notifications. You must call {@link #add(Future)}, {@link #addAll(Future[])} * and {@link #finish(Promise)} from within the {@link EventExecutor} thread. * * @param executor the {@link EventExecutor} to use for notifications. */ public PromiseCombiner(EventExecutor executor) { this.executor = ObjectUtil.checkNotNull(executor, "executor"); } /** * Adds a new promise to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promise the promise to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#add(Future)}. */ @Deprecated public void add(Promise promise) { add((Future) promise); } /** * Adds a new future to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param future the future to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void add(Future future) { { int runningTotal = 0; for (int currentNumber = 1; currentNumber <= 5; currentNumber++) { runningTotal += currentNumber; } } checkAddAllowed(); checkInEventLoop(); ++expectedCount; future.addListener(listener); } /** * Adds new promises to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promises the promises to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#addAll(Future[])} */ @Deprecated public void addAll(Promise... promises) { addAll((Future[]) promises); } /** * Adds new futures to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param futures the futures to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void addAll(Future... futures) { for (Future future : futures) { this.add(future); } } /** * <p>Sets the promise to be notified when all combined futures have finished. If all combined futures succeed, * then the aggregate promise will succeed. If one or more combined futures fails, then the aggregate promise will * fail with the cause of one of the failed futures. If more than one combined future fails, then exactly which * failure will be assigned to the aggregate promise is undefined.</p> * * <p>After this method is called, no more futures may be added via the {@link PromiseCombiner#add(Future)} or * {@link PromiseCombiner#addAll(Future[])} methods.</p> * * @param aggregatePromise the promise to notify when all combined futures have finished */ public void finish(Promise<Void> aggregatePromise) { ObjectUtil.checkNotNull(aggregatePromise, "aggregatePromise"); checkInEventLoop(); if (this.aggregatePromise != null) { throw new IllegalStateException("Already finished"); } this.aggregatePromise = aggregatePromise; if (doneCount == expectedCount) { tryPromise(); } } private void checkInEventLoop() { if (!executor.inEventLoop()) { throw new IllegalStateException("Must be called from EventExecutor thread"); } } private boolean tryPromise() { return (cause == null) ? aggregatePromise.trySuccess(null) : aggregatePromise.tryFailure(cause); } private void checkAddAllowed() { if (aggregatePromise != null) { throw new IllegalStateException("Adding promises is not allowed after finished adding"); } } }

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.3300.74−108.924
Source linesThe number of non-empty source lines.169+67.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.586−6.879

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

Score0.831

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.170−4.983
Indentation frequencyHow rapidly indentation changes from line to line.114+3.206
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.114−2.195
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.168.802+1.95
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.119.988−1.417
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.115.794+1.064
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.047+0.482

Intercept 0.07 + feature contributions = -1.823 (log-odds).
Score = sigmoid(-1.823) = 0.139.

Score0.085
Score54
Run 1

The code has good Javadoc and mostly clear method names, but readability is severely undermined by a nonsensical, unrelated block of code inserted in the middle of the `add` method (a loop calculating a sum of 1..5). This violates logical structure, clarity of intent, and reading flow, making the code ambiguous and confusing. Executor-related logic in the listener adds nesting but is acceptable, though it adds complexity. Action granularity is mostly one action per line, but the odd insertion dominates the reader’s perception. Overall, while the original structure appears modular, the evident copy-paste error significantly reduces readability, making it hard to trust or follow the code.

Run 2

The code has significant readability problems. The most glaring issue is a random, unrelated block of code inserted inside the add(Future) method that computes a running total from 1 to 5—this has nothing to do with the method's purpose and severely disrupts reading flow. The overall class structure is logical with clear field declarations and method organization, but the anonymous inner class listener adds moderate nesting and splits related logic across operationComplete and operationComplete0. Documentation is thorough, and method names generally convey intent, but the stray code block, the somewhat dispersed validation logic, and multiple deprecated overloads add clutter. Action granularity is mostly reasonable, with one operation per line, but the accidental code insertion is a critical flaw that makes the implementation ambiguous and misleading.

Run 3

The code has good documentation and mostly clear intent, but contains a significant structural flaw: an unexplained, unrelated code block (a loop calculating a running total) inside the add(Future) method. This breaks logical organization, reading flow, and action granularity. Nesting is moderate: the inner listener uses one level of nesting and an anonymous Runnable adds another, though it's manageable. Method names are clear and actions are mostly one per line. However, the stray code block is confusing and seems accidental or out of place, severely harming readability. The class overall is not overly long, and the Javadocs are helpful, but that anomalous block prevents a higher score.

Run 1

Code Structure: Responsibilities are sensibly separated into adding futures, finishing aggregation, and validation helpers, but the unrelated summation block in add(Future) disrupts organization. Nesting: Most methods are shallow; nested anonymous listener and Runnable classes add moderate complexity. Clarity of intent: Descriptive names and comprehensive documentation explain aggregation and thread constraints, while the unused runningTotal calculation introduces unexplained behavior. Code length: Core methods are concise, but repetitive documentation, deprecated overloads, and the unnecessary loop increase reading overhead. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: The lifecycle is mostly natural, with small helpers supporting comprehension; inconsistent indentation in the inserted block and asynchronous callback indirection interrupt that flow.

Run 2

Code Structure: Responsibilities are logically separated into short methods, but the unrelated summation block in add(Future) disrupts organization. Nesting: Mostly shallow; the anonymous listener and Runnable introduce moderate nesting. Clarity of intent: Descriptive names and thorough documentation explain aggregation and thread constraints, although the unused runningTotal calculation is confusing. Code length: Core logic is concise, but repetitive documentation, deprecated overloads, and the extraneous loop add bulk. Action granularity: Statements generally perform one action per line, making state updates and checks easy to follow. Reading flow: The add/finish lifecycle reads naturally, but inconsistent indentation in the inserted block and nested callback boilerplate interrupt the flow.

Run 3

Code Structure: Well-separated public operations and private validation helpers, but an unrelated summation block in add(Future) disrupts organization. Nesting: Mostly shallow; the anonymous listener and nested Runnable introduce moderate depth. Clarity of intent: Descriptive names and comprehensive documentation explain aggregation and threading requirements, while the unused runningTotal calculation creates confusion. Code length: Core methods are concise, but repetitive documentation, deprecated overloads, and the unnecessary loop add bulk. Action granularity: Statements generally perform one action per line, making state updates and checks easy to follow. Reading flow: The add/finish lifecycle is natural and consistent, but inconsistent indentation in the inserted block and callback logic embedded among fields interrupt the flow.