Skip to content

Commit fce17ab

Browse files
committed
+ javadoc
+ elf4j version bump
1 parent 8859c8c commit fce17ab

File tree

7 files changed

+177
-66
lines changed

7 files changed

+177
-66
lines changed

pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<dependency>
135135
<groupId>io.github.elf4j</groupId>
136136
<artifactId>elf4j</artifactId>
137-
<version>4.0.0</version>
137+
<version>4.1.0</version>
138138
</dependency>
139139
<dependency>
140140
<groupId>com.google.code.findbugs</groupId>
@@ -212,8 +212,11 @@
212212
<configuration>
213213
<java>
214214
<palantirJavaFormat>
215-
<version>2.38.0</version>
215+
<version>2.47.0</version>
216+
<style>PALANTIR</style>
217+
<formatJavadoc>true</formatJavadoc>
216218
</palantirJavaFormat>
219+
<removeUnusedImports/>
217220
<formatAnnotations/>
218221
</java>
219222
</configuration>

src/main/java/chunk4j/Chopper.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@
2727
import java.util.List;
2828

2929
/**
30+
* The Chopper interface defines the contract for chopping a data blob into chunks. Implementations of this interface
31+
* should provide a method to chop a byte array into a list of Chunk objects. Each Chunk object represents a portion of
32+
* the original data blob. The size of each portion is determined by a pre-configured maximum size (the Chunk's
33+
* capacity). If the size of the original data blob is smaller or equal to the Chunk's capacity, the returned list will
34+
* contain only one Chunk.
35+
*
3036
* @author Qingtian Wang
3137
*/
3238
public interface Chopper {
3339

3440
/**
35-
* @param bytes
36-
* the original data blob to be chopped into chunks
37-
* @return the group of chunks which the original data blob is chopped into. Each chunk carries a portion of the
38-
* original bytes; and the size of that portion has a pre-configured maximum (a.k.a. the {@code Chunk}'s
39-
* capacity). Thus, if the size of the original bytes is smaller or equal to the chunk's capacity, then the
40-
* returned chunk group will have only one chunk element.
41+
* Chops a byte array into a list of Chunk objects. Each Chunk object represents a portion of the original data
42+
* blob. The size of each portion is determined by a pre-configured maximum size (the Chunk's capacity). If the size
43+
* of the original data blob is smaller or equal to the Chunk's capacity, the returned list will contain only one
44+
* Chunk.
45+
*
46+
* @param bytes the original data blob to be chopped into chunks
47+
* @return the group of chunks which the original data blob is chopped into.
4148
*/
4249
List<Chunk> chop(byte[] bytes);
4350
}

src/main/java/chunk4j/Chunk.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@
3232
import lombok.Value;
3333

3434
/**
35-
* A larger blob of data can be chopped up into smaller "chunks" to form a "group". When needed, often on a different
36-
* network node than the one where the data was chopped, the group of chunks can be collectively stitched back together
37-
* to restore the original data.
38-
*
39-
* @author Qingtian Wang
35+
* The Chunk class represents a chunk of data that is part of a larger data blob. The data blob can be chopped up into
36+
* smaller chunks to form a group. When needed, often on a different network node than the one where the data was
37+
* chopped, the group of chunks can be collectively stitched back together to restore the original data. The Chunk class
38+
* is thread-safe and serializable. @author Qingtian Wang
4039
*/
4140
@Value
4241
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
4342
@Builder
4443
public class Chunk implements Serializable {
4544

4645
private static final long serialVersionUID = -1879320933982945956L;
47-
/**
48-
* The group ID of the original data blob. All chunks in the same group share the same group ID.
49-
*/
46+
47+
/** The group ID of the original data blob. All chunks in the same group share the same group ID. */
5048
@EqualsAndHashCode.Include
5149
UUID groupId;
5250

@@ -58,14 +56,10 @@ public class Chunk implements Serializable {
5856
@EqualsAndHashCode.Include
5957
int index;
6058

61-
/**
62-
* Total number of chunks the original data blob is chopped to form the group.
63-
*/
59+
/** Total number of chunks the original data blob is chopped to form the group. */
6460
int groupSize;
6561

66-
/**
67-
* Data bytes chopped for this current chunk to hold.
68-
*/
62+
/** Data bytes chopped for this current chunk to hold. */
6963
@ToString.Exclude
7064
byte[] bytes;
7165
}

src/main/java/chunk4j/ChunkChopper.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@
2929
import java.util.List;
3030
import java.util.UUID;
3131
import javax.annotation.concurrent.ThreadSafe;
32+
import lombok.NonNull;
3233

3334
/**
35+
* The ChunkChopper class is responsible for chopping data into chunks. It is thread-safe and provides a static factory
36+
* method for creating new instances. Each instance is configured with a maximum chunk byte size.
37+
*
3438
* @author Qingtian Wang
3539
*/
3640
@ThreadSafe
3741
public final class ChunkChopper implements Chopper {
3842

3943
private final int chunkCapacity;
4044

45+
/**
46+
* Private constructor for the ChunkChopper class. It is used by the static factory method to create a new instance
47+
* of ChunkChopper.
48+
*
49+
* @param chunkByteCapacity The maximum size of the byte array in a chunk.
50+
*/
4151
private ChunkChopper(int chunkByteCapacity) {
4252
if (chunkByteCapacity <= 0) {
4353
throw new IllegalArgumentException(
@@ -47,16 +57,24 @@ private ChunkChopper(int chunkByteCapacity) {
4757
}
4858

4959
/**
50-
* @param maxChunkByteSize
51-
* how big you want the chunks of your data chopped up to be
52-
* @return new Chopper instance
60+
* Static factory method for creating a new ChunkChopper.
61+
*
62+
* @param maxChunkByteSize The maximum size of the byte array in a chunk.
63+
* @return A new ChunkChopper.
5364
*/
54-
public static ChunkChopper ofByteSize(int maxChunkByteSize) {
65+
public static @NonNull ChunkChopper ofByteSize(int maxChunkByteSize) {
5566
return new ChunkChopper(maxChunkByteSize);
5667
}
5768

69+
/**
70+
* Chops a byte array into chunks. Each chunk is represented by a Chunk object and contains a portion of the
71+
* original byte array. The chunks are added to a list, which is returned by the method.
72+
*
73+
* @param bytes The byte array to chop into chunks.
74+
* @return A list of chunks.
75+
*/
5876
@Override
59-
public List<Chunk> chop(byte[] bytes) {
77+
public @NonNull List<Chunk> chop(byte[] bytes) {
6078
final List<Chunk> chunks = new ArrayList<>();
6179
final UUID groupId = UUID.randomUUID();
6280
final int groupSize = numberOfChunks(bytes);
@@ -75,7 +93,13 @@ public List<Chunk> chop(byte[] bytes) {
7593
return chunks;
7694
}
7795

78-
private int numberOfChunks(byte[] bytes) {
96+
/**
97+
* Calculates the number of chunks that a byte array will be chopped into.
98+
*
99+
* @param bytes The byte array to chop into chunks.
100+
* @return The number of chunks.
101+
*/
102+
private int numberOfChunks(byte @NonNull [] bytes) {
79103
int chunkCount = bytes.length / this.chunkCapacity;
80104
return bytes.length % this.chunkCapacity == 0 ? chunkCount : chunkCount + 1;
81105
}

0 commit comments

Comments
 (0)