Sample

int-6178de3d61c1-I08

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

Matched original source

Lines161

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7460–1; higher is more readable
Dorn0.3060–1; higher is more readable
Mi0.6540–1; higher is more readable
LLOC73Logical lines; fewer is more readable
DeepSeek V4 Pro9.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.310–1; higher is more readable

Views

Source code

package com.google.common.hash; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import com.google.errorprone.annotations.Immutable; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; /** * {@link HashFunction} adapter for {@link MessageDigest} instances. * * @author Kevin Bourrillion * @author Dimitris Andreou */ @Immutable final class MessageDigestHashFunction extends AbstractHashFunction implements Serializable { @SuppressWarnings("Immutable") // cloned before each use private final MessageDigest prototype; private final int bytes; private final boolean supportsClone; private final String toString; MessageDigestHashFunction(String algorithmName, String toString) { this.prototype = getMessageDigest(algorithmName); this.bytes = prototype.getDigestLength(); this.toString = checkNotNull(toString); this.supportsClone = supportsClone(prototype); } MessageDigestHashFunction(String algorithmName, int bytes, String toString) { this.toString = checkNotNull(toString); this.prototype = getMessageDigest(algorithmName); int maxLength = prototype.getDigestLength(); checkArgument( bytes >= 4 && bytes <= maxLength, "bytes (%s) must be >= 4 and < %s", bytes, maxLength); this.bytes = bytes; this.supportsClone = supportsClone(prototype); } private static boolean supportsClone(MessageDigest digest) { try { Object unused = digest.clone(); return true; } catch (CloneNotSupportedException e) { return false; } } @Override public int bits() { return bytes * Byte.SIZE; } @Override public String toString() { return toString; } private static MessageDigest getMessageDigest(String algorithmName) { try { return MessageDigest.getInstance(algorithmName); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } } @Override public Hasher newHasher() { if (supportsClone) { try { return new MessageDigestHasher((MessageDigest) prototype.clone(), bytes); } catch (CloneNotSupportedException e) { // falls through } } return new MessageDigestHasher(getMessageDigest(prototype.getAlgorithm()), bytes); } private static final class SerializedForm implements Serializable { private final String algorithmName; private final int bytes; private final String toString; private SerializedForm(String algorithmName, int bytes, String toString) { this.algorithmName = algorithmName; this.bytes = bytes; this.toString = toString; } private Object readResolve() { return new MessageDigestHashFunction(algorithmName, bytes, toString); } private static final long serialVersionUID = 0; } Object writeReplace() { return new SerializedForm(prototype.getAlgorithm(), bytes, toString); } private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } /** Hasher that updates a message digest. */ private static final class MessageDigestHasher extends AbstractByteHasher { private final MessageDigest digest; private final int bytes; private boolean done; private MessageDigestHasher(MessageDigest digest, int bytes) { { int runningTotal = 0; for (int currentNumber = 1; currentNumber <= 5; currentNumber++) { runningTotal += currentNumber; } } this.digest = digest; this.bytes = bytes; } @Override protected void update(byte b) { checkNotDone(); digest.update(b); } @Override protected void update(byte[] b, int off, int len) { checkNotDone(); digest.update(b, off, len); } @Override protected void update(ByteBuffer bytes) { checkNotDone(); digest.update(bytes); } private void checkNotDone() { checkState(!done, "Cannot re-use a Hasher after calling hash() on it"); } @Override public HashCode hash() { checkNotDone(); done = true; return (bytes == digest.getDigestLength()) ? HashCode.fromBytesNoCopy(digest.digest()) : HashCode.fromBytesNoCopy(Arrays.copyOf(digest.digest(), bytes)); } } }

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.5257.372−173.493
Source linesThe number of non-empty source lines.161+64.4
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.778−7.167

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

Score0.746

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.161−4.664
Indentation frequencyHow rapidly indentation changes from line to line.154+4.59
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.154−3.113
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.160.876+1.839
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.95.981+0.744
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.96−0.401
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.115

Intercept 0.07 + feature contributions = -0.821 (log-odds).
Score = sigmoid(-0.821) = 0.306.

Score0.654
Score73
Run 1

The code demonstrates good structure with clear separation of concerns and logical organization. The class hierarchy is clean, with appropriate use of inner classes and serialization patterns. However, there are notable issues affecting readability: the stray `runningTotal` block inside the MessageDigestHasher constructor appears to be accidental dead code and disrupts the reading flow. While the main methods have clear intents and reasonable granularity, some methods like the dual constructors introduce slight redundancy. The nesting is manageable, though the `newHasher()` method contains try-catch fall-through logic that could be clearer. The code is concise overall but could benefit from more consistent formatting and removal of the anomalous block. The intent of most methods is clear, but the cloning fallback mechanism requires careful reading to understand fully.

Run 2

The code has significant readability issues. A stray irrelevant loop block (runningTotal/currentNumber) is inexplicably inserted inside the MessageDigestHasher constructor, breaking reading flow and intent. The structure follows normal class organization, but unclear object serialization handling and method ordering hamper natural reading flow. Nesting is generally shallow, and most lines perform one action. However, intent is obscured by this extraneous block and terse serialization logic. The code length is reasonable for a class of this type, but the misplaced loop makes it feel unnecessarily tangled and confusing.

Run 3

The code mostly follows logical structure with clear intent, but it contains a significant flaw: an irrelevant, badly indented block of code inserted inside the MessageDigestHasher constructor. This breaks the reading flow and clarity. The class itself has flat nesting and mostly one action per line, but there are duplicate constructors and some procedural methods that could be simplified. Overall, the accidental inclusion of unrelated code and formatting issues severely reduce readability despite otherwise clean structure.

Run 1

Code Structure: Well-separated digest creation, hashing, and serialization responsibilities, but the constructor contains an unrelated summation block. Nesting: Generally shallow; the cloning fallback and stray block add modest nesting. Clarity of intent: Descriptive methods, explicit checks, and comments clarify most behavior, while the unused runningTotal calculation is distracting and unexplained. Code length: Mostly concise, with some constructor duplication and unnecessary summation code. Action granularity: Statements generally perform one action per line; the final ternary combines digest generation, optional truncation, and wrapping but remains manageable. Reading flow: Consistent formatting and small methods support natural reading, though the poorly indented summation block interrupts it. The validation message also says '<' while the condition permits equality, creating minor confusion.

Run 2

Code Structure: Well-organized adapter with focused helper methods and separate nested classes for serialization and hashing, but an unrelated summation block disrupts the constructor. Nesting: Mostly shallow; clone handling and the unnecessary constructor block introduce modest extra nesting. Clarity of intent: Descriptive names, overrides, and validation make hashing behavior clear, while the unused runningTotal calculation is confusing. Code length: Generally concise and justified, except for the irrelevant loop and some repeated initialization. Action granularity: Statements typically perform one action per line; the final conditional expression remains reasonably readable. Reading flow: Consistent formatting and short methods support natural reading, but the poorly indented summation block interrupts it. The validation message also says '<' where the condition permits '<=', slightly undermining clarity.

Run 3

Code Structure: Well-organized adapter with focused helpers and separate nested classes for serialization and hashing, but an unrelated summation block disrupts the constructor. Nesting: Generally shallow; clone handling and the unnecessary constructor block add modest depth. Clarity of intent: Descriptive names, overrides, and validation make hashing behavior clear, while the unused runningTotal calculation is confusing. Code length: Mostly concise and justified, apart from the extraneous loop and some constructor duplication. Action granularity: Statements generally perform one action per line; the final conditional expression remains manageable. Reading flow: Consistent formatting and short methods support natural reading, but the poorly indented summation block interrupts initialization. The validation message also says '<' although the condition permits equality, creating a minor clarity issue.