Skip to content

Commit b2f77c7

Browse files
committed
add javadoc to BytesHolder
Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
1 parent a993161 commit b2f77c7

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

datatypes/src/main/java/org/hyperledger/besu/datatypes/BytesHolder.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,52 @@
1919

2020
import org.apache.tuweni.bytes.Bytes;
2121

22+
/**
23+
* A wrapper class that holds a {@link Bytes} value.
24+
*
25+
* <p>This class serves as a base holder for byte sequences, implementing {@link Comparable} to
26+
* allow for ordered collections and comparisons. Subclasses can extend this to create specialized
27+
* byte holders with domain-specific semantics.
28+
*/
2229
public class BytesHolder implements Comparable<BytesHolder> {
2330
private final Bytes value;
2431

32+
/**
33+
* Constructs a BytesHolder with the given bytes value.
34+
*
35+
* @param value the bytes value to hold
36+
*/
2537
protected BytesHolder(final Bytes value) {
2638
this.value = value;
2739
}
2840

41+
/**
42+
* Returns the underlying bytes value.
43+
*
44+
* @return the bytes value held by this instance
45+
*/
2946
public Bytes getBytes() {
3047
return value;
3148
}
3249

50+
/**
51+
* Creates a default BytesHolder instance with the given bytes value.
52+
*
53+
* @param value the bytes value to hold
54+
* @return a new BytesHolder instance
55+
*/
3356
public static BytesHolder createDefaultHolder(final Bytes value) {
3457
return new BytesHolder(value);
3558
}
3659

60+
/**
61+
* Compares this BytesHolder to another object for equality.
62+
*
63+
* <p>Two BytesHolder instances are equal if they contain the same byte sequence.
64+
*
65+
* @param obj the object to compare with
66+
* @return {@code true} if the objects are equal, {@code false} otherwise
67+
*/
3768
@Override
3869
public boolean equals(final Object obj) {
3970
if (obj == this) {
@@ -45,16 +76,36 @@ public boolean equals(final Object obj) {
4576
return Arrays.equals(value.toArrayUnsafe(), other.value.toArrayUnsafe());
4677
}
4778

79+
/**
80+
* Returns the hash code of this BytesHolder.
81+
*
82+
* @return the hash code based on the underlying bytes value
83+
*/
4884
@Override
4985
public int hashCode() {
5086
return value.hashCode();
5187
}
5288

89+
/**
90+
* Returns a string representation of this BytesHolder.
91+
*
92+
* @return the string representation of the underlying bytes value
93+
*/
5394
@Override
5495
public String toString() {
5596
return value.toString();
5697
}
5798

99+
/**
100+
* Compares this BytesHolder with another for ordering.
101+
*
102+
* <p>The comparison is performed lexicographically on the underlying byte sequences.
103+
*
104+
* @param bytesHolder the BytesHolder to compare with
105+
* @return a negative integer, zero, or a positive integer as this BytesHolder is less than, equal
106+
* to, or greater than the specified BytesHolder
107+
* @throws NullPointerException if bytesHolder is null
108+
*/
58109
@Override
59110
public int compareTo(final BytesHolder bytesHolder) {
60111
Objects.requireNonNull(bytesHolder, "bytesHolder cannot be null");

0 commit comments

Comments
 (0)