Fix the few remaining warnings and enable checkstyle.
Change-Id: I6eaeaefe921633d76dfa6283d0685a3c53320b95
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<packaging>bundle</packaging>
<properties>
- <odlparent.checkstyle.skip>true</odlparent.checkstyle.skip>
<odlparent.spotbugs.enforce>false</odlparent.spotbugs.enforce>
</properties>
* @param bytes entry bytes
* @return resulting object
*/
- T bytesToObject(final long index, ByteBuf bytes);
+ T bytesToObject(long index, ByteBuf bytes);
/**
* Converts an object into a series of bytes in the specified {@link ByteBuf}.
*/
final class JournalSegment {
/**
- * Encapsulation of a {@link JournalSegment}'s state;
+ * Encapsulation of a {@link JournalSegment}'s state.
*/
sealed interface State {
// Marker interface
* @param id The segment identifier.
* @return The segment descriptor builder.
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withId(final long id) {
this.id = id;
return this;
* @param index The segment starting index.
* @return The segment descriptor builder.
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withIndex(final long index) {
this.index = index;
return this;
* @param maxSegmentSize The maximum count of the segment.
* @return The segment descriptor builder.
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withMaxSegmentSize(final int maxSegmentSize) {
this.maxSegmentSize = maxSegmentSize;
return this;
* @deprecated since 3.0.2
*/
@Deprecated
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withMaxEntries(final int maxEntries) {
this.maxEntries = maxEntries;
return this;
* @param updated Epoch milliseconds
* @return The segment descriptor builder.
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withUpdated(final long updated) {
this.updated = updated;
return this;
}
@Override
+ @SuppressWarnings("checkstyle:avoidHidingCauseException")
MappedFileWriter newFileWriter() {
return new MappedFileWriter(file, maxEntrySize, mappedBuffer.slice(), () -> {
- try {
- mappedBuffer.force();
- } catch (UncheckedIOException e) {
- throw e.getCause();
- }
+ try {
+ mappedBuffer.force();
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ }
});
}
* @param name The journal name.
* @return The builder instance
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withName(final String name) {
this.name = requireNonNull(name, "name cannot be null");
return this;
* @param storageLevel The storage level.
* @return The builder instance
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withStorageLevel(final StorageLevel storageLevel) {
this.storageLevel = requireNonNull(storageLevel, "storageLevel cannot be null");
return this;
* @return The builder instance
* @throws NullPointerException If the {@code directory} is {@code null}
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withDirectory(final String directory) {
return withDirectory(new File(requireNonNull(directory, "directory cannot be null")));
}
* @return The builder instance
* @throws NullPointerException If the {@code directory} is {@code null}
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withDirectory(final File directory) {
this.directory = requireNonNull(directory, "directory cannot be null");
return this;
* @return The builder instance
* @throws IllegalArgumentException If the {@code maxSegmentSize} is not positive
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withMaxSegmentSize(final int maxSegmentSize) {
checkArgument(maxSegmentSize > JournalSegmentDescriptor.BYTES,
"maxSegmentSize must be greater than " + JournalSegmentDescriptor.BYTES);
* @return the builder instance
* @throws IllegalArgumentException if the {@code maxEntrySize} is not positive
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withMaxEntrySize(final int maxEntrySize) {
checkArgument(maxEntrySize > 0, "maxEntrySize must be positive");
this.maxEntrySize = maxEntrySize;
* @deprecated This option has no effect and is scheduled for removal.
*/
@Deprecated(forRemoval = true, since = "9.0.3")
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withMaxEntriesPerSegment(final int maxEntriesPerSegment) {
checkArgument(maxEntriesPerSegment > 0, "max entries per segment must be positive");
checkArgument(maxEntriesPerSegment <= DEFAULT_MAX_ENTRIES_PER_SEGMENT,
* @return the builder instance
* @throws IllegalArgumentException if the density is not between 0 and 1
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withIndexDensity(final double indexDensity) {
checkArgument(indexDensity > 0 && indexDensity < 1, "index density must be between 0 and 1");
this.indexDensity = indexDensity;
* @param flushOnCommit Whether to flush buffers to disk when entries are committed to a segment.
* @return The builder instance
*/
+ @SuppressWarnings("checkstyle:hiddenField")
public Builder withFlushOnCommit(final boolean flushOnCommit) {
this.flushOnCommit = flushOnCommit;
return this;
@Test
public void testWriteRead() throws Exception {
try (var journal = createJournal()) {
- var writer = journal.writer();
- var reader = journal.openReader(1);
+ final var writer = journal.writer();
+ final var reader = journal.openReader(1);
// Append a couple entries.
assertEquals(1, writer.getNextIndex());
assertNoNext(reader);
// Test opening a new reader and reading from the journal.
- reader = journal.openReader(1);
- entry1 = assertNext(reader);
+ final var reader2 = journal.openReader(1);
+ entry1 = assertNext(reader2);
assertEquals(1, entry1.index());
- assertEquals(2, reader.getNextIndex());
- entry2 = assertNext(reader);
+ assertEquals(2, reader2.getNextIndex());
+ entry2 = assertNext(reader2);
assertEquals(2, entry2.index());
- assertNoNext(reader);
+ assertNoNext(reader2);
// Reset the reader.
- reader.reset();
+ reader2.reset();
// Test opening a new reader and reading from the journal.
- reader = journal.openReader(1);
- entry1 = assertNext(reader);
+ final var reader3 = journal.openReader(1);
+ entry1 = assertNext(reader3);
assertEquals(1, entry1.index());
- assertEquals(2, reader.getNextIndex());
- entry2 = assertNext(reader);
+ assertEquals(2, reader3.getNextIndex());
+ entry2 = assertNext(reader3);
assertEquals(2, entry2.index());
- assertNoNext(reader);
+ assertNoNext(reader3);
// Truncate the journal and write a different entry.
writer.reset(2);
assertEquals(2, writer.getNextIndex());
writer.append(ENTRY);
- reader.reset(2);
- indexed = assertNext(reader);
+ reader3.reset(2);
+ indexed = assertNext(reader3);
assertEquals(2, indexed.index());
// Reset the reader to a specific index and read the last entry again.
- reader.reset(2);
+ reader3.reset(2);
- assertEquals(2, reader.getNextIndex());
- entry2 = assertNext(reader);
+ assertEquals(2, reader3.getNextIndex());
+ entry2 = assertNext(reader3);
assertEquals(2, entry2.index());
- assertNoNext(reader);
+ assertNoNext(reader3);
}
}
@Test
public void testResetTruncateZero() throws Exception {
- try (SegmentedJournal<TestEntry> journal = createJournal()) {
- JournalWriter<TestEntry> writer = journal.writer();
- JournalReader<TestEntry> reader = journal.openReader(1);
+ try (var journal = createJournal()) {
+ final var writer = journal.writer();
+ final var reader = journal.openReader(1);
assertEquals(0, journal.lastIndex());
assertEquals(1, writer.getNextIndex());