Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleplus committed Mar 5, 2025
1 parent 76ef8cd commit 0f14fc2
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 16 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ limitations under the License.
<release>${java.minVersion}</release>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Xdoclint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand All @@ -189,7 +194,7 @@ limitations under the License.
<goal>jar</goal>
</goals>
<configuration>
<source>8</source>
<source>${java.minVersion}</source>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
Expand Down Expand Up @@ -363,7 +368,7 @@ limitations under the License.
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.version}</version>
<configuration>
<source>8</source>
<source>${java.minVersion}</source>
<show>public</show>
</configuration>
</plugin>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/leplus/ristretto/util/ArrayListVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
public class ArrayListVector<E> extends VectorAdapter<E> {

/** The serial version UID. */
private static final long serialVersionUID = -7584729063793597958L;

/** The {@link java.util.ArrayList} delegate. */
Expand Down Expand Up @@ -81,9 +82,7 @@ private ArrayListVector(final ArrayList<E> list) {
*/
@Override
public ArrayListVector<E> clone() {
final ArrayListVector<E> clone = (ArrayListVector<E>) super.clone();
clone.delegate = new ArrayList<>(delegate);
return clone;
return new ArrayListVector<E>(new ArrayList<E>(delegate));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/leplus/ristretto/util/IdentityHashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
public class IdentityHashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Serializable {

/** The serial version UID. */
private static final long serialVersionUID = -6954699503843913409L;

/**
Expand Down Expand Up @@ -66,7 +67,9 @@ public IdentityHashSet() {
*/
public IdentityHashSet(final Collection<? extends E> c) {
this();
addAll(c);
for (E e : c) {
map.put(e, DUMMY);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/leplus/ristretto/util/IdentityObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
*/
public final class IdentityObject implements Cloneable, Serializable {

/** The serial version UID. */
private static final long serialVersionUID = Long.MAX_VALUE;

/** The singleton. */
public static final IdentityObject IT = new IdentityObject();

/** Private constructor to prevent instantiation. */
private IdentityObject() {
super();
}
Expand Down Expand Up @@ -60,6 +62,11 @@ public int hashCode() {
return Integer.MAX_VALUE;
}

/**
* To replace the deserialized object with the singleton.
*
* @return the singleton.
*/
private Object readResolve() {
return IT;
}
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/org/leplus/ristretto/util/ReproducibleUUIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class ReproducibleUUIDs {
/** Buffer size for digest. */
private static final int BUFFER_SIZE = 8192;

/** Private constructor to prevent instantiation. */
private ReproducibleUUIDs() {
super();
}
Expand Down Expand Up @@ -103,17 +104,28 @@ public static UUID fromByteBuffer(final ByteBuffer buffer) {
return digest(md);
}

/**
* Digests bytes in a manner compatible with UUID.nameUUIDFromBytes(byte[]).
*
* @param md the digest.
* @return the resulting UUID.
*/
@SuppressWarnings("checkstyle:magicnumber")
private static UUID digest(final MessageDigest md) {
final byte[] md5Bytes = md.digest();
// for compatibility with UUID.nameUUIDFromBytes(byte[]).
md5Bytes[6] &= 0x0f;
md5Bytes[6] |= 0x30;
md5Bytes[8] &= 0x3f;
md5Bytes[8] |= 0x80;
md5Bytes[6] &= (byte) 0x0f;
md5Bytes[6] |= (byte) 0x30;
md5Bytes[8] &= (byte) 0x3f;
md5Bytes[8] |= (byte) 0x80;
return UUIDConvertor.toUUID(md5Bytes);
}

/**
* Private factory method for digests.
*
* @return the digest to use.
*/
private static MessageDigest createDigest() {
try {
/*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/leplus/ristretto/util/UUIDConvertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,26 @@ public final class UUIDConvertor {
/** Maximum number of longs that can be converted into a UUID. */
public static final int MAX_LONGS = UUID_BYTES / Long.BYTES;

/** Private constructor to prevent instantiation. */
private UUIDConvertor() {
super();
}

/**
* Allocates a buffer.
*
* @return the buffer.
*/
private static ByteBuffer allocateByteBuffer() {
return ByteBuffer.allocate(UUID_BYTES);
}

/**
* Converts a UUID to a byte buffer.
*
* @param uuid the uuid to convert.
* @return the resulting byte buffer.
*/
private static ByteBuffer toByteBuffer(final UUID uuid) {
final ByteBuffer buffer = ByteBuffer.allocate(UUID_BYTES);
buffer.asLongBuffer().put(uuid.getMostSignificantBits()).put(uuid.getLeastSignificantBits());
Expand Down Expand Up @@ -226,6 +238,12 @@ public static UUID toUUID(final byte... bytes) throws ArrayIndexOutOfBoundsExcep
return toUUID(byteBuffer);
}

/**
* Converts a byte buffer to a UUID.
*
* @param bytes the byte buffer to convert.
* @return the resulting UUID.
*/
private static UUID toUUID(final ByteBuffer bytes) {
bytes.position(0);
return new UUID(bytes.getLong(), bytes.getLong());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/leplus/ristretto/util/VectorAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
public abstract class VectorAdapter<E> extends Vector<E> {

/** The serial version UID. */
private static final long serialVersionUID = -5465186583387834552L;

/** Default constructor. Should be called by subclasses. */
Expand Down
19 changes: 18 additions & 1 deletion src/test/java/org/leplus/ristretto/util/TestArrayListVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
@SuppressWarnings({"checkstyle:magicnumber"})
public final class TestArrayListVector {

private TestArrayListVector() {
/** Default constructor. */
public TestArrayListVector() {
super();
}

Expand All @@ -70,6 +71,11 @@ private TestArrayListVector() {
*/
public static class AdditionalTests {

/** Default constructor. */
public AdditionalTests() {
super();
}

/** A bunch of tests. */
@Test
public void test() {
Expand Down Expand Up @@ -144,6 +150,11 @@ public void test() {
assertThat(actual, not(IsEmptyCollection.empty()));
}

/**
* Various checks.
*
* @param v a vector containing "a", "b" and "c".
*/
private void checkAbc(final Vector<String> v) {
assertThat(v, hasSize(3));
assertThat(v.size(), is(3));
Expand Down Expand Up @@ -209,6 +220,7 @@ public void testSerialize() {
*/
public static final class GuavaTests {

/** Private constructor. */
private GuavaTests() {
super();
}
Expand Down Expand Up @@ -269,6 +281,11 @@ protected List<String> create(final String[] elements) {
*/
public static class VectorCompatibilityTests {

/** Default constructor. */
public VectorCompatibilityTests() {
super();
}

/** Test equality between a Vector and an ArrayListVector. */
@Test
public void testEquals() {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/leplus/ristretto/util/TestIdentityEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*/
public final class TestIdentityEnum {

/** Default constructor. */
public TestIdentityEnum() {
super();
}

/** Checks that IdentityEnum.IT is equal (==) to a deep clone of itself. */
@Test
public void testEqualDeepClone() {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/leplus/ristretto/util/TestIdentityHashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
})
public final class TestIdentityHashSet {

/** Default constructor. */
public TestIdentityHashSet() {
super();
}

/**
* Some additional tests.
*
Expand All @@ -56,6 +61,11 @@ public final class TestIdentityHashSet {
*/
public static class AdditionalTests {

/** Default constructor. */
public AdditionalTests() {
super();
}

/** Tests {@link IdentityHashSet#clear()}. */
@Test
public void testClear() {
Expand Down Expand Up @@ -188,6 +198,11 @@ public void testEquals() {
*/
public static final class GuavaTests {

/** Private constructor. */
private GuavaTests() {
super();
}

/**
* Creates the test suite.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
*/
public final class TestIdentityObject {

/** Public constructor. */
public TestIdentityObject() {
super();
}

/** Checks that IdentityObject.IT is equal (==) to a shallow clone of itself. */
@Test
public void testEqualClone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@
@SuppressWarnings({"checkstyle:magicnumber"})
public final class TestReproducibleUUIDs {

/** Default constructor. */
public TestReproducibleUUIDs() {
super();
}

/** Byte buffer size. */
private static final int NUMBER_OF_BYTES = 1024;

/**
* Tests nulls.
*
* @throws IOException then test failed.
*/
@Test
Expand Down Expand Up @@ -83,6 +90,8 @@ public void testString() {
}

/**
* Tests input stream.
*
* @throws IOException then test failed.
*/
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
*/
public final class TestUUIDConvertor {

/** Default constructor. */
public TestUUIDConvertor() {
super();
}

/** The random number generator. */
private static final Random PRNG = new Random();

/** Test. */
Expand Down
15 changes: 10 additions & 5 deletions src/test/java/org/leplus/ristretto/util/TestVectorAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@
*/
public final class TestVectorAdapter {

/** Default constructor. */
public TestVectorAdapter() {
super();
}

/** The Class ClassComparator. */
public static final class ClassComparator implements Comparator<Class<?>> {

/** Private constructor. */
private ClassComparator() {
super();
}

/**
* Compare.
*
Expand Down Expand Up @@ -170,11 +180,6 @@ public String toString() {
}
}

/** Default constructor. */
public TestVectorAdapter() {
super();
}

/** Tests that VectorAdapter overrides all public methods from Vector. */
@Test
public void testOverride() {
Expand Down

0 comments on commit 0f14fc2

Please sign in to comment.