Sample

int-86290b4a127f-I13

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

Matched original source

Lines155

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.570–1; higher is more readable
Dorn0.8740–1; higher is more readable
Mi0.2440–1; higher is more readable
LLOC45Logical lines; fewer is more readable
DeepSeek V4 Pro17.670–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.4690–1; higher is more readable

Views

Source code

package com.google.common.util.concurrent; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.throwIfUnchecked; import static com.google.common.util.concurrent.Platform.restoreInterruptIfIsInterruptedException; import static java.util.concurrent.Executors.callable; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jspecify.annotations.Nullable; /** * An abstract {@code ExecutorService} that allows subclasses to {@linkplain #wrapTask(Callable) * wrap} tasks before they are submitted to the underlying executor. * * <p>Note that task wrapping may occur even if the task is never executed. * * <p>For delegation without task-wrapping, see {@link ForwardingExecutorService}. * * @author Chris Nokleberg */ @J2ktIncompatible @GwtIncompatible abstract class WrappingExecutorService implements ExecutorService { private final ExecutorService delegate; protected WrappingExecutorService(ExecutorService delegate) { this.delegate = checkNotNull(delegate); } /** * Wraps a {@code Callable} for submission to the underlying executor. This method is also applied * to any {@code Runnable} passed to the default implementation of {@link #wrapTask(Runnable)}. */ protected abstract <T extends @Nullable Object> Callable<T> wrapTask(Callable<T> callable); /** * Wraps a {@code Runnable} for submission to the underlying executor. The default implementation * delegates to {@link #wrapTask(Callable)}. */ protected Runnable wrapTask(Runnable command) { Callable<Object> wrapped = wrapTask(callable(command, null)); return () -> { try { wrapped.call(); } catch (Exception e) { restoreInterruptIfIsInterruptedException(e); throwIfUnchecked(e); throw new RuntimeException(e); } }; } /** * Wraps a collection of tasks. * * @throws NullPointerException if any element of {@code tasks} is null */ private <T extends @Nullable Object> ImmutableList<Callable<T>> wrapTasks( Collection<? extends Callable<T>> tasks) { ImmutableList.Builder<Callable<T>> builder = ImmutableList.builder(); { java.util.Iterator<?> loopIterator = (tasks).iterator(); while (loopIterator.hasNext()) { Callable<T> task = (Callable<T>) loopIterator.next(); builder.add(wrapTask(task)); } } return builder.build(); } // These methods wrap before delegating. @Override public final void execute(Runnable command) { delegate.execute(wrapTask(command)); } @Override public final <T extends @Nullable Object> Future<T> submit(Callable<T> task) { return delegate.submit(wrapTask(checkNotNull(task))); } @Override public final Future<?> submit(Runnable task) { return delegate.submit(wrapTask(task)); } @Override public final <T extends @Nullable Object> Future<T> submit( Runnable task, @ParametricNullness T result) { return delegate.submit(wrapTask(task), result); } @Override public final <T extends @Nullable Object> List<Future<T>> invokeAll( Collection<? extends Callable<T>> tasks) throws InterruptedException { return delegate.invokeAll(wrapTasks(tasks)); } @Override public final <T extends @Nullable Object> List<Future<T>> invokeAll( Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { return delegate.invokeAll(wrapTasks(tasks), timeout, unit); } @Override public final <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { return delegate.invokeAny(wrapTasks(tasks)); } @Override public final <T extends @Nullable Object> T invokeAny( Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return delegate.invokeAny(wrapTasks(tasks), timeout, unit); } // The remaining methods just delegate. @Override public final void shutdown() { delegate.shutdown(); } @Override @CanIgnoreReturnValue public final List<Runnable> shutdownNow() { return delegate.shutdownNow(); } @Override public final boolean isShutdown() { return delegate.isShutdown(); } @Override public final boolean isTerminated() { return delegate.isTerminated(); } @Override public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return delegate.awaitTermination(timeout, unit); } }

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.5471.459−180.558
Source linesThe number of non-empty source lines.155+62
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.864−7.296

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

Score0.57

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.156−4.487
Indentation frequencyHow rapidly indentation changes from line to line.134+3.898
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.154.891+1.755
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.96.769+0.757
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.99.949−0.568
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.934 (log-odds).
Score = sigmoid(1.934) = 0.874.

Score0.244
Score45
Run 1

The code is highly readable and well-structured. It follows a clear, logical organization: constructor, abstract wrap methods, a private helper, wrapping delegation methods, and plain delegation methods. Nesting is minimal; the only block within a method is in wrapTasks, which uses an unnecessary extra brace block but remains flat. Intent is explicit via clear method names and Javadoc. Methods are concise and each line typically performs one action. The reading flow is natural, with related methods grouped and the delegation pattern easy to follow. Minor issues include the redundant block in wrapTasks and slightly verbose generic signatures, but overall this is exceptionally clean.

Run 2

The code is well-structured, following a clear abstract class pattern for wrapping executor tasks. Methods are logically grouped: wrapping/delegating methods first, then simple delegation methods. Nesting is minimal except for a slightly awkward block in wrapTasks, which could be simplified to a for-each loop. Intent is clear—wrapping tasks before submission—supported by concise Javadoc. Code length is appropriate, with no unnecessary verbosity. Action granularity is good, with one operation per line in most cases. Reading flow is natural, moving from core wrapping logic to standard executor method overrides. The only minor issue is the unnecessary cast and block structure in wrapTasks, which slightly reduces clarity.

Run 3

This code is highly readable due to its clear structure and consistent patterns. The class has a single responsibility: wrapping tasks before delegating to an ExecutorService. Methods are logically grouped—wrapping methods first, then delegation-only methods—making navigation easy. Nesting is minimal; the only deeper block is the try-catch in wrapTask(Runnable), which is justified. Intent is evident from method names and Javadoc, especially the distinction between wrapTask(Callable) and wrapTask(Runnable). Concision is mostly good, though wrapTasks uses an unnecessary iterator loop instead of a simpler for-each or stream, slightly hurting readability. Action granularity is generally one action per line, though method chaining could reduce some verbose lines. Reading flow is natural: constructor, abstract wrap method, helper methods, then ExecutorService overrides. The use of generic type parameters like `<T extends @Nullable Object>` adds some noise but is consistent with Guava's style. Overall, this is production-quality, maintainable code.

Run 1

Code Structure: Well organized into wrapping helpers, task-submission methods, and lifecycle delegation, with comments marking sections. Nesting: Mostly shallow; the lambda's try/catch is reasonable, but wrapTasks adds an unnecessary block around its loop. Clarity of intent: Descriptive names and Javadoc clearly explain the wrapping/delegation purpose. The wildcard iterator and unchecked cast obscure otherwise simple collection traversal. Code length: Most methods are concise; repeated overrides are justified by the interface, although wrapTasks could use a shorter enhanced for-loop. Action granularity: Generally one statement per line, with nested calls expressing straightforward wrap-then-delegate operations. Reading flow: Consistent formatting and method grouping make the class easy to follow; dense imports, verbose generic annotations, and the awkward iterator implementation introduce minor friction.

Run 2

Code Structure: Logically separates task-wrapping helpers, submission methods, and lifecycle delegation. Nesting: Mostly shallow; the lambda's try/catch is reasonable, but wrapTasks adds an unnecessary block around its loop. Clarity of intent: Descriptive names, Javadoc, and section comments clearly explain the wrapper/delegation design. The wildcard iterator and unchecked cast obscure otherwise simple iteration. Code length: Most methods are concise; repetitive overrides are justified by the interface, though wrapTasks could use a shorter enhanced for-loop. Action granularity: Statements generally perform one clear operation, with nested wrapping/delegation calls remaining easy to understand. Reading flow: Consistent formatting and method grouping support natural reading; tightly packed imports and the awkward iterator implementation slightly disrupt it.

Run 3

Code Structure: Logically separates task wrapping, submission methods, and lifecycle delegation, with helpful section comments. Nesting: Mostly flat; the lambda's try/catch is reasonable, but wrapTasks adds an unnecessary block around its loop. Clarity of intent: Descriptive names and Javadoc clearly explain the wrapper/delegate design; the wildcard iterator and unchecked cast unnecessarily obscure collection traversal. Code length: Methods are concise, and most repetition is justified by the ExecutorService interface, though an enhanced for-loop would shorten wrapTasks. Action granularity: Statements generally perform one action per line; nested wrapping and delegation calls remain easy to follow. Reading flow: Consistent formatting and method grouping support natural reading, with minor interruptions from dense generic annotations, tightly packed imports, and the awkward iterator implementation.