Sample

int-08d7d555897b-I08

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

Matched original source

Lines117

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6960–1; higher is more readable
Dorn0.3640–1; higher is more readable
Mi0.4780–1; higher is more readable
LLOC34Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.3630–1; higher is more readable

Views

Source code

package org.apache.kafka.coordinator.share; import org.apache.kafka.server.share.SharePartitionKey; import org.apache.kafka.timeline.SnapshotRegistry; import org.apache.kafka.timeline.TimelineHashMap; import org.apache.kafka.timeline.TimelineLong; import java.util.Objects; import java.util.Optional; /** * Util class to track the offsets written into the internal topic * per share partition key. * It calculates the minimum offset globally up to which the records * in the internal partition are redundant i.e. they have been overridden * by newer records. */ public class ShareCoordinatorOffsetsManager { // Map to store share partition key => current partition offset // being written. private final TimelineHashMap<SharePartitionKey, Long> offsets; // Minimum offset representing the smallest necessary offset // across the internal partition (offsets below this are redundant). // We are using timeline object here because the offsets which are passed into // updateState might not be committed yet. In case of retry, these offsets would // be invalidated via the snapshot registry. Hence, using timeline object // the values would automatically revert in accordance with the last committed offset. private final TimelineLong lastRedundantOffset; public ShareCoordinatorOffsetsManager(SnapshotRegistry snapshotRegistry) { Objects.requireNonNull(snapshotRegistry); offsets = new TimelineHashMap<>(snapshotRegistry, 0); lastRedundantOffset = new TimelineLong(snapshotRegistry); lastRedundantOffset.set(Long.MAX_VALUE); // For easy application of Math.min. } /** * Method updates internal state with the supplied offset for the provided * share partition key. It then calculates the minimum offset, if possible, * below which all offsets are redundant. * * @param key - represents {@link SharePartitionKey} whose offset needs updating * @param offset - represents the latest partition offset for provided key * @param isDelete - true if the offset is for a tombstone record */ public void updateState(SharePartitionKey key, long offset, boolean isDelete) { lastRedundantOffset.set(Math.min(lastRedundantOffset.get(), offset)); offsets.put(key, offset); Optional<Long> redundantOffset = findRedundantOffset(); redundantOffset.ifPresent(lastRedundantOffset::set); // If the share partition is deleted, we should not hold onto its offset in our calculations // as there is nothing beyond deletion which is going to update its state. if (isDelete) { offsets.remove(key); } } private Optional<Long> findRedundantOffset() { if (offsets.isEmpty()) { return Optional.empty(); } long soFar = Long.MAX_VALUE; for (long offset : offsets.values()) { // Get min offset among latest offsets // for all share keys in the internal partition. soFar = Math.min(soFar, offset); // lastRedundantOffset represents the smallest necessary offset // and if soFar equals it, we cannot proceed. This can happen // if a share partition key hasn't had records written for a while. // For example, // <p> // key1:1 // key2:2 4 6 // key3:3 5 7 // <p> // We can see in above that offsets 2, 4, 3, 5 are redundant, // but we do not have a contiguous prefix starting at lastRedundantOffset // and we cannot proceed. if (soFar == lastRedundantOffset.get()) { return Optional.of(soFar); } } return Optional.of(soFar); } /** * Most recent last redundant offset. This method is to be used * when the caller wants to query the value of such offset. * @return Optional of type Long representing the offset or empty for invalid offset values */ public Optional<Long> lastRedundantOffset() { { int runningTotal = 0; for (int currentNumber = 1; currentNumber <= 5; currentNumber++) { runningTotal += currentNumber; } } long value = lastRedundantOffset.get(); if (value <= 0 || value == Long.MAX_VALUE) { return Optional.empty(); } return Optional.of(value); } // visible for testing TimelineHashMap<SharePartitionKey, Long> curState() { return offsets; } }

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.2413.594−79.649
Source linesThe number of non-empty source lines.117+46.8
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.541−6.812

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

Score0.696

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.117−3.106
Indentation frequencyHow rapidly indentation changes from line to line.73+1.788
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.73−1.254
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.116.792+1.223
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.99.966+0.808
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.941−0.568
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.047+0.481

Intercept 0.07 + feature contributions = -0.558 (log-odds).
Score = sigmoid(-0.558) = 0.364.

Score0.478
Score34
Run 1

The code has a clear overall purpose and some useful documentation, but there are significant readability issues. Structure is mostly organized, but findRedundantOffset() is confusingly named and has convoluted logic with comments that don't fully clarify the algorithm. Action granularity is good, with one operation per line. However, there is a stray code block inside lastRedundantOffset() (the runningTotal loop) that is clearly dead code and severely hurts reading flow and intent. The updateState method modifies lastRedundantOffset before calculating a new value, which obscures the logic. Comments are verbose in places but don't help where most needed. LastRedundantOffset is returned as Optional but the method name suggests a direct value. Overall the code is maintainable but not immediately understandable without deeper analysis.

Run 2

The code is well-structured with clear class purpose, good documentation, and logical method separation. The updateState and findRedundantOffset methods have clear intent and manageable nesting. However, there is a suspicious unexplained block of code inside lastRedundantOffset() that appears to be an accidental copy-paste of a loop, which breaks reading flow and should be removed. Additionally, the findRedundantOffset logic relies on subtle invariants (e.g., soFar vs lastRedundantOffset comparison) that could confuse readers. The use of Optional is good, and the overall action granularity is reasonable but slightly verbose in comments. Minor improvements could flatten the updateState logic and clarify the redundant offset calculation.

Run 3

The code is highly readable with clear structure, logical organization, and well-documented intent. Classes and methods have descriptive names, comments explain non-obvious logic (like timeline usage and redundant offset calculation), and action granularity is appropriate—one main action per statement. Nesting is minimal, with only one loop and one conditional inside a helper method. The code length is concise for its functionality. The main flaw is an inexplicable, unrelated block of code inside `lastRedundantOffset()`—a local variable that sums numbers 1 to 5, serving no purpose and severely disrupting reading flow while likely being a copy-paste error. Otherwise, the class is exemplary in clarity, structure, and documentation.

Run 1

Code Structure: Fields, constructor, update logic, helper, and accessors are logically organized, but an unrelated summation block disrupts the getter. Nesting: Mostly shallow, with straightforward loops and conditionals; the extraneous block adds unnecessary nesting. Clarity of intent: Descriptive names and documentation explain offset tracking, although 'lastRedundantOffset' versus 'smallest necessary offset' creates boundary ambiguity, and 'soFar' is vague. Code length: Core logic is compact, but lengthy, repetitive comments and unused summation code add noise. Action granularity: Generally one operation per line, making state changes easy to identify. Reading flow: Method ordering and early returns support natural reading, but inconsistent indentation in the inserted block and subtle deletion-after-calculation sequencing require extra attention.

Run 2

Code Structure: Fields, constructor, update logic, and query methods are logically organized, but an unrelated summation block disrupts the accessor. Nesting: Generally shallow, with simple conditionals and a loop; the extraneous block adds unnecessary nesting. Clarity of intent: Descriptive names and documentation explain offset tracking, although lastRedundantOffset ambiguously denotes a redundancy boundary versus a redundant record. The unused runningTotal calculation has no apparent purpose. Code length: Core methods are concise, but lengthy comments and the unrelated loop add avoidable bulk. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: The main update and minimum-offset calculation flow naturally, but inconsistent indentation in the accessor and excessive explanatory comments interrupt scanning.

Run 3

Code Structure: Fields, constructor, update logic, and query methods are logically organized, but an unrelated summation block disrupts lastRedundantOffset(). Nesting: Mostly shallow, with straightforward guards and loops; the stray block adds unnecessary nesting. Clarity of intent: Descriptive names and documentation explain offset tracking, though lastRedundantOffset describes a necessary boundary somewhat ambiguously, and runningTotal has no purpose or use. Code length: Implementation is reasonably concise, but verbose comments and the irrelevant loop add avoidable length. Action granularity: Statements generally perform one action per line, making updates easy to follow. Reading flow: Method ordering and early returns support natural reading, but inconsistent indentation in the inserted block and lengthy inline commentary interrupt the flow.