[#4] add checkstyle

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-07-30 14:43:31 +03:00
parent 7518893388
commit ab8a574d0d
14 changed files with 139 additions and 25 deletions

View file

@ -0,0 +1,35 @@
package info.frostfs.sdk;
import java.nio.ByteBuffer;
import java.util.UUID;
import static java.util.Objects.isNull;
public class UuidExtension {
private static final int UUID_BYTE_ARRAY_LENGTH = 16;
private UuidExtension() {
}
public static UUID asUuid(byte[] bytes) {
if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) {
throw new IllegalArgumentException("Uuid byte array length must be " + UUID_BYTE_ARRAY_LENGTH);
}
ByteBuffer bb = ByteBuffer.wrap(bytes);
long firstLong = bb.getLong();
long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
public static byte[] asBytes(UUID uuid) {
if (isNull(uuid)) {
throw new IllegalArgumentException("Uuid is not present");
}
ByteBuffer bb = ByteBuffer.allocate(UUID_BYTE_ARRAY_LENGTH);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
}